Skip to content

Commit aaf3510

Browse files
committed
Set dsp-version label on managed resources
This change makes it so that new reconciles on dspa owned resources are labelled with a dsp-version=<dspa-version> label. This is to allow for the dspa selectively watch (for manual WatchesRawSources) on resources that are descendents of DSPAs with .spec.dspVersion set to supported versions. Signed-off-by: Humair Khan <[email protected]>
1 parent cd6d5a6 commit aaf3510

33 files changed

+168
-18
lines changed

config/crd/bases/datasciencepipelinesapplications.opendatahub.io_datasciencepipelinesapplications.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ spec:
859859
status: {}
860860
- deprecated: true
861861
deprecationWarning: datasciencepipelinesapplications.opendatahub.io/v1alpha1 is
862-
deprecated
862+
deprecated.
863863
name: v1alpha1
864864
schema:
865865
openAPIV3Schema:

controllers/config/defaults.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ import (
2727
"k8s.io/apimachinery/pkg/api/resource"
2828
)
2929

30+
const DSPV2VersionString = "v2"
31+
const DSPVersionk8sLabel = "dsp-version"
32+
33+
var SupportedDSPVersions = []string{DSPV2VersionString}
34+
3035
const (
31-
DSPDefaultVersion = "v2"
32-
DSPV2VersionString = DSPDefaultVersion
33-
DefaultImageValue = "MustSetInConfig"
36+
DefaultImageValue = "MustSetInConfig"
3437

3538
CustomCABundleRootMountPath = "/dsp-custom-certs"
3639

@@ -222,3 +225,7 @@ func GetDefaultDBExtraParams(params DBExtraParams, log logr.Logger) (string, err
222225
}
223226
return string(extraParamsJson), nil
224227
}
228+
229+
func GetSupportedDSPAVersions() []string {
230+
return SupportedDSPVersions
231+
}

controllers/dspipeline_controller.go

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22-
2322
"github.com/opendatahub-io/data-science-pipelines-operator/controllers/dspastatus"
2423
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2524
"sigs.k8s.io/controller-runtime/pkg/controller"
@@ -82,18 +81,25 @@ func (r *DSPAReconciler) Apply(owner mf.Owner, params *DSPAParams, template stri
8281
if err != nil {
8382
return fmt.Errorf("error loading template (%s) yaml: %w", template, err)
8483
}
84+
85+
// Apply the owner injection transformation
8586
tmplManifest, err = tmplManifest.Transform(
8687
mf.InjectOwner(owner),
88+
// Apply dsp-version=<ver> label on all resources managed by this dspo
89+
util.AddLabelTransformer(config.DSPVersionk8sLabel, params.DSPVersion),
90+
util.AddDeploymentPodLabelTransformer(config.DSPVersionk8sLabel, params.DSPVersion),
8791
)
8892
if err != nil {
8993
return err
9094
}
9195

96+
// Apply dsp-version labels to all manifests
9297
tmplManifest, err = tmplManifest.Transform(fns...)
9398
if err != nil {
9499
return err
95100
}
96101

102+
// Apply the manifest
97103
return tmplManifest.Apply()
98104
}
99105

@@ -188,7 +194,7 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
188194

189195
defer r.updateStatus(ctx, dspa, dspaStatus, log, req)
190196

191-
if dspa.Spec.DSPVersion != config.DSPV2VersionString {
197+
if !util.DSPAWithSupportedDSPVersion(dspa) {
192198
err1 := fmt.Errorf("unsupported DSP version %s detected. Please manually remove "+
193199
"this DSP resource and re-apply with a supported version field set", dspa.Spec.DSPVersion)
194200
dspaStatus.SetDatabaseNotReady(err1, config.UnsupportedVersion)
@@ -600,7 +606,6 @@ func (r *DSPAReconciler) SetupWithManager(mgr ctrl.Manager) error {
600606
// Watch for global ca bundle, if one is added to this namespace
601607
// we need to reconcile on all the dspa's in this namespace
602608
// so they may mount this cert in the appropriate containers
603-
604609
WatchesRawSource(source.Kind(mgr.GetCache(), &corev1.ConfigMap{}),
605610
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, o client.Object) []reconcile.Request {
606611
cm := o.(*corev1.ConfigMap)
@@ -611,8 +616,6 @@ func (r *DSPAReconciler) SetupWithManager(mgr ctrl.Manager) error {
611616
return nil
612617
}
613618

614-
log.V(1).Info(fmt.Sprintf("Reconcile event triggered by change in event on Global CA Bundle: %s", cm.Name))
615-
616619
var dspaList dspav1.DataSciencePipelinesApplicationList
617620
if err := r.List(ctx, &dspaList, client.InNamespace(thisNamespace)); err != nil {
618621
log.Error(err, "unable to list DSPA's when attempting to handle Global CA Bundle event.")
@@ -621,11 +624,18 @@ func (r *DSPAReconciler) SetupWithManager(mgr ctrl.Manager) error {
621624

622625
var reconcileRequests []reconcile.Request
623626
for _, dspa := range dspaList.Items {
624-
namespacedName := types.NamespacedName{
625-
Name: dspa.Name,
626-
Namespace: thisNamespace,
627+
// Only update supported DSP versions
628+
if util.DSPAWithSupportedDSPVersion(&dspa) {
629+
namespacedName := types.NamespacedName{
630+
Name: dspa.Name,
631+
Namespace: thisNamespace,
632+
}
633+
reconcileRequests = append(reconcileRequests, reconcile.Request{NamespacedName: namespacedName})
627634
}
628-
reconcileRequests = append(reconcileRequests, reconcile.Request{NamespacedName: namespacedName})
635+
}
636+
637+
if len(reconcileRequests) > 0 {
638+
log.V(1).Info(fmt.Sprintf("Reconcile event triggered by change in event on Global CA Bundle: %s", cm.Name))
629639
}
630640

631641
return reconcileRequests
@@ -641,6 +651,12 @@ func (r *DSPAReconciler) SetupWithManager(mgr ctrl.Manager) error {
641651
return nil
642652
}
643653

654+
// Silently skip reconcile on this pod if the resource was owned
655+
// by an unsupported dspa
656+
if !util.HasSupportedDSPVersionLabel(pod.Labels) {
657+
return nil
658+
}
659+
644660
dspaName, hasDSPALabel := pod.Labels["dspa"]
645661
if !hasDSPALabel {
646662
msg := fmt.Sprintf("Pod with data-science-pipelines label encountered, but is missing dspa "+
@@ -665,9 +681,6 @@ func (r *DSPAReconciler) SetupWithManager(mgr ctrl.Manager) error {
665681
if secret.Annotations["openshift.io/owning-component"] != "service-ca" {
666682
return nil
667683
}
668-
669-
log.V(1).Info(fmt.Sprintf("Reconcile event triggered by change on Secret owned by service-ca: %s", secret.Name))
670-
671684
serviceName := secret.Annotations["service.beta.openshift.io/originating-service-name"]
672685

673686
namespacedServiceName := types.NamespacedName{
@@ -681,17 +694,22 @@ func (r *DSPAReconciler) SetupWithManager(mgr ctrl.Manager) error {
681694
if err != nil {
682695
return nil
683696
}
684-
685697
dspaName, hasDSPALabel := service.Labels["dspa"]
686698
if !hasDSPALabel {
687699
return nil
688700
}
689701

690-
log.V(1).Info(fmt.Sprintf("Reconcile event triggered by [Service: %s] ", serviceName))
702+
// Silently skip reconcile on this ervice if the resource was owned
703+
// by an unsupported DSPA
704+
if !util.HasSupportedDSPVersionLabel(service.Labels) {
705+
return nil
706+
}
707+
691708
namespacedDspaName := types.NamespacedName{
692709
Name: dspaName,
693710
Namespace: secret.Namespace,
694711
}
712+
log.V(1).Info(fmt.Sprintf("Reconcile event triggered by change on Secret: %s owned by service-ca: %s", secret.Name, serviceName))
695713
return []reconcile.Request{{NamespacedName: namespacedDspaName}}
696714
}),
697715
).

controllers/testdata/declarative/case_0/expected/created/apiserver_deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: ds-pipeline-testdsp0
55
namespace: default
66
labels:
7+
dsp-version: v2
78
app: ds-pipeline-testdsp0
89
component: data-science-pipelines
910
dspa: testdsp0
@@ -16,6 +17,7 @@ spec:
1617
template:
1718
metadata:
1819
labels:
20+
dsp-version: v2
1921
app: ds-pipeline-testdsp0
2022
component: data-science-pipelines
2123
dspa: testdsp0

controllers/testdata/declarative/case_0/expected/created/configmap_server_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: ds-pipeline-server-config-testdsp0
55
namespace: default
66
labels:
7+
dsp-version: v2
78
app: ds-pipeline-testdsp0
89
component: data-science-pipelines
910
data:

controllers/testdata/declarative/case_0/expected/created/mariadb_deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ metadata:
55
name: mariadb-testdsp0
66
namespace: default
77
labels:
8+
dsp-version: v2
89
app: mariadb-testdsp0
910
component: data-science-pipelines
1011
dspa: testdsp0
@@ -19,6 +20,7 @@ spec:
1920
template:
2021
metadata:
2122
labels:
23+
dsp-version: v2
2224
app: mariadb-testdsp0
2325
component: data-science-pipelines
2426
dspa: testdsp0

controllers/testdata/declarative/case_0/expected/created/persistence-agent_deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: ds-pipeline-persistenceagent-testdsp0
55
namespace: default
66
labels:
7+
dsp-version: v2
78
app: ds-pipeline-persistenceagent-testdsp0
89
component: data-science-pipelines
910
dspa: testdsp0
@@ -18,6 +19,7 @@ spec:
1819
annotations:
1920
cluster-autoscaler.kubernetes.io/safe-to-evict: "true"
2021
labels:
22+
dsp-version: v2
2123
app: ds-pipeline-persistenceagent-testdsp0
2224
component: data-science-pipelines
2325
dspa: testdsp0

controllers/testdata/declarative/case_0/expected/created/scheduled-workflow_deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: ds-pipeline-scheduledworkflow-testdsp0
55
namespace: default
66
labels:
7+
dsp-version: v2
78
app: ds-pipeline-scheduledworkflow-testdsp0
89
component: data-science-pipelines
910
dspa: testdsp0
@@ -18,6 +19,7 @@ spec:
1819
annotations:
1920
cluster-autoscaler.kubernetes.io/safe-to-evict: "true"
2021
labels:
22+
dsp-version: v2
2123
app: ds-pipeline-scheduledworkflow-testdsp0
2224
component: data-science-pipelines
2325
dspa: testdsp0

controllers/testdata/declarative/case_2/expected/created/apiserver_deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: ds-pipeline-testdsp2
55
namespace: default
66
labels:
7+
dsp-version: v2
78
app: ds-pipeline-testdsp2
89
component: data-science-pipelines
910
dspa: testdsp2
@@ -16,6 +17,7 @@ spec:
1617
template:
1718
metadata:
1819
labels:
20+
dsp-version: v2
1921
app: ds-pipeline-testdsp2
2022
component: data-science-pipelines
2123
dspa: testdsp2

controllers/testdata/declarative/case_2/expected/created/mariadb_deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ metadata:
55
name: mariadb-testdsp2
66
namespace: default
77
labels:
8+
dsp-version: v2
89
app: mariadb-testdsp2
910
component: data-science-pipelines
1011
dspa: testdsp2
@@ -19,6 +20,7 @@ spec:
1920
template:
2021
metadata:
2122
labels:
23+
dsp-version: v2
2224
app: mariadb-testdsp2
2325
component: data-science-pipelines
2426
dspa: testdsp2

0 commit comments

Comments
 (0)