From 828f33c837c2228318890a6aa0c9b79ac87301df Mon Sep 17 00:00:00 2001 From: VaishnaviHire Date: Tue, 26 Nov 2024 19:43:21 -0500 Subject: [PATCH] Update label to platform.opendatahub.io --- .../dashboard/dashboard_controller_actions.go | 4 ++++ .../monitoring/monitoring_controller.go | 4 ++-- .../monitoring_controller_actions.go | 2 +- .../kustomize/action_render_manifests_test.go | 4 ++-- .../reconciler/reconciler_support.go | 17 ++++--------- pkg/metadata/labels/types.go | 3 +-- tests/e2e/dashboard_test.go | 24 +++++++++++++++++++ 7 files changed, 39 insertions(+), 19 deletions(-) diff --git a/controllers/components/dashboard/dashboard_controller_actions.go b/controllers/components/dashboard/dashboard_controller_actions.go index 0458803ee0a..55659e5d457 100644 --- a/controllers/components/dashboard/dashboard_controller_actions.go +++ b/controllers/components/dashboard/dashboard_controller_actions.go @@ -111,7 +111,11 @@ func updateStatus(ctx context.Context, rr *odhtypes.ReconciliationRequest) error &rl, client.InNamespace(rr.DSCI.Spec.ApplicationsNamespace), client.MatchingLabels(map[string]string{ +<<<<<<< HEAD labels.ComponentPartOf: strings.ToLower(componentsv1.DashboardKind), +======= + labels.PlatformPartOf: componentsv1.DashboardInstanceName, +>>>>>>> 51e8117b (Update label to platform.opendatahub.io) }), ) diff --git a/controllers/services/monitoring/monitoring_controller.go b/controllers/services/monitoring/monitoring_controller.go index d2550ec14bf..954f702ed03 100644 --- a/controllers/services/monitoring/monitoring_controller.go +++ b/controllers/services/monitoring/monitoring_controller.go @@ -88,10 +88,10 @@ func NewServiceReconciler(ctx context.Context, mgr ctrl.Manager) error { WithAction(deploy.NewAction( deploy.WithCache(), deploy.WithFieldOwner(servicesv1.MonitoringInstanceName), - deploy.WithLabel(labels.ServicePartOf, servicesv1.MonitoringServiceName), + deploy.WithLabel(labels.PlatformPartOf, servicesv1.MonitoringServiceName), )). WithAction(updatestatus.NewAction( - updatestatus.WithSelectorLabel(labels.ServicePartOf, servicesv1.MonitoringServiceName), + updatestatus.WithSelectorLabel(labels.PlatformPartOf, servicesv1.MonitoringServiceName), )). WithAction(updateStatus). Build(ctx) diff --git a/controllers/services/monitoring/monitoring_controller_actions.go b/controllers/services/monitoring/monitoring_controller_actions.go index cf601796fd8..00f2bd386b7 100644 --- a/controllers/services/monitoring/monitoring_controller_actions.go +++ b/controllers/services/monitoring/monitoring_controller_actions.go @@ -31,7 +31,7 @@ func updateStatus(ctx context.Context, rr *odhtypes.ReconciliationRequest) error &rl, client.InNamespace(rr.DSCI.Spec.Monitoring.Namespace), client.MatchingLabels(map[string]string{ - labels.ServicePartOf: servicesv1.MonitoringServiceName, + labels.PlatformPartOf: servicesv1.MonitoringServiceName, }), ) diff --git a/pkg/controller/actions/render/kustomize/action_render_manifests_test.go b/pkg/controller/actions/render/kustomize/action_render_manifests_test.go index 6043ab1764c..da030e17d2e 100644 --- a/pkg/controller/actions/render/kustomize/action_render_manifests_test.go +++ b/pkg/controller/actions/render/kustomize/action_render_manifests_test.go @@ -194,7 +194,7 @@ func TestRenderResourcesWithCacheAction(t *testing.T) { action := kustomize.NewAction( kustomize.WithCache(), - kustomize.WithLabel(labels.ComponentPartOf, "foo"), + kustomize.WithLabel(labels.PlatformPartOf, "foo"), kustomize.WithLabel("platform.opendatahub.io/namespace", ns), kustomize.WithAnnotation("platform.opendatahub.io/release", "1.2.3"), kustomize.WithAnnotation("platform.opendatahub.io/type", "managed"), @@ -229,7 +229,7 @@ func TestRenderResourcesWithCacheAction(t *testing.T) { HaveLen(1), HaveEach(And( jq.Match(`.metadata.namespace == "%s"`, ns), - jq.Match(`.metadata.labels."%s" == "%s"`, labels.ComponentPartOf, "foo"), + jq.Match(`.metadata.labels."%s" == "%s"`, labels.PlatformPartOf, "foo"), jq.Match(`.metadata.labels."platform.opendatahub.io/namespace" == "%s"`, ns), jq.Match(`.metadata.annotations."platform.opendatahub.io/release" == "%s"`, "1.2.3"), jq.Match(`.metadata.annotations."platform.opendatahub.io/type" == "%s"`, "managed"), diff --git a/pkg/controller/reconciler/reconciler_support.go b/pkg/controller/reconciler/reconciler_support.go index fa637c4ea0d..ac8a0f56fb4 100644 --- a/pkg/controller/reconciler/reconciler_support.go +++ b/pkg/controller/reconciler/reconciler_support.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels" "strings" "golang.org/x/exp/slices" @@ -19,7 +20,6 @@ import ( "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/handlers" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/predicates/component" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/predicates/generation" - "github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/resources" ) @@ -114,14 +114,7 @@ func (b *ReconcilerBuilder) WithFinalizer(value actions.Fn) *ReconcilerBuilder { return b } -func (b *ReconcilerBuilder) Watches(object client.Object, opts ...WatchOpts) *ReconcilerBuilder { - var instanceLabel string - if _, ok := b.input.object.(components.ComponentObject); ok { - instanceLabel = labels.ComponentPartOf - } else if _, ok := b.input.object.(components.ComponentObject); ok { - instanceLabel = labels.ServicePartOf - } - +func (b *ReconcilerBuilder[T]) Watches(object client.Object, opts ...WatchOpts) *ReconcilerBuilder[T] { in := watchInput{} in.object = object in.owned = false @@ -133,15 +126,15 @@ func (b *ReconcilerBuilder) Watches(object client.Object, opts ...WatchOpts) *Re if in.eventHandler == nil { // use the components.opendatahub.io/part-of or services.opendatahub.io/part-of label to find out // the owner - in.eventHandler = handlers.LabelToName(instanceLabel) + in.eventHandler = handlers.LabelToName(labels.PlatformPartOf) } if len(in.predicates) == 0 { in.predicates = append(in.predicates, predicate.And( defaultPredicate, - // use the components.opendatahub.io/part-of label or services.opendatahub.io/part-of to filter + // use the platform.opendatahub.io/part-of label to filter // events not related to the owner - component.ForLabel(instanceLabel, b.ownerName), + component.ForLabel(labels.PlatformPartOf, b.ownerName), )) } diff --git a/pkg/metadata/labels/types.go b/pkg/metadata/labels/types.go index ab4a4303179..cfa4d864607 100644 --- a/pkg/metadata/labels/types.go +++ b/pkg/metadata/labels/types.go @@ -2,8 +2,7 @@ package labels const ( ODHAppPrefix = "app.opendatahub.io" - ComponentPartOf = "components.opendatahub.io/part-of" - ServicePartOf = "services.opendatahub.io/part-of" + PlatformPartOf = "platform.opendatahub.io/part-of" InjectTrustCA = "config.openshift.io/inject-trusted-cabundle" SecurityEnforce = "pod-security.kubernetes.io/enforce" ClusterMonitoring = "openshift.io/cluster-monitoring" diff --git a/tests/e2e/dashboard_test.go b/tests/e2e/dashboard_test.go index 7ce9ba85b68..2f70ed06776 100644 --- a/tests/e2e/dashboard_test.go +++ b/tests/e2e/dashboard_test.go @@ -230,7 +230,11 @@ func (d *DashboardTestCtx) validateOperandsDynamicallyWatchedResources(t *testin g.Eventually( d.List( gvk.OdhApplication, +<<<<<<< HEAD client.MatchingLabels{labels.ComponentPartOf: strings.ToLower(componentsv1.DashboardKind)}, +======= + client.MatchingLabels{labels.PlatformPartOf: componentsv1.DashboardInstanceName}, +>>>>>>> 51e8117b (Update label to platform.opendatahub.io) ), ).Should(And( HaveEach( @@ -245,7 +249,11 @@ func (d *DashboardTestCtx) validateUpdateOperandsResources(t *testing.T) { appDeployments, err := d.kubeClient.AppsV1().Deployments(d.applicationsNamespace).List( d.ctx, metav1.ListOptions{ +<<<<<<< HEAD LabelSelector: labels.ComponentPartOf + "=" + strings.ToLower(componentsv1.DashboardKind), +======= + LabelSelector: labels.PlatformPartOf + "=" + componentsv1.DashboardInstanceName, +>>>>>>> 51e8117b (Update label to platform.opendatahub.io) }, ) @@ -279,7 +287,11 @@ func (d *DashboardTestCtx) validateUpdateOperandsResources(t *testing.T) { d.List( gvk.Deployment, client.InNamespace(d.applicationsNamespace), +<<<<<<< HEAD client.MatchingLabels{labels.ComponentPartOf: strings.ToLower(componentsv1.DashboardKind)}, +======= + client.MatchingLabels{labels.PlatformPartOf: componentsv1.DashboardInstanceName}, +>>>>>>> 51e8117b (Update label to platform.opendatahub.io) ), ).Should(And( HaveLen(1), @@ -292,7 +304,11 @@ func (d *DashboardTestCtx) validateUpdateOperandsResources(t *testing.T) { d.List( gvk.Deployment, client.InNamespace(d.applicationsNamespace), +<<<<<<< HEAD client.MatchingLabels{labels.ComponentPartOf: strings.ToLower(componentsv1.DashboardKind)}, +======= + client.MatchingLabels{labels.PlatformPartOf: componentsv1.DashboardInstanceName}, +>>>>>>> 51e8117b (Update label to platform.opendatahub.io) ), ).WithTimeout(30 * time.Second).WithPolling(1 * time.Second).Should(And( HaveLen(1), @@ -309,7 +325,11 @@ func (d *DashboardTestCtx) validateDashboardDisabled(t *testing.T) { d.List( gvk.Deployment, client.InNamespace(d.applicationsNamespace), +<<<<<<< HEAD client.MatchingLabels{labels.ComponentPartOf: strings.ToLower(componentsv1.DashboardKind)}, +======= + client.MatchingLabels{labels.PlatformPartOf: componentsv1.DashboardInstanceName}, +>>>>>>> 51e8117b (Update label to platform.opendatahub.io) ), ).Should( HaveLen(1), @@ -327,7 +347,11 @@ func (d *DashboardTestCtx) validateDashboardDisabled(t *testing.T) { d.List( gvk.Deployment, client.InNamespace(d.applicationsNamespace), +<<<<<<< HEAD client.MatchingLabels{labels.ComponentPartOf: strings.ToLower(componentsv1.DashboardKind)}, +======= + client.MatchingLabels{labels.PlatformPartOf: componentsv1.DashboardInstanceName}, +>>>>>>> 51e8117b (Update label to platform.opendatahub.io) ), ).Should( BeEmpty(),