Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ OS ?= $(shell uname -s)
OS := $(shell echo $(OS) | tr '[:upper:]' '[:lower:]')
K8S_LATEST_VER ?= $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
export CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME)
TAG ?= v1.10.0
TAG ?= main

.PHONY: all
all: build
Expand Down
29 changes: 21 additions & 8 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const (
defaulReportMode = int(controllers.CollectFromManagementCluster)
mebibytes_bytes = 1 << 20
gibibytes_per_bytes = 1 << 30
sveltosNamespace = "NAMESPACE"
)

// Add RBAC for the authorized diagnostics endpoint.
Expand All @@ -124,15 +125,17 @@ func main() {

setupLogging()

sveltosNamespace := os.Getenv(sveltosNamespace)
if sveltosNamespace == "" {
setupLog.V(logs.LogInfo).Error(nil, "Missing required environment variables NAMESPACE")
os.Exit(1)
}

reportMode = controllers.ReportMode(tmpReportMode)
ctrl.SetLogger(klog.Background())
ctrlOptions := getCtrlOptions(scheme)

restConfig := ctrl.GetConfigOrDie()
restConfig.QPS = restConfigQPS
restConfig.Burst = restConfigBurst
restConfig.UserAgent = remote.DefaultClusterAPIUserAgent("addon-controller")
restConfig.WarningHandler = apiwarnings.DefaultHandler(klog.Background().WithName("API Server Warning"))
restConfig := getRestConfig()

ctx := ctrl.SetupSignalHandler()

Expand All @@ -143,6 +146,7 @@ func main() {
controllers.SetCAPIOnboardAnnotation(capiOnboardAnnotation)
controllers.SetDriftDetectionRegistry(registry)
controllers.SetAgentInMgmtCluster(agentInMgmtCluster)
controllers.SetSveltosNamespace(sveltosNamespace)

if isInitContainer() {
runInitContainerWork(ctx, restConfig, scheme)
Expand Down Expand Up @@ -175,7 +179,7 @@ func main() {
controllers.NewLicenseManager()

if shardKey == "" && !disableTelemetry {
err = telemetry.StartCollecting(ctx, mgr.GetConfig(), mgr.GetClient(), version)
err = telemetry.StartCollecting(ctx, mgr.GetConfig(), mgr.GetClient(), sveltosNamespace, version)
if err != nil {
setupLog.Error(err, "failed starting telemetry client")
}
Expand Down Expand Up @@ -256,10 +260,10 @@ func initFlags(fs *pflag.FlagSet) {
"Bind address to expose the pprof profiler (e.g. localhost:6060)")

fs.StringVar(&driftDetectionConfigMap, "drift-detection-config", "",
"The name of the ConfigMap in the projectsveltos namespace containing the drift-detection-manager configuration")
"The name of the ConfigMap in the namespace where projectsveltos is deployed containing the drift-detection-manager configuration")

fs.StringVar(&luaConfigMap, "lua-methods", "",
"The name of the ConfigMap in the projectsveltos namespace containing lua utilities to be loaded."+
"The name of the ConfigMap in the namespace where projectsveltos is deployed containing lua utilities to be loaded."+
"Changing the content of the ConfigMap does not cause Sveltos to redeploy.")

fs.StringVar(&registry, "registry", "",
Expand Down Expand Up @@ -797,3 +801,12 @@ func setupLogging() {

ctrl.SetLogger(klog.Background())
}

func getRestConfig() *rest.Config {
restConfig := ctrl.GetConfigOrDie()
restConfig.QPS = restConfigQPS
restConfig.Burst = restConfigBurst
restConfig.UserAgent = remote.DefaultClusterAPIUserAgent("addon-controller")
restConfig.WarningHandler = apiwarnings.DefaultHandler(klog.Background().WithName("API Server Warning"))
return restConfig
}
19 changes: 18 additions & 1 deletion config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ spec:
- "--report-mode=0"
- --shard-key=
- "--agent-in-mgmt-cluster=false"
env:
- name: GOMEMLIMIT
valueFrom:
resourceFieldRef:
resource: limits.memory
- name: GOMAXPROCS
valueFrom:
resourceFieldRef:
resource: limits.cpu
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
containers:
- name: controller
args:
Expand All @@ -22,7 +35,7 @@ spec:
- --shard-key=
- --capi-onboard-annotation=
- "--v=5"
- "--version=v1.10.0"
- "--version=main"
- "--agent-in-mgmt-cluster=false"
env:
- name: GOMEMLIMIT
Expand All @@ -33,3 +46,7 @@ spec:
valueFrom:
resourceFieldRef:
resource: limits.cpu
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
4 changes: 2 additions & 2 deletions config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ spec:
template:
spec:
initContainers:
- image: docker.io/projectsveltos/addon-controller:v1.10.0
- image: docker.io/projectsveltos/addon-controller:main
name: initialization
containers:
- image: docker.io/projectsveltos/addon-controller:v1.10.0
- image: docker.io/projectsveltos/addon-controller:main
name: controller
2 changes: 1 addition & 1 deletion controllers/clusterpromotion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ func (r *ClusterPromotionReconciler) verifyStageEligibility(ctx context.Context,
return false, err
}

result := license.VerifyLicenseSecret(ctx, r.Client, publicKey, logger)
result := license.VerifyLicenseSecret(ctx, r.Client, getSveltosNamespace(), publicKey, logger)
if result.Message != "" {
logger.V(logs.LogDebug).Info(result.Message)
}
Expand Down
10 changes: 5 additions & 5 deletions controllers/clustersummary_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func (r *ClusterSummaryReconciler) postFinalizerCleanup(ctx context.Context,

cs := clusterSummaryScope.ClusterSummary
if err := sharding.UnregisterClusterShard(ctx, r.Client, libsveltosv1beta1.ComponentAddonManager,
string(libsveltosv1beta1.FeatureHelm), cs.Spec.ClusterNamespace, cs.Spec.ClusterName,
getSveltosNamespace(), string(libsveltosv1beta1.FeatureHelm), cs.Spec.ClusterNamespace, cs.Spec.ClusterName,
cs.Spec.ClusterType); err != nil {
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to unregister cluster shard: %v", err))
return err
Expand Down Expand Up @@ -1048,7 +1048,7 @@ func (r *ClusterSummaryReconciler) updateMaps(ctx context.Context, clusterSummar
currentReferences.Insert(&corev1.ObjectReference{
APIVersion: corev1.SchemeGroupVersion.String(),
Kind: string(libsveltosv1beta1.ConfigMapReferencedResourceKind),
Namespace: projectsveltos,
Namespace: getSveltosNamespace(),
Name: driftDetectionConfigMap,
})
}
Expand Down Expand Up @@ -1608,8 +1608,8 @@ func (r *ClusterSummaryReconciler) updateClusterShardPair(ctx context.Context,
}

if hasShardChanged, err := sharding.RegisterClusterShard(ctx, r.Client, libsveltosv1beta1.ComponentAddonManager,
string(libsveltosv1beta1.FeatureHelm), r.ShardKey, clusterSummary.Spec.ClusterNamespace, clusterSummary.Spec.ClusterName,
clusterSummary.Spec.ClusterType); err != nil {
getSveltosNamespace(), string(libsveltosv1beta1.FeatureHelm), r.ShardKey, clusterSummary.Spec.ClusterNamespace,
clusterSummary.Spec.ClusterName, clusterSummary.Spec.ClusterType); err != nil {
logger.V(logs.LogDebug).Info(fmt.Sprintf("failed to check/update cluster:shard pair %v", err))
return err
} else if hasShardChanged {
Expand Down Expand Up @@ -1938,7 +1938,7 @@ func (r *ClusterSummaryReconciler) verifyPullModeEligibility(ctx context.Context
return false, err
}

result := license.VerifyLicenseSecret(ctx, r.Client, publicKey, logger)
result := license.VerifyLicenseSecret(ctx, r.Client, getSveltosNamespace(), publicKey, logger)
maxClusters := 0
if result.Payload != nil {
maxClusters = result.Payload.MaxClusters
Expand Down
13 changes: 8 additions & 5 deletions controllers/controllers_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ import (
)

var (
testEnv *helpers.TestEnvironment
cancel context.CancelFunc
ctx context.Context
scheme *runtime.Scheme
testEnv *helpers.TestEnvironment
cancel context.CancelFunc
ctx context.Context
scheme *runtime.Scheme
sveltosNamespace string
)

func TestControllers(t *testing.T) {
Expand Down Expand Up @@ -86,7 +87,9 @@ var _ = BeforeSuite(func() {
panic(err)
}

sveltosNamespace = randomString()
controllers.SetManagementClusterAccess(testEnv.Client, testEnv.Config, dc)
controllers.SetSveltosNamespace(sveltosNamespace)
controllers.CreatFeatureHandlerMaps()

Expect(index.AddDefaultIndexes(ctx, testEnv.Manager)).To(Succeed())
Expand Down Expand Up @@ -137,7 +140,7 @@ var _ = BeforeSuite(func() {

projectsveltosNs := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: "projectsveltos",
Name: sveltosNamespace,
},
}
Expect(testEnv.Create(context.TODO(), projectsveltosNs)).To(Succeed())
Expand Down
6 changes: 4 additions & 2 deletions controllers/drift_detection_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func upgradeDriftDetection(ctx context.Context, shardKey string, logger logr.Log
upgradeDriftDetectionDeploymentsInManagedClusters(ctx, shardKey, logger)
}

func upgradeDriftDetectionDeploymentsInManagedClusters(ctx context.Context, shardKey string, logger logr.Logger) {
func upgradeDriftDetectionDeploymentsInManagedClusters(ctx context.Context, shardKey string,
logger logr.Logger) {

const two = 2
const maxRetryAfter = two * time.Minute // Maximum sleep duration
retryAfter := 10 * time.Second
Expand Down Expand Up @@ -308,7 +310,7 @@ func skipUpgrading(ctx context.Context, c client.Client, cluster client.Object,
func isDriftDetectionManagerDeployedInCluster(ctx context.Context, c client.Client) (bool, error) {
deployment := &appsv1.Deployment{}
// A test in pkg/drift-detection makes sure this name is correct
err := c.Get(ctx, types.NamespacedName{Namespace: projectsveltos, Name: "drift-detection-manager"}, deployment)
err := c.Get(ctx, types.NamespacedName{Namespace: getSveltosNamespace(), Name: "drift-detection-manager"}, deployment)

if err != nil {
if apierrors.IsNotFound(err) {
Expand Down
4 changes: 2 additions & 2 deletions controllers/drift_detection_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ var _ = Describe("Drift Detection Upgrade", func() {
depl := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "drift-detection-manager",
Namespace: "projectsveltos",
Namespace: sveltosNamespace,
Labels: map[string]string{
"control-plane": "drift-detection-manager",
},
Expand All @@ -171,7 +171,7 @@ var _ = Describe("Drift Detection Upgrade", func() {
depl := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "some-other-deployment",
Namespace: "projectsveltos",
Namespace: sveltosNamespace,
Labels: map[string]string{
"control-plane": "drift-detection-manager",
},
Expand Down
13 changes: 11 additions & 2 deletions controllers/management_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
managementClusterMapper *restmapper.DeferredDiscoveryRESTMapper
managementClusterCachedDiscovery discovery.CachedDiscoveryInterface

sveltosNamespace string
driftdetectionConfigMap string
luaConfigMap string
capiOnboardAnnotation string
Expand Down Expand Up @@ -79,6 +80,10 @@ func SetAgentInMgmtCluster(isInMgmtCluster bool) {
agentInMgmtCluster = isInMgmtCluster
}

func SetSveltosNamespace(namespace string) {
sveltosNamespace = namespace
}

func getManagementClusterConfig() *rest.Config {
return managementClusterConfig
}
Expand Down Expand Up @@ -119,6 +124,10 @@ func getAgentInMgmtCluster() bool {
return agentInMgmtCluster
}

func getSveltosNamespace() string {
return sveltosNamespace
}

func resetManagementClusterMapper() {
managementClusterMapper.Reset()
}
Expand All @@ -131,7 +140,7 @@ func collectDriftDetectionConfigMap(ctx context.Context) (*corev1.ConfigMap, err
c := getManagementClusterClient()
configMap := &corev1.ConfigMap{}

err := c.Get(ctx, types.NamespacedName{Namespace: projectsveltos, Name: getDriftDetectionConfigMap()},
err := c.Get(ctx, types.NamespacedName{Namespace: sveltosNamespace, Name: getDriftDetectionConfigMap()},
configMap)
if err != nil {
return nil, err
Expand All @@ -144,7 +153,7 @@ func collectLuaConfigMap(ctx context.Context) (*corev1.ConfigMap, error) {
c := getManagementClusterClient()
configMap := &corev1.ConfigMap{}

err := c.Get(ctx, types.NamespacedName{Namespace: projectsveltos, Name: getLuaConfigMap()},
err := c.Get(ctx, types.NamespacedName{Namespace: sveltosNamespace, Name: getLuaConfigMap()},
configMap)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions controllers/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
var (
programResourceDurationHistogram = prometheus.NewHistogram(
prometheus.HistogramOpts{
Namespace: "projectsveltos",
Namespace: getSveltosNamespace(),
Name: "program_resources_time_seconds",
Help: "Program Resources on a workload cluster duration distribution",
Buckets: []float64{0.5, 1, 1.5, 2, 3, 5, 10, 30, 60, 90, 120},
Expand All @@ -39,7 +39,7 @@ var (

programChartDurationHistogram = prometheus.NewHistogram(
prometheus.HistogramOpts{
Namespace: "projectsveltos",
Namespace: getSveltosNamespace(),
Name: "program_charts_time_seconds",
Help: "Program Helm charts on a workload cluster duration distribution",
Buckets: []float64{0.5, 1, 1.5, 2, 3, 5, 10, 30, 60, 90, 120},
Expand All @@ -48,7 +48,7 @@ var (

reconciliationCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "projectsveltos",
Namespace: getSveltosNamespace(),
Name: "reconcile_operations_total",
Help: "Total number of reconcile operations for Helm, Resources, and Kustomization",
},
Expand All @@ -57,7 +57,7 @@ var (

driftCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "projectsveltos",
Namespace: getSveltosNamespace(),
Name: "total_drifts",
Help: "Total number of drifts for a given cluster indexed via type, namespace/name and feature id",
},
Expand Down
Loading