Skip to content

Commit

Permalink
Replace components.opendatahub.io/managed-by with components.opendata…
Browse files Browse the repository at this point in the history
…hub.io/part-of (#1343)

This commit replaces then label components.opendatahub.io/managed-by
with components.opendatahub.io/part-of as managed-by was misleading
since the label is mainly used for watching and request mapping
  • Loading branch information
lburgazzoli authored Nov 5, 2024
1 parent 90bd116 commit 37f65b6
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions controllers/components/dashboard/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func NewComponentReconciler(ctx context.Context, mgr ctrl.Manager) error {
//
// By default the Watches functions adds:
// - an event handler mapping to a cluster scope resource identified by the
// components.opendatahub.io/managed-by annotation
// components.opendatahub.io/part-of annotation
// - a predicate that check for generation change for Delete/Updates events
// for to objects that have the label components.opendatahub.io/managed-by
// for to objects that have the label components.opendatahub.io/part-of
// set to the current owner
//
Watches(&extv1.CustomResourceDefinition{}).
Expand All @@ -88,10 +88,10 @@ func NewComponentReconciler(ctx context.Context, mgr ctrl.Manager) error {
WithAction(updatePodSecurityRolebinding).
WithAction(deploy.NewAction(
deploy.WithFieldOwner(componentsv1.DashboardInstanceName),
deploy.WithLabel(labels.ComponentManagedBy, componentsv1.DashboardInstanceName),
deploy.WithLabel(labels.ComponentPartOf, componentsv1.DashboardInstanceName),
)).
WithAction(updatestatus.NewAction(
updatestatus.WithSelectorLabel(labels.ComponentManagedBy, componentsv1.DashboardInstanceName),
updatestatus.WithSelectorLabel(labels.ComponentPartOf, componentsv1.DashboardInstanceName),
)).
WithAction(updateStatus).
Build(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func updateStatus(ctx context.Context, rr *odhtypes.ReconciliationRequest) error
&rl,
client.InNamespace(rr.DSCI.Spec.ApplicationsNamespace),
client.MatchingLabels(map[string]string{
labels.ComponentManagedBy: componentsv1.DashboardInstanceName,
labels.ComponentPartOf: componentsv1.DashboardInstanceName,
}),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ func NewComponentReconciler(ctx context.Context, mgr ctrl.Manager) error {
WithAction(customizeResources).
WithAction(deploy.NewAction(
deploy.WithFieldOwner(componentsv1.ModelRegistryInstanceName),
deploy.WithLabel(labels.ComponentManagedBy, componentsv1.ModelRegistryInstanceName),
deploy.WithLabel(labels.ComponentPartOf, componentsv1.ModelRegistryInstanceName),
)).
WithAction(updatestatus.NewAction(
updatestatus.WithSelectorLabel(labels.ComponentManagedBy, componentsv1.ModelRegistryInstanceName),
updatestatus.WithSelectorLabel(labels.ComponentPartOf, componentsv1.ModelRegistryInstanceName),
)).
WithAction(updateStatus).
Build(ctx)
Expand Down
4 changes: 2 additions & 2 deletions controllers/components/ray/ray_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ func NewComponentReconciler(ctx context.Context, mgr ctrl.Manager) error {
)).
WithAction(deploy.NewAction(
deploy.WithFieldOwner(componentsv1.RayInstanceName),
deploy.WithLabel(labels.ComponentManagedBy, componentsv1.RayInstanceName),
deploy.WithLabel(labels.ComponentPartOf, componentsv1.RayInstanceName),
)).
WithAction(updatestatus.NewAction(
updatestatus.WithSelectorLabel(labels.ComponentManagedBy, componentsv1.RayInstanceName),
updatestatus.WithSelectorLabel(labels.ComponentPartOf, componentsv1.RayInstanceName),
)).
Build(ctx)

Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/actions/render/action_render_manifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestRenderResourcesWithCacheAction(t *testing.T) {

action := render.NewAction(
render.WithCache(true, render.DefaultCachingKeyFn),
render.WithLabel(labels.ComponentManagedBy, "foo"),
render.WithLabel(labels.ComponentPartOf, "foo"),
render.WithLabel("platform.opendatahub.io/namespace", ns),
render.WithAnnotation("platform.opendatahub.io/release", "1.2.3"),
render.WithAnnotation("platform.opendatahub.io/type", "managed"),
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestRenderResourcesWithCacheAction(t *testing.T) {
HaveLen(1),
HaveEach(And(
jq.Match(`.metadata.namespace == "%s"`, ns),
jq.Match(`.metadata.labels."%s" == "%s"`, labels.ComponentManagedBy, "foo"),
jq.Match(`.metadata.labels."%s" == "%s"`, labels.ComponentPartOf, "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"),
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ func ToOwner() handler.EventHandler {
return []reconcile.Request{}
}

managedBy := objLabels[labels.ComponentManagedBy]
if managedBy == "" {
partOf := objLabels[labels.ComponentPartOf]
if partOf == "" {
return []reconcile.Request{}
}

return []reconcile.Request{{
NamespacedName: types.NamespacedName{
Name: managedBy,
Name: partOf,
},
}}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/reconciler/component_reconciler_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (b *ComponentReconcilerBuilder) Build(ctx context.Context) (*ComponentRecon
if len(watchOpts) == 0 {
watchOpts = append(watchOpts, builder.WithPredicates(predicate.And(
generation.New(),
component.ForLabel(labels.ComponentManagedBy, b.ownerName),
component.ForLabel(labels.ComponentPartOf, b.ownerName),
)))
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/metadata/labels/types.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package labels

const (
ODHAppPrefix = "app.opendatahub.io"
ComponentManagedBy = "components.opendatahub.io/managed-by"
InjectTrustCA = "config.openshift.io/inject-trusted-cabundle"
SecurityEnforce = "pod-security.kubernetes.io/enforce"
ClusterMonitoring = "openshift.io/cluster-monitoring"
ODHAppPrefix = "app.opendatahub.io"
ComponentPartOf = "components.opendatahub.io/part-of"
InjectTrustCA = "config.openshift.io/inject-trusted-cabundle"
SecurityEnforce = "pod-security.kubernetes.io/enforce"
ClusterMonitoring = "openshift.io/cluster-monitoring"
)

// K8SCommon keeps common kubernetes labels [1]
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (tc *DashboardTestCtx) testUpdateOnDashboardResources() error {
// Test Updating Dashboard Replicas

appDeployments, err := tc.testCtx.kubeClient.AppsV1().Deployments(tc.testCtx.applicationsNamespace).List(tc.testCtx.ctx, metav1.ListOptions{
LabelSelector: labels.ComponentManagedBy + "=" + tc.testDashboardInstance.Name,
LabelSelector: labels.ComponentPartOf + "=" + tc.testDashboardInstance.Name,
})
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/modelregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (mr *ModelRegistryTestCtx) validateOperandsOwnerReferences(t *testing.T) {
mr.List(
gvk.Deployment,
client.InNamespace(mr.applicationsNamespace),
client.MatchingLabels{labels.ComponentManagedBy: componentsv1.ModelRegistryInstanceName},
client.MatchingLabels{labels.ComponentPartOf: componentsv1.ModelRegistryInstanceName},
),
).Should(And(
HaveLen(1),
Expand All @@ -168,7 +168,7 @@ func (mr *ModelRegistryTestCtx) validateUpdateModelRegistryOperandsResources(t *
appDeployments, err := mr.kubeClient.AppsV1().Deployments(mr.applicationsNamespace).List(
mr.ctx,
metav1.ListOptions{
LabelSelector: labels.ComponentManagedBy + "=" + componentsv1.ModelRegistryInstanceName,
LabelSelector: labels.ComponentPartOf + "=" + componentsv1.ModelRegistryInstanceName,
},
)

Expand Down Expand Up @@ -203,7 +203,7 @@ func (mr *ModelRegistryTestCtx) validateUpdateModelRegistryOperandsResources(t *
mr.List(
gvk.Deployment,
client.InNamespace(mr.applicationsNamespace),
client.MatchingLabels{labels.ComponentManagedBy: componentsv1.ModelRegistryInstanceName},
client.MatchingLabels{labels.ComponentPartOf: componentsv1.ModelRegistryInstanceName},
),
).Should(And(
HaveLen(1),
Expand All @@ -216,7 +216,7 @@ func (mr *ModelRegistryTestCtx) validateUpdateModelRegistryOperandsResources(t *
mr.List(
gvk.Deployment,
client.InNamespace(mr.applicationsNamespace),
client.MatchingLabels{labels.ComponentManagedBy: componentsv1.ModelRegistryInstanceName},
client.MatchingLabels{labels.ComponentPartOf: componentsv1.ModelRegistryInstanceName},
),
).WithTimeout(30 * time.Second).WithPolling(1 * time.Second).Should(And(
HaveLen(1),
Expand Down Expand Up @@ -262,7 +262,7 @@ func (mr *ModelRegistryTestCtx) validateModelRegistryDisabled(t *testing.T) {
mr.List(
gvk.Deployment,
client.InNamespace(mr.applicationsNamespace),
client.MatchingLabels{labels.ComponentManagedBy: componentsv1.ModelRegistryInstanceName},
client.MatchingLabels{labels.ComponentPartOf: componentsv1.ModelRegistryInstanceName},
),
).Should(
HaveLen(1),
Expand All @@ -280,7 +280,7 @@ func (mr *ModelRegistryTestCtx) validateModelRegistryDisabled(t *testing.T) {
mr.List(
gvk.Deployment,
client.InNamespace(mr.applicationsNamespace),
client.MatchingLabels{labels.ComponentManagedBy: componentsv1.ModelRegistryInstanceName},
client.MatchingLabels{labels.ComponentPartOf: componentsv1.ModelRegistryInstanceName},
),
).Should(
BeEmpty(),
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/ray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (tc *RayTestCtx) testUpdateOnRayResources() error {
// Test Updating Ray Replicas

appDeployments, err := tc.testCtx.kubeClient.AppsV1().Deployments(tc.testCtx.applicationsNamespace).List(tc.testCtx.ctx, metav1.ListOptions{
LabelSelector: labels.ComponentManagedBy + "=" + tc.testRayInstance.Name,
LabelSelector: labels.ComponentPartOf + "=" + tc.testRayInstance.Name,
})
if err != nil {
return err
Expand Down

0 comments on commit 37f65b6

Please sign in to comment.