Skip to content

Commit efcbb82

Browse files
Merge pull request opendatahub-io#88 from gmfrasca/iris-sample
Add/Enable Customizable Sample Pipeline to APIServer
2 parents f83edae + 313672c commit efcbb82

File tree

13 files changed

+679
-2
lines changed

13 files changed

+679
-2
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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,24 @@ spec:
190190
memory: {{.APIServer.Resources.Limits.Memory}}
191191
{{ end }}
192192
{{ end }}
193+
{{ if .APIServer.EnableSamplePipeline }}
194+
volumeMounts:
195+
- name: sample-config
196+
mountPath: /config/sample_config.json
197+
subPath: sample_config.json
198+
- name: sample-pipeline
199+
mountPath: /samples/
200+
{{ end }}
193201
serviceAccountName: ds-pipeline-{{.Name}}
194202
volumes:
195203
- name: proxy-tls
196204
secret:
197205
secretName: ds-pipelines-proxy-tls-{{.Name}}
206+
{{ if .APIServer.EnableSamplePipeline }}
207+
- name: sample-config
208+
configMap:
209+
name: sample-config-{{.Name}}
210+
- name: sample-pipeline
211+
configMap:
212+
name: sample-pipeline-{{.Name}}
213+
{{ end }}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: sample-config-{{.Name}}
5+
namespace: {{.Namespace}}
6+
labels:
7+
app: ds-pipeline-{{.Name}}
8+
component: data-science-pipelines
9+
data:
10+
sample_config.json: |-
11+
[
12+
{
13+
"name": "[Demo] iris-training",
14+
"description": "[source code](https://github.com/opendatahub-io/data-science-pipelines/tree/master/samples/iris-training) A simple pipeline to demonstrate a basic ML Training workflow",
15+
"file": "/samples/iris-pipeline-compiled.yaml"
16+
}
17+
]

config/internal/apiserver/sample-pipeline.yaml.tmpl

Lines changed: 554 additions & 0 deletions
Large diffs are not rendered by default.

controllers/apiserver.go

Lines changed: 24 additions & 0 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

@@ -39,6 +40,13 @@ var apiServerTemplates = []string{
3940
// as such it is handled separately
4041
const serverRoute = "apiserver/route.yaml.tmpl"
4142

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+
4250
func (r *DSPAReconciler) ReconcileAPIServer(ctx context.Context, dsp *dspav1alpha1.DataSciencePipelinesApplication, params *DSPAParams) error {
4351

4452
if !dsp.Spec.APIServer.Deploy {
@@ -69,6 +77,22 @@ func (r *DSPAReconciler) ReconcileAPIServer(ctx context.Context, dsp *dspav1alph
6977
}
7078
}
7179

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+
7296
r.Log.Info("Finished applying APIServer Resources")
7397
return nil
7498
}

controllers/dspipeline_controller_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var cases = map[string]TestCase{
5555
Path: "./testdata/deploy/case_2/cr.yaml",
5656
},
5757
"case_3": {
58-
Description: "custom Artifact configmap is provided, custom images override defaults",
58+
Description: "custom Artifact configmap is provided, custom images override defaults, no sample pipeline",
5959
Path: "./testdata/deploy/case_3/cr.yaml",
6060
AdditionalResources: map[string][]string{
6161
SecretKind: {
@@ -110,7 +110,9 @@ var secretsCreated = CaseComponentResources{
110110

111111
var configMapsNotCreated = CaseComponentResources{
112112
"case_3": {
113-
"apiserver": "./testdata/results/case_3/apiserver/configmap_artifact_script.yaml",
113+
"apiserver": "./testdata/results/case_3/apiserver/configmap_artifact_script.yaml",
114+
"apiserver-sampleconfig": "./testdata/results/case_3/apiserver/sample-config.yaml",
115+
"apiserver-samplepipeline": "./testdata/results/case_3/apiserver/sample-pipeline.yaml",
114116
},
115117
}
116118

controllers/testdata/deploy/case_2/cr.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ spec:
1414
injectDefaultScript: true
1515
stripEOF: true
1616
enableOauth: true
17+
enableSamplePipeline: true
1718
terminateStatus: Cancelled
1819
trackArtifacts: true
1920
dbConfigConMaxLifetimeSec: 125

controllers/testdata/deploy/case_3/cr.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ metadata:
55
spec:
66
apiServer:
77
enableOauth: true
8+
enableSamplePipeline: false
89
artifactScriptConfigMap:
910
name: doesnotexist
1011
key: "somekey"

controllers/testdata/results/case_0/apiserver/deployment.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,24 @@ spec:
179179
limits:
180180
cpu: 500m
181181
memory: 1Gi
182+
volumeMounts:
183+
- mountPath: /config/sample_config.json
184+
name: sample-config
185+
subPath: sample_config.json
186+
- mountPath: /samples/
187+
name: sample-pipeline
182188
volumes:
183189
- name: proxy-tls
184190
secret:
185191
secretName: ds-pipelines-proxy-tls-testdsp0
186192
defaultMode: 420
193+
- configMap:
194+
defaultMode: 420
195+
name: sample-config-testdsp0
196+
name: sample-config
197+
- configMap:
198+
defaultMode: 420
199+
name: sample-pipeline-testdsp0
200+
name: sample-pipeline
201+
187202
serviceAccountName: ds-pipeline-testdsp0

0 commit comments

Comments
 (0)