Skip to content

Commit

Permalink
Merge pull request #88 from gmfrasca/iris-sample
Browse files Browse the repository at this point in the history
Add/Enable Customizable Sample Pipeline to APIServer
  • Loading branch information
openshift-merge-robot authored Apr 13, 2023
2 parents f83edae + 313672c commit efcbb82
Show file tree
Hide file tree
Showing 13 changed files with 679 additions and 2 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/dspipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ type APIServer struct {
EnableRoute bool `json:"enableOauth"`
// +kubebuilder:default:=true
// +kubebuilder:validation:Optional
EnableSamplePipeline bool `json:"enableSamplePipeline"`
// +kubebuilder:default:=true
// +kubebuilder:validation:Optional
AutoUpdatePipelineDefaultVersion bool `json:"autoUpdatePipelineDefaultVersion"`
Resources *ResourceRequirements `json:"resources,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ spec:
enableOauth:
default: true
type: boolean
enableSamplePipeline:
default: true
type: boolean
image:
type: string
injectDefaultScript:
Expand Down
16 changes: 16 additions & 0 deletions config/internal/apiserver/deployment.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,24 @@ spec:
memory: {{.APIServer.Resources.Limits.Memory}}
{{ end }}
{{ end }}
{{ if .APIServer.EnableSamplePipeline }}
volumeMounts:
- name: sample-config
mountPath: /config/sample_config.json
subPath: sample_config.json
- name: sample-pipeline
mountPath: /samples/
{{ end }}
serviceAccountName: ds-pipeline-{{.Name}}
volumes:
- name: proxy-tls
secret:
secretName: ds-pipelines-proxy-tls-{{.Name}}
{{ if .APIServer.EnableSamplePipeline }}
- name: sample-config
configMap:
name: sample-config-{{.Name}}
- name: sample-pipeline
configMap:
name: sample-pipeline-{{.Name}}
{{ end }}
17 changes: 17 additions & 0 deletions config/internal/apiserver/sample-config.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: sample-config-{{.Name}}
namespace: {{.Namespace}}
labels:
app: ds-pipeline-{{.Name}}
component: data-science-pipelines
data:
sample_config.json: |-
[
{
"name": "[Demo] iris-training",
"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",
"file": "/samples/iris-pipeline-compiled.yaml"
}
]
554 changes: 554 additions & 0 deletions config/internal/apiserver/sample-pipeline.yaml.tmpl

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions controllers/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
dspav1alpha1 "github.com/opendatahub-io/data-science-pipelines-operator/api/v1alpha1"
v1 "github.com/openshift/api/route/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
)

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

// Sample Pipeline and Config are resources deployed conditionally
// as such it is handled separately
var samplePipelineTemplates = map[string]string{
"sample-pipeline": "apiserver/sample-pipeline.yaml.tmpl",
"sample-config": "apiserver/sample-config.yaml.tmpl",
}

func (r *DSPAReconciler) ReconcileAPIServer(ctx context.Context, dsp *dspav1alpha1.DataSciencePipelinesApplication, params *DSPAParams) error {

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

for cmName, template := range samplePipelineTemplates {
if dsp.Spec.APIServer.EnableSamplePipeline {
err := r.Apply(dsp, params, template)
if err != nil {
return err
}
} else {
cm := &corev1.ConfigMap{}
namespacedNamed := types.NamespacedName{Name: cmName + "-" + dsp.Name, Namespace: dsp.Namespace}
err := r.DeleteResourceIfItExists(ctx, cm, namespacedNamed)
if err != nil {
return err
}
}
}

r.Log.Info("Finished applying APIServer Resources")
return nil
}
6 changes: 4 additions & 2 deletions controllers/dspipeline_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var cases = map[string]TestCase{
Path: "./testdata/deploy/case_2/cr.yaml",
},
"case_3": {
Description: "custom Artifact configmap is provided, custom images override defaults",
Description: "custom Artifact configmap is provided, custom images override defaults, no sample pipeline",
Path: "./testdata/deploy/case_3/cr.yaml",
AdditionalResources: map[string][]string{
SecretKind: {
Expand Down Expand Up @@ -110,7 +110,9 @@ var secretsCreated = CaseComponentResources{

var configMapsNotCreated = CaseComponentResources{
"case_3": {
"apiserver": "./testdata/results/case_3/apiserver/configmap_artifact_script.yaml",
"apiserver": "./testdata/results/case_3/apiserver/configmap_artifact_script.yaml",
"apiserver-sampleconfig": "./testdata/results/case_3/apiserver/sample-config.yaml",
"apiserver-samplepipeline": "./testdata/results/case_3/apiserver/sample-pipeline.yaml",
},
}

Expand Down
1 change: 1 addition & 0 deletions controllers/testdata/deploy/case_2/cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
injectDefaultScript: true
stripEOF: true
enableOauth: true
enableSamplePipeline: true
terminateStatus: Cancelled
trackArtifacts: true
dbConfigConMaxLifetimeSec: 125
Expand Down
1 change: 1 addition & 0 deletions controllers/testdata/deploy/case_3/cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
spec:
apiServer:
enableOauth: true
enableSamplePipeline: false
artifactScriptConfigMap:
name: doesnotexist
key: "somekey"
Expand Down
15 changes: 15 additions & 0 deletions controllers/testdata/results/case_0/apiserver/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,24 @@ spec:
limits:
cpu: 500m
memory: 1Gi
volumeMounts:
- mountPath: /config/sample_config.json
name: sample-config
subPath: sample_config.json
- mountPath: /samples/
name: sample-pipeline
volumes:
- name: proxy-tls
secret:
secretName: ds-pipelines-proxy-tls-testdsp0
defaultMode: 420
- configMap:
defaultMode: 420
name: sample-config-testdsp0
name: sample-config
- configMap:
defaultMode: 420
name: sample-pipeline-testdsp0
name: sample-pipeline

serviceAccountName: ds-pipeline-testdsp0
14 changes: 14 additions & 0 deletions controllers/testdata/results/case_2/apiserver/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,23 @@ spec:
limits:
cpu: 2522m
memory: 5Gi
volumeMounts:
- mountPath: /config/sample_config.json
name: sample-config
subPath: sample_config.json
- mountPath: /samples/
name: sample-pipeline
volumes:
- name: proxy-tls
secret:
secretName: ds-pipelines-proxy-tls-testdsp2
defaultMode: 420
- configMap:
defaultMode: 420
name: sample-config-testdsp2
name: sample-config
- configMap:
defaultMode: 420
name: sample-pipeline-testdsp2
name: sample-pipeline
serviceAccountName: ds-pipeline-testdsp2
16 changes: 16 additions & 0 deletions controllers/testdata/results/case_3/apiserver/sample-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
data:
sample_config.json: |-
[
{
"name": "[Demo] iris-training",
"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",
"file": "/samples/iris-pipeline-compiled.yaml"
"file": "/samples/iris-pipeline-compiled.yaml"
}
]
kind: ConfigMap
metadata:
name: sample-config-testdsp3
namespace: default
11 changes: 11 additions & 0 deletions controllers/testdata/results/case_3/apiserver/sample-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: sample-pipeline-testdsp3
namespace: default
data:
sample-pipeline.yaml: |-
pipeline: placeholder
reason: |-
we're not actually checking the contents here,
just verifying the CM itself doesn't exist in this test

0 comments on commit efcbb82

Please sign in to comment.