Skip to content

Commit cbf76c8

Browse files
committed
Add APIServer.EnableSamplePipeline bool to DSPA CRD
- Create new bool .APIServer.EnableSamplePipeline. Default: true - Conditionnally include custom SamplePipeline if bool is set to true
1 parent 4fa3b1f commit cbf76c8

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

api/v1alpha1/dspipeline_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ type APIServer struct {
7676
EnableRoute bool `json:"enableOauth"`
7777
// +kubebuilder:default:=true
7878
// +kubebuilder:validation:Optional
79+
EnableSamplePipeline bool `json:"enableSamplePipeline"`
80+
// +kubebuilder:default:=true
81+
// +kubebuilder:validation:Optional
7982
AutoUpdatePipelineDefaultVersion bool `json:"autoUpdatePipelineDefaultVersion"`
8083
Resources *ResourceRequirements `json:"resources,omitempty"`
8184
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ spec:
7272
enableOauth:
7373
default: true
7474
type: boolean
75+
enableSamplePipeline:
76+
default: true
77+
type: boolean
7578
image:
7679
type: string
7780
injectDefaultScript:

config/internal/apiserver/deployment.yaml.tmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,25 @@ spec:
190190
memory: {{.APIServer.Resources.Limits.Memory}}
191191
{{ end }}
192192
{{ end }}
193+
{{ if .APIServer.EnableSamplePipeline }}
193194
volumeMounts:
194195
- name: sample-config
195196
mountPath: /config/sample_config.json
196197
subPath: sample_config.json
197198
- name: sample-pipeline
198199
mountPath: /samples/
200+
{{ end }}
199201
serviceAccountName: ds-pipeline-{{.Name}}
200202
volumes:
201203
- name: proxy-tls
202204
secret:
203205
secretName: ds-pipelines-proxy-tls-{{.Name}}
204-
# TODO: encap in if-exists block
206+
{{ if .APIServer.EnableSamplePipeline }}
205207
- name: sample-config
206208
configMap:
207209
name: sample-config-{{.Name}}
208210
- name: sample-pipeline
209211
configMap:
210212
name: sample-pipeline-{{.Name}}
213+
{{ end }}
211214

controllers/apiserver.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
dspav1alpha1 "github.com/opendatahub-io/data-science-pipelines-operator/api/v1alpha1"
2121
v1 "github.com/openshift/api/route/v1"
22+
corev1 "k8s.io/api/core/v1"
2223
"k8s.io/apimachinery/pkg/types"
2324
)
2425

@@ -33,14 +34,19 @@ var apiServerTemplates = []string{
3334
"apiserver/service.yaml.tmpl",
3435
"apiserver/deployment.yaml.tmpl",
3536
"apiserver/monitor.yaml.tmpl",
36-
"apiserver/sample-config.yaml.tmpl",
37-
"apiserver/sample-pipeline.yaml.tmpl",
3837
}
3938

4039
// serverRoute is a resource deployed conditionally
4140
// as such it is handled separately
4241
const serverRoute = "apiserver/route.yaml.tmpl"
4342

43+
// Sample Pipeline and Config are resources deployed conditionally
44+
// as such it is handled separately
45+
var samplePipelineTemplates = map[string]string{
46+
"sample-pipeline": "apiserver/sample-pipeline.yaml.tmpl",
47+
"sample-config": "apiserver/sample-config.yaml.tmpl",
48+
}
49+
4450
func (r *DSPAReconciler) ReconcileAPIServer(ctx context.Context, dsp *dspav1alpha1.DataSciencePipelinesApplication, params *DSPAParams) error {
4551

4652
if !dsp.Spec.APIServer.Deploy {
@@ -71,6 +77,22 @@ func (r *DSPAReconciler) ReconcileAPIServer(ctx context.Context, dsp *dspav1alph
7177
}
7278
}
7379

80+
for cmName, template := range samplePipelineTemplates {
81+
if dsp.Spec.APIServer.EnableSamplePipeline {
82+
err := r.Apply(dsp, params, template)
83+
if err != nil {
84+
return err
85+
}
86+
} else {
87+
cm := &corev1.ConfigMap{}
88+
namespacedNamed := types.NamespacedName{Name: cmName + "-" + dsp.Name, Namespace: dsp.Namespace}
89+
err := r.DeleteResourceIfItExists(ctx, cm, namespacedNamed)
90+
if err != nil {
91+
return err
92+
}
93+
}
94+
}
95+
7496
r.Log.Info("Finished applying APIServer Resources")
7597
return nil
7698
}

0 commit comments

Comments
 (0)