Skip to content

Commit

Permalink
Pipeline has inputs fields which can be read by runTemplates
Browse files Browse the repository at this point in the history
Co-authored-by: Waciuma Wanjohi <lwanjohi@pivotal.io>
Co-authored-by: Todd Ritchie <tritchie@vmware.com>

[#81]
  • Loading branch information
waciumawanjohi committed Sep 22, 2021
1 parent fe16d8b commit 49e55fb
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 9 deletions.
4 changes: 4 additions & 0 deletions config/crd/bases/carto.run_pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ spec:
type: object
spec:
properties:
inputs:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
type: object
runTemplateRef:
properties:
kind:
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/v1alpha1/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ type PipelineStatus struct {

type PipelineSpec struct {
// +kubebuilder:validation:Required
RunTemplateRef TemplateReference `json:"runTemplateRef"`
RunTemplateRef TemplateReference `json:"runTemplateRef"`
Inputs map[string]apiextensionsv1.JSON `json:"inputs,omitempty"`
}

type TemplateReference struct {
Expand Down
9 changes: 8 additions & 1 deletion pkg/apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions tests/integration/pipeline_service/pipeline_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var _ = Describe("Stamping a resource on Pipeline Creation", func() {
matchExpressions:
- operator : In
scopeName: PriorityClass
values: [$(pipeline.metadata.labels.some-val)$]
values: [$(pipeline.spec.inputs.key)$]
`,
testNS, testNS,
)
Expand All @@ -97,13 +97,13 @@ var _ = Describe("Stamping a resource on Pipeline Creation", func() {
metadata:
namespace: %s
name: my-pipeline
labels:
some-val: first
spec:
runTemplateRef:
name: my-run-template
namespace: %s
kind: RunTemplate
inputs:
key: val
`,
testNS, testNS)

Expand Down Expand Up @@ -134,12 +134,12 @@ var _ = Describe("Stamping a resource on Pipeline Creation", func() {
}, "2s").Should(BeNumerically("<=", 1))

Expect(resourceList.Items[0].Name).To(ContainSubstring("my-stamped-resource-"))
Expect(resourceList.Items[0].Spec.ScopeSelector.MatchExpressions[0].Values).To(ConsistOf("first"))
Expect(resourceList.Items[0].Spec.ScopeSelector.MatchExpressions[0].Values).To(ConsistOf("val"))
})

Context("and the Pipeline object is updated", func() {
BeforeEach(func() {
Expect(AlterFieldOfNestedStringMaps(pipelineDefinition.Object, "metadata.labels.some-val", "second")).To(Succeed())
Expect(AlterFieldOfNestedStringMaps(pipelineDefinition.Object, "spec.inputs.key", "new-val")).To(Succeed())
Expect(c.Update(ctx, pipelineDefinition, &client.UpdateOptions{})).To(Succeed())
})
It("creates a second object alongside the first", func() {
Expand All @@ -162,8 +162,8 @@ var _ = Describe("Stamping a resource on Pipeline Creation", func() {
return element.(v1.ResourceQuota).Spec.ScopeSelector.MatchExpressions[0].Values[0]
}
Expect(resourceList.Items).To(MatchAllElements(id, Elements{
"first": Not(BeNil()),
"second": Not(BeNil()),
"val": Not(BeNil()),
"new-val": Not(BeNil()),
}))
})
})
Expand Down
29 changes: 29 additions & 0 deletions tests/kuttl/pipeline-with-inputs/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2021 VMware
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---

apiVersion: carto.run/v1alpha1
kind: Deliverable
value:
object:
nested: hi
still-nested: bye
list:
- position: one
val: first
- position: two
val: second
string: silly
int: 3
36 changes: 36 additions & 0 deletions tests/kuttl/pipeline-with-inputs/00-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2021 VMware
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: carto.run/v1alpha1
kind: Pipeline
metadata:
name: my-pipeline
labels:
my-label: this-is-it
my-other-label: bye
spec:
runTemplateRef:
name: my-run-template-inputs

inputs:
some-object:
nested: hi
still-nested: bye
some-list:
- position: one
val: first
- position: two
val: second
some-int: 3
some-string: silly
30 changes: 30 additions & 0 deletions tests/kuttl/pipeline-with-inputs/00-run-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2021 VMware
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: carto.run/v1alpha1
kind: RunTemplate
metadata:
name: my-run-template-inputs
spec:
template:
apiVersion: carto.run/v1alpha1
kind: Deliverable
metadata:
generateName: my-stamped-resource-inputs-
value:
object: $(pipeline.spec.inputs.some-object)$
list: $(pipeline.spec.inputs.some-list)$
string: $(pipeline.spec.inputs.some-string)$
int: $(pipeline.spec.inputs.some-int)$
30 changes: 30 additions & 0 deletions tests/kuttl/pipelines-driven-by-supply-chain/00-run-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2021 VMware
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: carto.run/v1alpha1
kind: RunTemplate
metadata:
name: my-run-template-inputs
spec:
template:
apiVersion: carto.run/v1alpha1
kind: Deliverable
metadata:
generateName: my-stamped-resource-inputs-
value:
url: $(pipeline.spec.inputs.source-url)$
revision: $(pipeline.spec.inputs.source-revision)$
some-object-def: $(pipeline.spec.inputs.definition)$
some-hard-coded-info: not-from-the-pipeline
61 changes: 61 additions & 0 deletions tests/kuttl/pipelines-driven-by-supply-chain/00-templates.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2021 VMware
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: carto.run/v1alpha1
kind: ClusterSourceTemplate
metadata:
name: source---pipelines-driven-by-supply-chain
spec:
template:
apiVersion: v1
kind: ConfigMap
metadata:
name: example-first-configmap
data:
url: $(workload.spec.source.git.url)$
branch: "main"
urlPath: data.url
revisionPath: data.branch

---
apiVersion: carto.run/v1alpha1
kind: ClusterSourceTemplate
metadata:
name: pipeline---pipelines-driven-by-supply-chain
spec:
# TODO: update in story 4
urlPath: .spec.runTemplateRef.name
revisionPath: .spec.runTemplateRef.name

params:
- name: expected-param
default:
key: value

template:
apiVersion: carto.run/v1alpha1
kind: Pipeline
metadata:
name: my-pipeline
labels:
my-label: this-is-it
spec:
runTemplateRef:
name: my-run-template-inputs

inputs:
source-url: $(source.url)$
source-revision: $(source.revision)$
definition: $(params.expected-param)$
38 changes: 38 additions & 0 deletions tests/kuttl/pipelines-driven-by-supply-chain/01-supply-chain.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2021 VMware
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: carto.run/v1alpha1
kind: ClusterSupplyChain
metadata:
name: supply-chain---pipelines-driven-by-supply-chain
spec:
selector:
integration-test: "pipelines-driven-by-supply-chain"
components:
- name: source-provider
templateRef:
kind: ClusterSourceTemplate
name: source---pipelines-driven-by-supply-chain

- name: pipeline-provider
templateRef:
kind: ClusterSourceTemplate
name: pipeline---pipelines-driven-by-supply-chain
sources:
- component: source-provider
name: source-provider
params:
- name: expected-param
value: $(workload.spec.params[0].value)$
29 changes: 29 additions & 0 deletions tests/kuttl/pipelines-driven-by-supply-chain/02-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2021 VMware
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---

apiVersion: carto.run/v1alpha1
kind: Deliverable
value:
url: https://github.com/spring-projects/spring-petclinic.git
revision: main
some-object-def:
apiVersion: v1
kind: ConfigMap
metadata:
name: some-configmap
data:
an-ice-cream-flavor: cookies-and-cream
some-hard-coded-info: not-from-the-pipeline
34 changes: 34 additions & 0 deletions tests/kuttl/pipelines-driven-by-supply-chain/02-workload.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2021 VMware
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: carto.run/v1alpha1
kind: Workload
metadata:
name: petclinic
labels:
integration-test: "pipelines-driven-by-supply-chain"
spec:
params:
- name: a-config-map
value:
apiVersion: v1
kind: ConfigMap
metadata:
name: some-configmap
data:
an-ice-cream-flavor: cookies-and-cream
source:
git:
url: https://github.com/spring-projects/spring-petclinic.git

0 comments on commit 49e55fb

Please sign in to comment.