Skip to content

Instantly share code, notes, and snippets.

@jorgemoralespou
Last active February 27, 2020 19:13
Show Gist options
  • Save jorgemoralespou/35fdddfb1a7a801efed427a8310f9aeb to your computer and use it in GitHub Desktop.
Save jorgemoralespou/35fdddfb1a7a801efed427a8310f9aeb to your computer and use it in GitHub Desktop.
#@ load("@ytt:data", "data")
---
apiVersion: v1
kind: Namespace
metadata:
name: #@ data.values.namespace
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: admin
namespace: #@ data.values.namespace
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: admin
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: #@ data.values.developeruser
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/part-of: voting
app.kubernetes.io/name: ui
app.kubernetes.io/component: frontend
app.kubernetes.io/managed-by: tekton
name: ui
namespace: #@ data.values.namespace
spec:
replicas: 1
selector:
matchLabels:
app: ui
template:
metadata:
labels:
app: ui
spec:
containers:
- image: quay.io/openshift-pipeline/vote-ui:latest
imagePullPolicy: Always
name: ui
ports:
- containerPort: 8080
protocol: TCP
- containerPort: 9090
protocol: TCP
env:
- name: VOTING_API_SERVICE_HOST
value: "api"
- name: VOTING_API_SERVICE_PORT
value: "9000"
---
apiVersion: v1
kind: Service
metadata:
labels:
app: ui
name: ui
namespace: #@ data.values.namespace
spec:
type: NodePort
ports:
- name: 8080-tcp
port: 8080
targetPort: 8080
protocol: TCP
selector:
app: ui
---
apiVersion: route.openshift.io/v1
kind: Route
metadata:
labels:
app: ui
name: ui
namespace: #@ data.values.namespace
spec:
port:
targetPort: 8080-tcp
to:
kind: Service
name: ui
weight: 100
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/part-of: voting
app.kubernetes.io/name: api
app.kubernetes.io/component: backend
app.kubernetes.io/managed-by: tekton3
name: api
namespace: #@ data.values.namespace
spec:
replicas: 1
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- image: quay.io/openshift-pipeline/vote-api:latest
imagePullPolicy: Always
name: api
ports:
- containerPort: 9000
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
labels:
app: api
name: api
namespace: #@ data.values.namespace
spec:
type: ClusterIP
ports:
- protocol: TCP
port: 9000
targetPort: 9000
selector:
app: api
#@ load("@ytt:data", "data")
---
apiVersion: v1
kind: Namespace
metadata:
name: #@ data.values.namespace
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: admin
namespace: #@ data.values.namespace
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: admin
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: #@ data.values.developeruser
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: api-repo
namespace: #@ data.values.namespace
annotations:
kapp.k14s.io/change-group: "tekton/pipeline"
spec:
type: git
params:
- name: url
value: http://github.com/openshift-pipelines/vote-api.git
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: api-image
namespace: #@ data.values.namespace
annotations:
kapp.k14s.io/change-group: "tekton/pipeline"
spec:
type: image
params:
- name: url
value: #@ "image-registry.openshift-image-registry.svc:5000/{}/api:latest".format(data.values.namespace)
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: ui-repo
namespace: #@ data.values.namespace
annotations:
kapp.k14s.io/change-group: "tekton/pipeline"
spec:
type: git
params:
- name: url
value: http://github.com/openshift-pipelines/vote-ui.git
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: ui-image
namespace: #@ data.values.namespace
annotations:
kapp.k14s.io/change-group: "tekton/pipeline"
spec:
type: image
params:
- name: url
value: #@ "image-registry.openshift-image-registry.svc:5000/{}/ui:latest".format(data.values.namespace)
---
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: apply-manifests
namespace: #@ data.values.namespace
annotations:
kapp.k14s.io/change-group: "tekton/pipeline"
spec:
inputs:
resources:
- {type: git, name: source}
params:
- name: manifest_dir
description: The directory in source that contains yaml manifests
type: string
default: "k8s"
steps:
- name: apply
image: quay.io/openshift/origin-cli:latest
workingDir: /workspace/source
command: ["/bin/bash", "-c"]
args:
- |-
echo Applying manifests in $(inputs.params.manifest_dir) directory
oc apply -f $(inputs.params.manifest_dir)
echo -----------------------------------
---
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: update-deployment
namespace: #@ data.values.namespace
annotations:
kapp.k14s.io/change-group: "tekton/pipeline"
spec:
inputs:
resources:
- {type: image, name: image}
params:
- name: deployment
description: The name of the deployment patch the image
type: string
steps:
- name: patch
image: quay.io/openshift/origin-cli:latest
command: ["/bin/bash", "-c"]
args:
- |-
oc patch deployment $(inputs.params.deployment) --patch='{"spec":{"template":{"spec":{
"containers":[{
"name": "$(inputs.params.deployment)",
"image":"$(inputs.resources.image.url)"
}]
}}}}'
---
apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
name: build-and-deploy
namespace: #@ data.values.namespace
annotations:
kapp.k14s.io/change-group: "tekton/pipeline"
spec:
resources:
- name: api-repo
type: git
- name: api-image
type: image
- name: ui-repo
type: git
- name: ui-image
type: image
tasks:
- name: build-api
taskRef:
name: buildah
kind: ClusterTask
resources:
inputs:
- name: source
resource: api-repo
outputs:
- name: image
resource: api-image
params:
- name: TLSVERIFY
value: "false"
- name: apply-api-manifests
taskRef:
name: apply-manifests
resources:
inputs:
- name: source
resource: api-repo
runAfter:
- build-api
- name: update-api-image
taskRef:
name: update-deployment
resources:
inputs:
- name: image
resource: api-image
params:
- name: deployment
value: "api"
runAfter:
- apply-api-manifests
- name: build-ui
taskRef:
name: s2i-python-3
kind: ClusterTask
resources:
inputs:
- name: source
resource: ui-repo
outputs:
- name: image
resource: ui-image
params:
- name: TLSVERIFY
value: "false"
- name: apply-ui-manifests
taskRef:
name: apply-manifests
resources:
inputs:
- name: source
resource: ui-repo
runAfter:
- build-ui
- update-api-image
- name: update-ui-image
taskRef:
name: update-deployment
resources:
inputs:
- name: image
resource: ui-image
params:
- name: deployment
value: "ui"
runAfter:
- apply-ui-manifests
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
name: build-and-deploy
namespace: #@ data.values.namespace
annotations:
kapp.k14s.io/versioned: ''
kapp.k14s.io/change-rule: "upsert after upserting tekton/pipeline"
spec:
pipelineRef:
name: build-and-deploy
resources:
- name: api-repo
resourceRef:
name: api-repo
- name: api-image
resourceRef:
name: api-image
- name: ui-repo
resourceRef:
name: api-repo
- name: ui-image
resourceRef:
name: api-image
serviceAccountName: pipeline
timeout: 1h0m0s
Deployed (note /tmp/kapp/kapp is my modified kapp):
```
ytt ytt -f example-app.yaml -f example-pipeline.yaml -f values.yaml | /tmp/kapp/kapp deploy -a tekton-sample -n default -y -f-
```
Changed in example-app, line 97 to a new value, and executed again:
```
ytt ytt -f example-app.yaml -f example-pipeline.yaml -f values.yaml | /tmp/kapp/kapp deploy -a tekton-sample -n default -y -f-
```
And got the error:
```
panic: Invalid template version
goroutine 1 [running]:
github.com/k14s/kapp/pkg/kapp/diff.TemplateResource.Version(0x20bbe00, 0xc00002d2c0, 0x0, 0x0, 0x0, 0x203000)
github.com/k14s/kapp@/pkg/kapp/diff/template_resource.go:45 +0x9b
github.com/k14s/kapp/pkg/kapp/diff.ChangeSetWithTemplates.groupResourcesByTemplate.func2(0x1, 0x0, 0xc0008f6718)
github.com/k14s/kapp@/pkg/kapp/diff/change_set_with_templates.go:87 +0x6f
sort.insertionSort_func(0xc0008f6798, 0xc0004a1d40, 0x0, 0x2)
sort/zfuncversion.go:12 +0xb1
sort.quickSort_func(0xc0008f6798, 0xc0004a1d40, 0x0, 0x2, 0x4)
sort/zfuncversion.go:158 +0x1f3
sort.Slice(0x1cd10a0, 0xc0003c4d00, 0xc0008f6798)
sort/slice.go:17 +0xf1
github.com/k14s/kapp/pkg/kapp/diff.ChangeSetWithTemplates.groupResourcesByTemplate(0xc0004a4800, 0x1b, 0x20, 0xc000466200, 0xf, 0x10, 0xc00034a540, 0x2, 0x2, 0x1, ...)
github.com/k14s/kapp@/pkg/kapp/diff/change_set_with_templates.go:86 +0x15a
github.com/k14s/kapp/pkg/kapp/diff.ChangeSetWithTemplates.Calculate(0xc0004a4800, 0x1b, 0x20, 0xc000466200, 0xf, 0x10, 0xc00034a540, 0x2, 0x2, 0x1, ...)
github.com/k14s/kapp@/pkg/kapp/diff/change_set_with_templates.go:32 +0xd7
github.com/k14s/kapp/pkg/kapp/cmd/app.(*DeployOptions).calculateAndPresentChanges(0xc0002ad440, 0xc0004a4800, 0x1b, 0x20, 0xc000466200, 0xf, 0x10, 0xc000358600, 0x1, 0x1, ...)
github.com/k14s/kapp@/pkg/kapp/cmd/app/deploy.go:288 +0x3d6
github.com/k14s/kapp/pkg/kapp/cmd/app.(*DeployOptions).Run(0xc0002ad440, 0x0, 0x0)
github.com/k14s/kapp@/pkg/kapp/cmd/app/deploy.go:136 +0x7a8
github.com/k14s/kapp/pkg/kapp/cmd/app.NewDeployCmd.func1(0xc00042af00, 0xc0004d8720, 0x0, 0x6, 0xc0004dee40, 0xc0000dbbe0)
github.com/k14s/kapp@/pkg/kapp/cmd/app/deploy.go:48 +0x2a
github.com/k14s/kapp/pkg/kapp/cmd.NewKappCmd.func1.1(0xc00042af00, 0xc0004d8720, 0x0, 0x6, 0x0, 0x0)
github.com/k14s/kapp@/pkg/kapp/cmd/kapp.go:122 +0xcc
github.com/cppforlife/cobrautil.ReconfigureLeafCmd.func1(0xc00042af00, 0xc0004d8720, 0x0, 0x6, 0x0, 0x0)
github.com/cppforlife/[email protected]/misc.go:67 +0x135
github.com/cppforlife/cobrautil.WrapRunEForCmd.func1.1(0xc00042af00, 0xc0004d8720, 0x0, 0x6, 0x0, 0x0)
github.com/cppforlife/[email protected]/misc.go:25 +0xaf
github.com/cppforlife/cobrautil.WrapRunEForCmd.func1.1(0xc00042af00, 0xc0004d8720, 0x0, 0x6, 0x0, 0x0)
github.com/cppforlife/[email protected]/misc.go:25 +0xaf
github.com/spf13/cobra.(*Command).execute(0xc00042af00, 0xc0004d8660, 0x6, 0x6, 0xc00042af00, 0xc0004d8660)
github.com/spf13/[email protected]/command.go:762 +0x460
github.com/spf13/cobra.(*Command).ExecuteC(0xc00042a500, 0xc00042a500, 0xc00030b5c0, 0x103b32a)
github.com/spf13/[email protected]/command.go:852 +0x2ea
github.com/spf13/cobra.(*Command).Execute(...)
github.com/spf13/[email protected]/command.go:800
main.main()
github.com/k14s/kapp@/cmd/kapp/kapp.go:27 +0x16f
```
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
annotations:
kapp.k14s.io/identity: v1;tekton-sample/tekton.dev/Task/apply-manifests;tekton.dev/v1alpha1
kapp.k14s.io/nonce: "1582739835959499000"
kapp.k14s.io/original: '{"apiVersion":"tekton.dev/v1alpha1","kind":"Task","metadata":{"labels":{"kapp.k14s.io/app":"1582739791109138000","kapp.k14s.io/association":"v1.84b72e873db941ac9c96fc2056ed1778"},"name":"apply-manifests","namespace":"tekton-sample"},"spec":{"inputs":{"params":[{"default":"k8s","description":"The
directory in source that contains yaml manifests","name":"manifest_dir","type":"string"}],"resources":[{"name":"source","type":"git"}]},"steps":[{"args":["echo
Applying manifests in $(inputs.params.manifest_dir) directory\noc apply -f $(inputs.params.manifest_dir)\necho
-----------------------------------"],"command":["/bin/bash","-c"],"image":"quay.io/openshift/origin-cli:latest","name":"apply","workingDir":"/workspace/source"}]}}'
kapp.k14s.io/original-diff: |
- type: test
path: /metadata/annotations
value: {}
- type: remove
path: /metadata/annotations
- type: test
path: /spec/steps/0/resources
value: {}
- type: remove
path: /spec/steps/0/resources
kapp.k14s.io/original-diff-full: ""
kapp.k14s.io/original-diff-md5: 35806250b5c519f4774c2cf9216b956d
kapp.k14s.io/versioned: ""
creationTimestamp: "2020-02-26T17:58:34Z"
generation: 1
labels:
app.kubernetes.io/managed-by: tekton-pipelines
kapp.k14s.io/app: "1582739791109138000"
kapp.k14s.io/association: v1.84b72e873db941ac9c96fc2056ed1778
tekton.dev/pipeline: build-and-deploy
tekton.dev/pipelineRun: build-and-deploy-ver-2
tekton.dev/pipelineTask: apply-api-manifests
tekton.dev/task: apply-manifests
name: build-and-deploy-ver-2-apply-api-manifests-k5ckt
namespace: tekton-sample
ownerReferences:
- apiVersion: tekton.dev/v1alpha1
blockOwnerDeletion: true
controller: true
kind: PipelineRun
name: build-and-deploy-ver-2
uid: 98e5fddb-dfb4-4c01-8961-98293c4d6ac3
resourceVersion: "80380"
selfLink: /apis/tekton.dev/v1alpha1/namespaces/tekton-sample/taskruns/build-and-deploy-ver-2-apply-api-manifests-k5ckt
uid: af8ad901-0b0c-4b10-93bd-111e24d09b36
spec:
inputs:
resources:
- name: source
resourceRef:
name: api-repo
outputs: {}
serviceAccountName: pipeline
taskRef:
kind: Task
name: apply-manifests
timeout: 1h0m0s
status:
completionTime: "2020-02-26T17:58:50Z"
conditions:
- lastTransitionTime: "2020-02-26T17:58:50Z"
message: All Steps have completed executing
reason: Succeeded
status: "True"
type: Succeeded
podName: build-and-deploy-ver-2-apply-api-manifests-k5ckt-pod-x7d4c
resourcesResult:
- digest: ""
key: commit
name: ""
resourceRef: {}
value: 374d1daa9ee175fcf590cb62402ed43076973b0d
startTime: "2020-02-26T17:58:34Z"
steps:
- container: step-apply
imageID: quay.io/openshift/origin-cli@sha256:9bbc48ded57e662103f226217855caf107b957fbb4febb7da650bfe25d307f7b
name: apply
terminated:
containerID: cri-o://a65487cf28816569b72cf8b573407a7539996ee938de909d8e29858c3a4f2248
exitCode: 0
finishedAt: "2020-02-26T17:58:50Z"
reason: Completed
startedAt: "2020-02-26T17:58:49Z"
- container: step-git-source-api-repo-hlj9j
imageID: quay.io/openshift-pipeline/tektoncd-pipeline-git-init@sha256:0956ae04297fe4740af495ec1d6d51bd7fbd79686f5d5a4ea09ca44c4e9838cf
name: git-source-api-repo-hlj9j
terminated:
containerID: cri-o://432b03d52573f2217a750de8bef5e1052a0acc9e6cc0d6647249b00ba685b081
exitCode: 0
finishedAt: "2020-02-26T17:58:48Z"
message: '[{"name":"","digest":"","key":"commit","value":"374d1daa9ee175fcf590cb62402ed43076973b0d","resourceRef":{}}]'
reason: Completed
startedAt: "2020-02-26T17:58:47Z"
#@data/values
---
namespace: tekton-sample
developeruser: developer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment