diff --git a/COMPONENT_VERSION b/COMPONENT_VERSION index 10c2c0c3d..46b81d815 100644 --- a/COMPONENT_VERSION +++ b/COMPONENT_VERSION @@ -1 +1 @@ -2.10.0 +2.11.0 diff --git a/operators/endpointmetrics/controllers/observabilityendpoint/match_evaluator_test.go b/operators/endpointmetrics/controllers/observabilityendpoint/match_evaluator_test.go index b98f809a6..749359670 100644 --- a/operators/endpointmetrics/controllers/observabilityendpoint/match_evaluator_test.go +++ b/operators/endpointmetrics/controllers/observabilityendpoint/match_evaluator_test.go @@ -22,7 +22,7 @@ func TestEvluateMatchExpression(t *testing.T) { expr: metav1.LabelSelectorRequirement{ Key: "test_key", Operator: "In", - Values: []string{"SNO"}, + Values: []string{snoClusterType}, }, expectedResult: false, }, @@ -31,7 +31,7 @@ func TestEvluateMatchExpression(t *testing.T) { expr: metav1.LabelSelectorRequirement{ Key: "clusterType", Operator: "test_op", - Values: []string{"SNO"}, + Values: []string{snoClusterType}, }, expectedResult: false, }, @@ -40,9 +40,9 @@ func TestEvluateMatchExpression(t *testing.T) { expr: metav1.LabelSelectorRequirement{ Key: "clusterType", Operator: "NotIn", - Values: []string{"SNO"}, + Values: []string{snoClusterType}, }, - clusterType: "SNO", + clusterType: snoClusterType, expectedResult: false, }, { @@ -50,7 +50,7 @@ func TestEvluateMatchExpression(t *testing.T) { expr: metav1.LabelSelectorRequirement{ Key: "clusterType", Operator: "In", - Values: []string{"SNO"}, + Values: []string{snoClusterType}, }, clusterType: "", expectedResult: false, @@ -60,7 +60,7 @@ func TestEvluateMatchExpression(t *testing.T) { expr: metav1.LabelSelectorRequirement{ Key: "clusterType", Operator: "NotIn", - Values: []string{"SNO"}, + Values: []string{snoClusterType}, }, clusterType: "", expectedResult: true, @@ -70,9 +70,9 @@ func TestEvluateMatchExpression(t *testing.T) { expr: metav1.LabelSelectorRequirement{ Key: "clusterType", Operator: "In", - Values: []string{"SNO"}, + Values: []string{snoClusterType}, }, - clusterType: "SNO", + clusterType: snoClusterType, expectedResult: true, }, } diff --git a/operators/endpointmetrics/controllers/observabilityendpoint/metrics_collector.go b/operators/endpointmetrics/controllers/observabilityendpoint/metrics_collector.go index 04573eb91..174d0a6c6 100644 --- a/operators/endpointmetrics/controllers/observabilityendpoint/metrics_collector.go +++ b/operators/endpointmetrics/controllers/observabilityendpoint/metrics_collector.go @@ -110,7 +110,7 @@ func getCommands(params CollectorParams) []string { if !installPrometheus { commands = append(commands, "--from-ca-file="+caFile) } - if params.clusterType != "" { + if params.clusterType != defaultClusterType { commands = append(commands, fmt.Sprintf("--label=\"clusterType=%s\"", params.clusterType)) } @@ -203,32 +203,39 @@ func createDeployment(params CollectorParams) *appsv1.Deployment { }, }, }, - { - Name: "secret-kube-rbac-proxy-tls", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: secretName + "-kube-rbac-tls", + } + + if params.clusterType != ocpThreeClusterType { + serviceCAOperatorGenerated := []corev1.Volume{ + { + Name: "secret-kube-rbac-proxy-tls", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: secretName + "-kube-rbac-tls", + }, }, }, - }, - { - Name: "secret-kube-rbac-proxy-metric", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: secretName + "-kube-rbac-proxy-metric", + { + Name: "secret-kube-rbac-proxy-metric", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: secretName + "-kube-rbac-proxy-metric", + }, }, }, - }, - { - Name: "metrics-client-ca", - VolumeSource: corev1.VolumeSource{ - ConfigMap: &corev1.ConfigMapVolumeSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: secretName + "-clientca-metric", + { + Name: "metrics-client-ca", + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: secretName + "-clientca-metric", + }, }, }, }, - }, + } + + volumes = append(volumes, serviceCAOperatorGenerated...) } mounts := []corev1.VolumeMount{ { @@ -362,15 +369,12 @@ func createDeployment(params CollectorParams) *appsv1.Deployment { } if hubMetricsCollector { - //to avoid hub metrics collector from sending status + // to avoid hub metrics collector from sending status metricsCollectorDep.Spec.Template.Spec.Containers[0].Env = append(metricsCollectorDep.Spec.Template.Spec.Containers[0].Env, corev1.EnvVar{ Name: "STANDALONE", Value: "true", }) - - //Since there is no obsAddOn for hub-metrics-collector, we need to set the resources here - metricsCollectorDep.Spec.Template.Spec.Containers[0].Resources = operatorconfig.HubMetricsCollectorResources } privileged := false @@ -760,7 +764,7 @@ func getMetricsAllowlist(ctx context.Context, c client.Client, } else { if cm.Data != nil { configmapKey := operatorconfig.MetricsConfigMapKey - if clusterType == "ocp3" { + if clusterType == ocpThreeClusterType { configmapKey = operatorconfig.MetricsOcp311ConfigMapKey } err = yaml.Unmarshal([]byte(cm.Data[configmapKey]), l) diff --git a/operators/endpointmetrics/controllers/observabilityendpoint/metrics_collector_test.go b/operators/endpointmetrics/controllers/observabilityendpoint/metrics_collector_test.go index e4f39874a..709282427 100644 --- a/operators/endpointmetrics/controllers/observabilityendpoint/metrics_collector_test.go +++ b/operators/endpointmetrics/controllers/observabilityendpoint/metrics_collector_test.go @@ -185,7 +185,7 @@ func TestMetricsCollector(t *testing.T) { params := CollectorParams{ isUWL: false, clusterID: testClusterID, - clusterType: "", + clusterType: defaultClusterType, obsAddonSpec: obsAddon, hubInfo: *hubInfo, allowlist: list, @@ -212,7 +212,7 @@ func TestMetricsCollector(t *testing.T) { params.replicaCount = 1 params.clusterID = testClusterID + "-update" - params.clusterType = "SNO" + params.clusterType = snoClusterType _, err = updateMetricsCollector(ctx, c, params, false) if err != nil { t.Fatalf("Failed to create metrics collector deployment: (%v)", err) diff --git a/operators/endpointmetrics/controllers/observabilityendpoint/observabilityaddon_controller.go b/operators/endpointmetrics/controllers/observabilityendpoint/observabilityaddon_controller.go index 4bf628e3e..5f5c3426d 100644 --- a/operators/endpointmetrics/controllers/observabilityendpoint/observabilityaddon_controller.go +++ b/operators/endpointmetrics/controllers/observabilityendpoint/observabilityaddon_controller.go @@ -34,6 +34,7 @@ import ( "github.com/stolostron/multicluster-observability-operator/operators/endpointmetrics/pkg/rendering" "github.com/stolostron/multicluster-observability-operator/operators/endpointmetrics/pkg/util" oav1beta1 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta1" + oav1beta2 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta1" operatorconfig "github.com/stolostron/multicluster-observability-operator/operators/pkg/config" "github.com/stolostron/multicluster-observability-operator/operators/pkg/deploying" rendererutil "github.com/stolostron/multicluster-observability-operator/operators/pkg/rendering" @@ -47,14 +48,18 @@ var ( const ( obAddonName = "observability-addon" - mcoCRName = "observability" ownerLabelKey = "owner" ownerLabelValue = "observabilityaddon" obsAddonFinalizer = "observability.open-cluster-management.io/addon-cleanup" promSvcName = "prometheus-k8s" promNamespace = "openshift-monitoring" openShiftClusterMonitoringlabel = "openshift.io/cluster-monitoring" - hubMetricsCollectionNamespace = "open-cluster-management-observability" +) + +const ( + defaultClusterType = "" + ocpThreeClusterType = "ocp3" + snoClusterType = "SNO" ) var ( @@ -157,13 +162,15 @@ func (r *ObservabilityAddonReconciler) Reconcile(ctx context.Context, req ctrl.R } hubInfo.ClusterName = string(hubSecret.Data[operatorconfig.ClusterNameKey]) - clusterType := "" + clusterType := defaultClusterType clusterID := "" - //read the image configmap + // read the image configmap imagesCM := &corev1.ConfigMap{} - err = r.Client.Get(ctx, types.NamespacedName{Name: operatorconfig.ImageConfigMap, - Namespace: namespace}, imagesCM) + err = r.Client.Get(ctx, types.NamespacedName{ + Name: operatorconfig.ImageConfigMap, + Namespace: namespace, + }, imagesCM) if err != nil { log.Error(err, "Failed to get images configmap") return ctrl.Result{}, err @@ -180,8 +187,10 @@ func (r *ObservabilityAddonReconciler) Reconcile(ctx context.Context, req ctrl.R if !installPrometheus { // If no prometheus service found, set status as NotSupported promSvc := &corev1.Service{} - err = r.Client.Get(ctx, types.NamespacedName{Name: promSvcName, - Namespace: promNamespace}, promSvc) + err = r.Client.Get(ctx, types.NamespacedName{ + Name: promSvcName, + Namespace: promNamespace, + }, promSvc) if err != nil { if errors.IsNotFound(err) { log.Error(err, "OCP prometheus service does not exist") @@ -199,11 +208,11 @@ func (r *ObservabilityAddonReconciler) Reconcile(ctx context.Context, req ctrl.R // OCP 3.11 has no cluster id, set it as empty string clusterID = "" // to differentiate ocp 3.x - clusterType = "ocp3" + clusterType = ocpThreeClusterType } isSNO, err := isSNO(ctx, r.Client) if err == nil && isSNO { - clusterType = "SNO" + clusterType = snoClusterType } err = createMonitoringClusterRoleBinding(ctx, r.Client) if err != nil { @@ -214,7 +223,7 @@ func (r *ObservabilityAddonReconciler) Reconcile(ctx context.Context, req ctrl.R return ctrl.Result{}, err } } else { - //Render the prometheus templates + // Render the prometheus templates renderer := rendererutil.NewRenderer() toDeploy, err := rendering.Render(renderer, r.Client, hubInfo) if err != nil { @@ -240,11 +249,22 @@ func (r *ObservabilityAddonReconciler) Reconcile(ctx context.Context, req ctrl.R return ctrl.Result{}, err } - forceRestart := false - if req.Name == mtlsCertName || req.Name == mtlsCaName || req.Name == caConfigmapName { - forceRestart = true - } + forceRestart := req.Name == mtlsCertName || req.Name == mtlsCaName || req.Name == caConfigmapName + if obsAddon.Spec.EnableMetrics || hubMetricsCollector { + if hubMetricsCollector { + mcoList := &oav1beta2.MultiClusterObservabilityList{} + err := r.HubClient.List(ctx, mcoList, client.InNamespace(corev1.NamespaceAll)) + if err != nil { + log.Error(err, "Failed to get multiclusterobservability") + return ctrl.Result{}, err + } + if len(mcoList.Items) != 1 { + log.Error(nil, fmt.Sprintf("Expected 1 multiclusterobservability, found %d", len(mcoList.Items))) + return ctrl.Result{}, nil + } + obsAddon.Spec = *mcoList.Items[0].Spec.ObservabilityAddonSpec + } created, err := updateMetricsCollectors( ctx, r.Client, @@ -253,7 +273,6 @@ func (r *ObservabilityAddonReconciler) Reconcile(ctx context.Context, req ctrl.R clusterType, 1, forceRestart) - if err != nil { util.ReportStatus(ctx, r.Client, obsAddon, "Degraded", !hubMetricsCollector) return ctrl.Result{}, err @@ -271,13 +290,14 @@ func (r *ObservabilityAddonReconciler) Reconcile(ctx context.Context, req ctrl.R } } - //TODO: UPDATE + // TODO: UPDATE return ctrl.Result{}, nil } func (r *ObservabilityAddonReconciler) initFinalization( ctx context.Context, delete bool, hubObsAddon *oav1beta1.ObservabilityAddon, - isHypershift bool) (bool, error) { + isHypershift bool, +) (bool, error) { if delete && slices.Contains(hubObsAddon.GetFinalizers(), obsAddonFinalizer) { log.Info("To clean observability components/configurations in the cluster") err := deleteMetricsCollector(ctx, r.Client, metricsCollectorName) diff --git a/operators/multiclusterobservability/controllers/multiclusterobservability/multiclusterobservability_controller.go b/operators/multiclusterobservability/controllers/multiclusterobservability/multiclusterobservability_controller.go index 46aa98dd3..fa7962bd2 100644 --- a/operators/multiclusterobservability/controllers/multiclusterobservability/multiclusterobservability_controller.go +++ b/operators/multiclusterobservability/controllers/multiclusterobservability/multiclusterobservability_controller.go @@ -42,6 +42,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/source" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + mchv1 "github.com/stolostron/multiclusterhub-operator/api/v1" + observatoriumv1alpha1 "github.com/stolostron/observatorium-operator/api/v1alpha1" + mcov1beta2 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta2" placementctrl "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/controllers/placementrule" certctrl "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/certificates" @@ -52,8 +55,6 @@ import ( "github.com/stolostron/multicluster-observability-operator/operators/pkg/deploying" commonutil "github.com/stolostron/multicluster-observability-operator/operators/pkg/util" operatorsutil "github.com/stolostron/multicluster-observability-operator/operators/pkg/util" - mchv1 "github.com/stolostron/multiclusterhub-operator/api/v1" - observatoriumv1alpha1 "github.com/stolostron/observatorium-operator/api/v1alpha1" ) const ( @@ -240,14 +241,13 @@ func (r *MultiClusterObservabilityReconciler) Reconcile(ctx context.Context, req return *result, err } - //set operand names to cover the upgrade case since we have name changed in new release + // set operand names to cover the upgrade case since we have name changed in new release err = config.SetOperandNames(r.Client) if err != nil { return *result, err } - //instance.Namespace = config.GetDefaultNamespace() instance.Spec.StorageConfig.StorageClass = storageClassSelected - //Render the templates with a specified CR + // Render the templates with a specified CR renderer := rendering.NewMCORenderer(instance, r.Client) toDeploy, err := renderer.Render() if err != nil { @@ -255,7 +255,7 @@ func (r *MultiClusterObservabilityReconciler) Reconcile(ctx context.Context, req return ctrl.Result{}, err } deployer := deploying.NewDeployer(r.Client) - //Deploy the resources + // Deploy the resources ns := &corev1.Namespace{} for _, res := range toDeploy { resNS := res.GetNamespace() @@ -363,7 +363,7 @@ func (r *MultiClusterObservabilityReconciler) Reconcile(ctx context.Context, req isLegacyResourceRemoved = true } - //update status + // update status requeueStatusUpdate <- struct{}{} return ctrl.Result{}, nil diff --git a/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go b/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go index 684a4cad7..65c478127 100644 --- a/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go +++ b/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go @@ -36,16 +36,17 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" + mchv1 "github.com/stolostron/multiclusterhub-operator/api/v1" + addonv1alpha1 "open-cluster-management.io/api/addon/v1alpha1" + clusterv1 "open-cluster-management.io/api/cluster/v1" + workv1 "open-cluster-management.io/api/work/v1" + mcov1beta1 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta1" mcov1beta2 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta2" "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/config" "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/util" operatorconfig "github.com/stolostron/multicluster-observability-operator/operators/pkg/config" commonutil "github.com/stolostron/multicluster-observability-operator/operators/pkg/util" - mchv1 "github.com/stolostron/multiclusterhub-operator/api/v1" - addonv1alpha1 "open-cluster-management.io/api/addon/v1alpha1" - clusterv1 "open-cluster-management.io/api/cluster/v1" - workv1 "open-cluster-management.io/api/work/v1" ) const ( @@ -57,8 +58,7 @@ const ( ) var ( - log = logf.Log.WithName("controller_placementrule") - //watchNamespace = config.GetDefaultNamespace() + log = logf.Log.WithName("controller_placementrule") isCRoleCreated = false clusterAddon = &addonv1alpha1.ClusterManagementAddOn{} defaultAddonDeploymentConfig = &addonv1alpha1.AddOnDeploymentConfig{} @@ -190,7 +190,6 @@ func (r *PlacementRuleReconciler) Reconcile(ctx context.Context, req ctrl.Reques }, }, }) - operatorconfig.HubMetricsCollectorResources = *config.GetOBAResources(mco.Spec.ObservabilityAddonSpec) err = deleteObsAddon(r.Client, localClusterName) if err != nil { log.Error(err, "Failed to delete observabilityaddon") @@ -335,11 +334,21 @@ func createAllRelatedRes( isCRoleCreated = true } - //Get or create ClusterManagementAddon + // Get or create ClusterManagementAddon clusterAddon, err = util.CreateClusterManagementAddon(c) if err != nil { return err } + + // Always start this loop with an empty addon deployment config. + // This simplifies the logic for the cases where: + // - There is nothing in `Spec.SupportedConfigs`. + // - There's something in `Spec.SupportedConfigs`, but none of them are for + // the group and resource that we care about. + // - There is something in `Spec.SupportedConfigs`, the group and resource are correct, + // but the default config is not present in the manifest or it is not found + // (i.e. was deleted or there's a typo). + defaultAddonDeploymentConfig = &addonv1alpha1.AddOnDeploymentConfig{} for _, config := range clusterAddon.Spec.SupportedConfigs { if config.ConfigGroupResource.Group == util.AddonGroup && config.ConfigGroupResource.Resource == util.AddonDeploymentConfigResource { @@ -474,7 +483,7 @@ func deleteGlobalResource(c client.Client) error { return err } isCRoleCreated = false - //delete ClusterManagementAddon + // delete ClusterManagementAddon err = util.DeleteClusterManagementAddon(c) if err != nil { return err @@ -543,7 +552,6 @@ func createManagedClusterRes( } func deleteManagedClusterRes(c client.Client, namespace string) error { - managedclusteraddon := &addonv1alpha1.ManagedClusterAddOn{ ObjectMeta: metav1.ObjectMeta{ Name: util.ManagedClusterAddonName, @@ -599,7 +607,7 @@ func (r *PlacementRuleReconciler) SetupWithManager(mgr ctrl.Manager) error { clusterPred := getClusterPreds() // Watch changes for AddonDeploymentConfig - AddonDeploymentPred := GetAddOnDeploymentPredicates() + addOnDeploymentConfigPred := GetAddOnDeploymentConfigPredicates() // Watch changes to endpoint-operator deployment hubEndpointOperatorPred := getHubEndpointOperatorPredicates() @@ -900,8 +908,9 @@ func (r *PlacementRuleReconciler) SetupWithManager(mgr ctrl.Manager) error { // secondary watch for alertmanager accessor serviceaccount Watches(&source.Kind{Type: &corev1.ServiceAccount{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(amAccessorSAPred)) - // watch for AddonDeploymentConfig - if _, err := r.RESTMapper.RESTMapping(schema.GroupKind{Group: addonv1alpha1.GroupVersion.Group, Kind: "AddOnDeploymentConfig"}, addonv1alpha1.GroupVersion.Version); err == nil { + // watch for AddOnDeploymentConfig + addOnDeploymentConfigGroupKind := schema.GroupKind{Group: addonv1alpha1.GroupVersion.Group, Kind: "AddOnDeploymentConfig"} + if _, err := r.RESTMapper.RESTMapping(addOnDeploymentConfigGroupKind, addonv1alpha1.GroupVersion.Version); err == nil { ctrBuilder = ctrBuilder.Watches( &source.Kind{Type: &addonv1alpha1.AddOnDeploymentConfig{}}, handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request { @@ -911,7 +920,7 @@ func (r *PlacementRuleReconciler) SetupWithManager(mgr ctrl.Manager) error { }}, } }), - builder.WithPredicates(AddonDeploymentPred), + builder.WithPredicates(addOnDeploymentConfigPred), ) } manifestWorkGroupKind := schema.GroupKind{Group: workv1.GroupVersion.Group, Kind: "ManifestWork"} diff --git a/operators/multiclusterobservability/controllers/placementrule/predicate_func.go b/operators/multiclusterobservability/controllers/placementrule/predicate_func.go index 928e4ceb2..013c1ce11 100644 --- a/operators/multiclusterobservability/controllers/placementrule/predicate_func.go +++ b/operators/multiclusterobservability/controllers/placementrule/predicate_func.go @@ -100,18 +100,19 @@ func getClusterPreds() predicate.Funcs { } } -func GetAddOnDeploymentPredicates() predicate.Funcs { +func GetAddOnDeploymentConfigPredicates() predicate.Funcs { return predicate.Funcs{ CreateFunc: func(e event.CreateEvent) bool { return true }, UpdateFunc: func(e event.UpdateEvent) bool { - if !reflect.DeepEqual(e.ObjectNew.(*addonv1alpha1.AddOnDeploymentConfig).Spec.ProxyConfig, - e.ObjectOld.(*addonv1alpha1.AddOnDeploymentConfig).Spec.ProxyConfig) { - log.Info("AddonDeploymentConfig is updated", e.ObjectNew.GetName(), "name", e.ObjectNew.GetNamespace(), "namespace") - return true + newObj := e.ObjectNew.(*addonv1alpha1.AddOnDeploymentConfig) + oldObj := e.ObjectOld.(*addonv1alpha1.AddOnDeploymentConfig) + if reflect.DeepEqual(newObj.Spec, oldObj.Spec) { + return false } - return false + log.Info("AddonDeploymentConfig is updated", e.ObjectNew.GetName(), "name", e.ObjectNew.GetNamespace(), "namespace") + return true }, DeleteFunc: func(e event.DeleteEvent) bool { return true diff --git a/operators/multiclusterobservability/controllers/placementrule/predicate_func_test.go b/operators/multiclusterobservability/controllers/placementrule/predicate_func_test.go index 6ae231f98..157027733 100644 --- a/operators/multiclusterobservability/controllers/placementrule/predicate_func_test.go +++ b/operators/multiclusterobservability/controllers/placementrule/predicate_func_test.go @@ -144,12 +144,11 @@ func TestClusterPred(t *testing.T) { t.Fatalf("HubInpre funcfoPred return true on deleteevent in case: (%v)", c.caseName) } } - }) } } -func TestAddonDeploymentPredicate(t *testing.T) { +func TestAddOnDeploymentConfigPredicate(t *testing.T) { name := "test-obj" caseList := []struct { caseName string @@ -157,13 +156,78 @@ func TestAddonDeploymentPredicate(t *testing.T) { expectedCreate bool expectedUpdate bool expectedDelete bool + createEvent *event.CreateEvent + updateEvent func() event.UpdateEvent + deleteEvent *event.DeleteEvent }{ { caseName: "Create AddonDeploymentConfig", namespace: testNamespace, expectedCreate: true, - expectedDelete: true, + createEvent: &event.CreateEvent{ + Object: defaultAddonDeploymentConfig, + }, + }, + { + caseName: "Update AddonDeploymentConfig with Spec.ProxyConfig changes", + namespace: testNamespace, expectedUpdate: true, + updateEvent: func() event.UpdateEvent { + newDefaultAddonDeploymentConfig := defaultAddonDeploymentConfig.DeepCopy() + newDefaultAddonDeploymentConfig.Spec.ProxyConfig.HTTPProxy = "http://bar1.com" + return event.UpdateEvent{ + ObjectOld: defaultAddonDeploymentConfig, + ObjectNew: newDefaultAddonDeploymentConfig, + } + }, + }, + { + caseName: "Update AddonDeploymentConfig with Spec.NodePlacement changes", + namespace: testNamespace, + expectedUpdate: true, + updateEvent: func() event.UpdateEvent { + newDefaultAddonDeploymentConfig := defaultAddonDeploymentConfig.DeepCopy() + newDefaultAddonDeploymentConfig.Spec.NodePlacement = &addonv1alpha1.NodePlacement{ + NodeSelector: map[string]string{"foo": "bar"}, + } + return event.UpdateEvent{ + ObjectOld: defaultAddonDeploymentConfig, + ObjectNew: newDefaultAddonDeploymentConfig, + } + }, + }, + { + caseName: "Update AddonDeploymentConfig without Spec changes", + namespace: testNamespace, + expectedUpdate: false, + updateEvent: func() event.UpdateEvent { + newDefaultAddonDeploymentConfig := defaultAddonDeploymentConfig.DeepCopy() + newDefaultAddonDeploymentConfig.Labels = map[string]string{"foo": "bar"} + return event.UpdateEvent{ + ObjectOld: defaultAddonDeploymentConfig, + ObjectNew: newDefaultAddonDeploymentConfig, + } + }, + }, + { + caseName: "Update AddonDeploymentConfig with the same Spec ", + namespace: testNamespace, + expectedUpdate: false, + updateEvent: func() event.UpdateEvent { + newDefaultAddonDeploymentConfig := defaultAddonDeploymentConfig.DeepCopy() + return event.UpdateEvent{ + ObjectOld: defaultAddonDeploymentConfig, + ObjectNew: newDefaultAddonDeploymentConfig, + } + }, + }, + { + caseName: "Delete AddonDeploymentConfig", + namespace: testNamespace, + expectedDelete: true, + deleteEvent: &event.DeleteEvent{ + Object: defaultAddonDeploymentConfig, + }, }, } @@ -182,35 +246,26 @@ func TestAddonDeploymentPredicate(t *testing.T) { } for _, c := range caseList { t.Run(c.caseName, func(t *testing.T) { - pred := GetAddOnDeploymentPredicates() - createEvent := event.CreateEvent{ - Object: defaultAddonDeploymentConfig, - } + pred := GetAddOnDeploymentConfigPredicates() - if c.expectedCreate { - if !pred.CreateFunc(createEvent) { - t.Fatalf("pre func return false on applied createevent in case: (%v)", c.caseName) + if c.createEvent != nil { + gotCreate := pred.CreateFunc(*c.createEvent) + if gotCreate != c.expectedCreate { + t.Fatalf("%s: expected predicate to return '%v' on applied create event. Got '%v'", c.caseName, c.expectedCreate, gotCreate) } } - newDefaultAddonDeploymentConfig := defaultAddonDeploymentConfig.DeepCopy() - newDefaultAddonDeploymentConfig.Spec.ProxyConfig.HTTPProxy = "http://bar1.com" - updateEvent := event.UpdateEvent{ - ObjectOld: defaultAddonDeploymentConfig, - ObjectNew: newDefaultAddonDeploymentConfig, - } - if c.expectedUpdate { - if !pred.UpdateFunc(updateEvent) { - t.Fatalf("pre func return false on applied update event in case: (%v)", c.caseName) + if c.updateEvent != nil { + gotUpdate := pred.UpdateFunc(c.updateEvent()) + if gotUpdate != c.expectedUpdate { + t.Fatalf("%s: expected predicate to return '%v' on applied update event. Got '%v'", c.caseName, c.expectedUpdate, gotUpdate) } } - deleteEvent := event.DeleteEvent{ - Object: defaultAddonDeploymentConfig, - } - if c.expectedDelete { - if !pred.DeleteFunc(deleteEvent) { - t.Fatalf("pre func return false on applied delete event in case: (%v)", c.caseName) + if c.deleteEvent != nil { + gotDelete := pred.DeleteFunc(*c.deleteEvent) + if gotDelete != c.expectedDelete { + t.Fatalf("%s: expected predicate to return '%v' on applied delete event. Got '%v'", c.caseName, c.expectedDelete, gotDelete) } } }) diff --git a/operators/multiclusterobservability/main.go b/operators/multiclusterobservability/main.go index b8ab58f8b..e59d0cee2 100644 --- a/operators/multiclusterobservability/main.go +++ b/operators/multiclusterobservability/main.go @@ -35,6 +35,12 @@ import ( ctrlwebhook "sigs.k8s.io/controller-runtime/pkg/webhook" migrationv1alpha1 "sigs.k8s.io/kube-storage-version-migrator/pkg/apis/migration/v1alpha1" + mchv1 "github.com/stolostron/multiclusterhub-operator/api/v1" + observatoriumAPIs "github.com/stolostron/observatorium-operator/api/v1alpha1" + addonv1alpha1 "open-cluster-management.io/api/addon/v1alpha1" + clusterv1 "open-cluster-management.io/api/cluster/v1" + workv1 "open-cluster-management.io/api/work/v1" + observabilityv1beta1 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta1" observabilityv1beta2 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta2" mcoctrl "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/controllers/multiclusterobservability" @@ -42,11 +48,6 @@ import ( "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/util" "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/webhook" operatorsutil "github.com/stolostron/multicluster-observability-operator/operators/pkg/util" - mchv1 "github.com/stolostron/multiclusterhub-operator/api/v1" - observatoriumAPIs "github.com/stolostron/observatorium-operator/api/v1alpha1" - addonv1alpha1 "open-cluster-management.io/api/addon/v1alpha1" - clusterv1 "open-cluster-management.io/api/cluster/v1" - workv1 "open-cluster-management.io/api/work/v1" // +kubebuilder:scaffold:imports ) diff --git a/operators/pkg/config/config.go b/operators/pkg/config/config.go index 56716fad4..85a087f9b 100644 --- a/operators/pkg/config/config.go +++ b/operators/pkg/config/config.go @@ -4,8 +4,6 @@ package config -import corev1 "k8s.io/api/core/v1" - const ( ClusterNameKey = "cluster-name" HubInfoSecretName = "hub-info-secret" @@ -61,18 +59,15 @@ const ( WorkloadPartitioningNSExpectedValue = "management" ) -var ( - ImageKeyNameMap = map[string]string{ - PrometheusKey: PrometheusKey, - KubeStateMetricsKey: KubeStateMetricsImgName, - NodeExporterKey: NodeExporterImgName, - KubeRbacProxyKey: KubeRbacProxyImgName, - MetricsCollectorKey: MetricsCollectorImgName, - PrometheusConfigmapReloaderKey: PrometheusConfigmapReloaderImgName, - } -) +var ImageKeyNameMap = map[string]string{ + PrometheusKey: PrometheusKey, + KubeStateMetricsKey: KubeStateMetricsImgName, + NodeExporterKey: NodeExporterImgName, + KubeRbacProxyKey: KubeRbacProxyImgName, + MetricsCollectorKey: MetricsCollectorImgName, + PrometheusConfigmapReloaderKey: PrometheusConfigmapReloaderImgName, +} var ( - HubMetricsCollectorResources = corev1.ResourceRequirements{} - IsMCOTerminating = false + IsMCOTerminating = false ) diff --git a/sonar-project.properties b/sonar-project.properties index 545f9a3e1..77a0de306 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -13,6 +13,6 @@ sonar.externalIssuesReportPaths=gosec.json # https://docs.sonarsource.com/sonarcloud/advanced-setup/analysis-scope/#ignoring-specific-rules-from-specific-files # ignore long lines rule -sonar.issue.ignore.imulticriteria=m1 +sonar.issue.ignore.multicriteria=m1 sonar.issue.ignore.multicriteria.m1.ruleKey=go:S103 sonar.issue.ignore.multicriteria.m1.resourceKey=**/*.go \ No newline at end of file