Skip to content

Commit

Permalink
Update label to platform.opendatahub.io
Browse files Browse the repository at this point in the history
  • Loading branch information
VaishnaviHire committed Nov 27, 2024
1 parent 0243a80 commit 828f33c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}),
)

Expand Down
4 changes: 2 additions & 2 deletions controllers/services/monitoring/monitoring_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down
17 changes: 5 additions & 12 deletions pkg/controller/reconciler/reconciler_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels"
"strings"

"golang.org/x/exp/slices"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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
Expand All @@ -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),
))
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/metadata/labels/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 24 additions & 0 deletions tests/e2e/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
},
)

Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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(),
Expand Down

0 comments on commit 828f33c

Please sign in to comment.