From 1a0e4e952b249047431b231a533fe7add2b3d856 Mon Sep 17 00:00:00 2001 From: Jesse Suen Date: Thu, 6 Feb 2020 17:43:03 -0800 Subject: [PATCH 1/6] fix: rollout transformer for pod affinity. add new v0.7 name references and testing --- Makefile | 6 +- docs/features/kustomize.md | 3 +- .../{ => example}/kustomization.yaml | 2 +- .../{ => example}/rollouts-demo.yaml | 0 .../features/kustomize/rollout-transform.yaml | 37 +++-- test/kustomize/rollout/expected.yaml | 152 ++++++++++++++++++ test/kustomize/rollout/kustomization.yaml | 43 +++++ test/kustomize/rollout/rollout.yaml | 108 +++++++++++++ test/kustomize/test.sh | 13 ++ 9 files changed, 344 insertions(+), 20 deletions(-) rename docs/features/kustomize/{ => example}/kustomization.yaml (95%) rename docs/features/kustomize/{ => example}/rollouts-demo.yaml (100%) create mode 100644 test/kustomize/rollout/expected.yaml create mode 100644 test/kustomize/rollout/kustomization.yaml create mode 100644 test/kustomize/rollout/rollout.yaml create mode 100755 test/kustomize/test.sh diff --git a/Makefile b/Makefile index 8614819885..97bb48e239 100644 --- a/Makefile +++ b/Makefile @@ -88,9 +88,13 @@ lint: golangci-lint run --fix .PHONY: test -test: +test: test-kustomize go test -failfast -covermode=count -coverprofile=coverage.out ${TEST_TARGET} +.PHONY: test-kustomize +test-kustomize: + ./test/kustomize/test.sh + .PHONY: coverage coverage: test go tool cover -html=coverage.out -o coverage.html diff --git a/docs/features/kustomize.md b/docs/features/kustomize.md index 2771aedbd2..6a36088e8b 100644 --- a/docs/features/kustomize.md +++ b/docs/features/kustomize.md @@ -18,4 +18,5 @@ configurations: - rollout-transform.yaml ``` -A example kustomize app demonstrating the ability to use transformers with Rollouts can be seen [here](https://github.com/argoproj/argo-rollouts/blob/master/docs/features/kustomize/). +A example kustomize app demonstrating the ability to use transformers with Rollouts can be seen +[here](https://github.com/argoproj/argo-rollouts/blob/master/docs/features/kustomize/example). diff --git a/docs/features/kustomize/kustomization.yaml b/docs/features/kustomize/example/kustomization.yaml similarity index 95% rename from docs/features/kustomize/kustomization.yaml rename to docs/features/kustomize/example/kustomization.yaml index dcc6693f78..dd59ddc065 100644 --- a/docs/features/kustomize/kustomization.yaml +++ b/docs/features/kustomize/example/kustomization.yaml @@ -2,7 +2,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization configurations: -- rollout-transform.yaml +- ../rollout-transform.yaml namePrefix: my- diff --git a/docs/features/kustomize/rollouts-demo.yaml b/docs/features/kustomize/example/rollouts-demo.yaml similarity index 100% rename from docs/features/kustomize/rollouts-demo.yaml rename to docs/features/kustomize/example/rollouts-demo.yaml diff --git a/docs/features/kustomize/rollout-transform.yaml b/docs/features/kustomize/rollout-transform.yaml index 2d14c531f5..99f88156d2 100644 --- a/docs/features/kustomize/rollout-transform.yaml +++ b/docs/features/kustomize/rollout-transform.yaml @@ -1,4 +1,4 @@ -# https://github.com/kubernetes-sigs/kustomize/blob/master/api/plugins/builtinconfig/consts/namereference.go +# https://github.com/kubernetes-sigs/kustomize/blob/master/api/konfig/builtinpluginconsts/namereference.go nameReference: - kind: ConfigMap version: v1 @@ -32,7 +32,17 @@ nameReference: kind: Rollout - path: spec/template/spec/volumes/projected/sources/secret/name kind: Rollout -# These Service fields are unique to Rollouts and absent from Rollout +- kind: ServiceAccount + version: v1 + fieldSpecs: + - path: spec/template/spec/serviceAccountName + kind: Rollout +- kind: PersistentVolumeClaim + version: v1 + fieldSpecs: + - path: spec/template/spec/volumes/persistentVolumeClaim/claimName + kind: Rollout +# The name references below are unique to Rollouts and not applicable to Deployment - kind: Service version: v1 fieldSpecs: @@ -42,18 +52,15 @@ nameReference: kind: Rollout - path: spec/strategy/canary/canaryService kind: Rollout -- kind: ServiceAccount - version: v1 - fieldSpecs: - - path: spec/template/spec/serviceAccountName + - path: spec/strategy/canary/stableService kind: Rollout -- kind: PersistentVolumeClaim - version: v1 +- kind: VirtualService + group: networking.istio.io fieldSpecs: - - path: spec/template/spec/volumes/persistentVolumeClaim/claimName + - path: spec/strategy/canary/trafficRouting/istio/virtualService/name kind: Rollout -# https://github.com/kubernetes-sigs/kustomize/blob/master/api/plugins/builtinconfig/consts/commonlabels.go +# https://github.com/kubernetes-sigs/kustomize/blob/master/api/konfig/builtinpluginconsts/commonlabels.go commonLabels: - path: spec/selector/matchLabels create: true @@ -63,28 +70,24 @@ commonLabels: kind: Rollout - path: spec/template/spec/affinity/podAffinity/preferredDuringSchedulingIgnoredDuringExecution/podAffinityTerm/labelSelector/matchLabels create: false - group: apps kind: Rollout - path: spec/template/spec/affinity/podAffinity/requiredDuringSchedulingIgnoredDuringExecution/labelSelector/matchLabels create: false - group: apps kind: Rollout - path: spec/template/spec/affinity/podAntiAffinity/preferredDuringSchedulingIgnoredDuringExecution/podAffinityTerm/labelSelector/matchLabels create: false - group: apps kind: Rollout - path: spec/template/spec/affinity/podAntiAffinity/requiredDuringSchedulingIgnoredDuringExecution/labelSelector/matchLabels create: false - group: apps kind: Rollout -# https://github.com/kubernetes-sigs/kustomize/blob/master/api/plugins/builtinconfig/consts/commonannotations.go +# https://github.com/kubernetes-sigs/kustomize/blob/master/api/konfig/builtinpluginconsts/commonannotations.go commonAnnotations: - path: spec/template/metadata/annotations create: true kind: Rollout -# https://github.com/kubernetes-sigs/kustomize/blob/master/api/plugins/builtinconfig/consts/varreference.go +# https://github.com/kubernetes-sigs/kustomize/blob/master/api/konfig/builtinpluginconsts/varreference.go varReference: - path: spec/template/spec/containers/args kind: Rollout @@ -103,7 +106,7 @@ varReference: - path: spec/template/spec/initContainers/volumeMounts/mountPath kind: Rollout -# https://github.com/kubernetes-sigs/kustomize/blob/master/api/plugins/builtinconfig/consts/replicas.go +# https://github.com/kubernetes-sigs/kustomize/blob/master/api/konfig/builtinpluginconsts/replicas.go replicas: - path: spec/replicas create: true diff --git a/test/kustomize/rollout/expected.yaml b/test/kustomize/rollout/expected.yaml new file mode 100644 index 0000000000..997f48754d --- /dev/null +++ b/test/kustomize/rollout/expected.yaml @@ -0,0 +1,152 @@ +apiVersion: v1 +data: + FOO: BAR +kind: ConfigMap +metadata: + annotations: + foo: bar + labels: + foo: bar + name: my-guestbook-cm-bt8kmct6gk +--- +apiVersion: v1 +data: + password: UGE1NXcwcmQ= +kind: Secret +metadata: + annotations: + foo: bar + labels: + foo: bar + name: my-guestbook-secret-t95h96m85d +type: Opaque +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + foo: bar + labels: + foo: bar + name: my-guestbook-canary-svc +spec: + ports: + - port: 80 + protocol: TCP + targetPort: 8080 + selector: + app: guestbook + foo: bar +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + foo: bar + labels: + foo: bar + name: my-guestbook-stable-svc +spec: + ports: + - port: 80 + protocol: TCP + targetPort: 8080 + selector: + app: guestbook + foo: bar +--- +apiVersion: argoproj.io/v1alpha1 +kind: Rollout +metadata: + annotations: + foo: bar + labels: + foo: bar + name: my-guestbook +spec: + replicas: 3 + selector: + matchLabels: + app: guestbook + foo: bar + strategy: + canary: + canaryService: my-guestbook-canary-svc + stableService: my-guestbook-stable-svc + trafficRouting: + istio: + virtualService: + name: my-guestbook-vsvc + routes: + - primary + template: + metadata: + annotations: + foo: bar + labels: + app: guestbook + foo: bar + spec: + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + podAffinityTerm: + labelSelector: + matchLabels: + app: guestbook + foo: bar + containers: + - command: + - ping my-guestbook-stable-svc + env: + - name: PASSWORD + valueFrom: + secretKeyRef: + key: password + name: my-guestbook-secret-t95h96m85d + - name: FOO + valueFrom: + configMapKeyRef: + key: FOO + name: my-guestbook-cm-bt8kmct6gk + image: guestbook:v2 + name: guestbook + ports: + - containerPort: 8080 + name: http + protocol: TCP + volumeMounts: + - mountPath: /etc/config + name: config-volume + - mountPath: /etc/secrets + name: secret-volume + volumes: + - configMap: + name: my-guestbook-cm-bt8kmct6gk + name: config-volume + - name: secret-volume + secret: + secretName: my-guestbook-secret-t95h96m85d +--- +apiVersion: networking.istio.io/v1alpha3 +kind: VirtualService +metadata: + annotations: + foo: bar + labels: + foo: bar + name: my-guestbook-vsvc +spec: + gateways: + - istio-rollout-gateway + hosts: + - istio-rollout.dev.argoproj.io + http: + - name: primary + route: + - destination: + host: guestbook-stable-svc + weight: 100 + - destination: + host: guestbook-canary-svc + weight: 0 diff --git a/test/kustomize/rollout/kustomization.yaml b/test/kustomize/rollout/kustomization.yaml new file mode 100644 index 0000000000..85adc2d71f --- /dev/null +++ b/test/kustomize/rollout/kustomization.yaml @@ -0,0 +1,43 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +configurations: +- ../../../docs/features/kustomize/rollout-transform.yaml + +namePrefix: my- + +resources: +- rollout.yaml + +configMapGenerator: +- name: guestbook-cm + literals: + - FOO=BAR + +secretGenerator: +- name: guestbook-secret + literals: + - password=Pa55w0rd + +commonLabels: + foo: bar + +commonAnnotations: + foo: bar + +vars: +- name: SERVICE_NAME + objref: + kind: Service + name: guestbook-stable-svc + apiVersion: v1 + fieldref: + fieldpath: metadata.name + +replicas: +- name: guestbook + count: 3 + +images: +- name: guestbook + newTag: v2 diff --git a/test/kustomize/rollout/rollout.yaml b/test/kustomize/rollout/rollout.yaml new file mode 100644 index 0000000000..0333e0a0be --- /dev/null +++ b/test/kustomize/rollout/rollout.yaml @@ -0,0 +1,108 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Rollout +metadata: + name: guestbook +spec: + selector: + matchLabels: + app: guestbook + template: + metadata: + labels: + app: guestbook + spec: + volumes: + - name: config-volume + configMap: + name: guestbook-cm + - name: secret-volume + secret: + secretName: guestbook-secret + containers: + - name: guestbook + image: guestbook:v1 + command: + - ping $(SERVICE_NAME) + ports: + - name: http + containerPort: 8080 + protocol: TCP + volumeMounts: + - name: config-volume + mountPath: /etc/config + - name: secret-volume + mountPath: /etc/secrets + env: + - name: PASSWORD + valueFrom: + secretKeyRef: + name: guestbook-secret + key: password + - name: FOO + valueFrom: + configMapKeyRef: + name: guestbook-cm + key: FOO + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + podAffinityTerm: + labelSelector: + matchLabels: + app: guestbook + strategy: + canary: + stableService: guestbook-stable-svc + canaryService: guestbook-canary-svc + trafficRouting: + istio: + virtualService: + name: guestbook-vsvc + routes: + - primary + +--- +apiVersion: networking.istio.io/v1alpha3 +kind: VirtualService +metadata: + name: guestbook-vsvc +spec: + gateways: + - istio-rollout-gateway + hosts: + - istio-rollout.dev.argoproj.io + http: + - name: primary + route: + - destination: + host: guestbook-stable-svc + weight: 100 + - destination: + host: guestbook-canary-svc + weight: 0 + +--- +apiVersion: v1 +kind: Service +metadata: + name: guestbook-stable-svc +spec: + selector: + app: guestbook + ports: + - protocol: TCP + port: 80 + targetPort: 8080 + +--- +apiVersion: v1 +kind: Service +metadata: + name: guestbook-canary-svc +spec: + selector: + app: guestbook + ports: + - protocol: TCP + port: 80 + targetPort: 8080 diff --git a/test/kustomize/test.sh b/test/kustomize/test.sh new file mode 100755 index 0000000000..f29b9fb118 --- /dev/null +++ b/test/kustomize/test.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +for i in `ls ${DIR}/*/kustomization.yaml`; do + dir_name=$(dirname $i) + diff_out=$(diff ${dir_name}/expected.yaml <(kustomize build ${dir_name} --load_restrictor none)) + if [[ $? -ne 0 ]]; then + echo "${i} had unexpected diff:" + echo "${diff_out}" + exit 1 + fi +done \ No newline at end of file From dfd7cd6330b0307dfa362758b3961d63c05e3354 Mon Sep 17 00:00:00 2001 From: Danny Thomson Date: Fri, 7 Feb 2020 14:34:30 -0800 Subject: [PATCH 2/6] Add kustomize to circleci --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 83768d0d48..963a39b19e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,6 +14,7 @@ jobs: - restore_cache: keys: - v3-pkg-cache + - run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash - run: go get github.com/jstemmer/go-junit-report - run: go get github.com/golangci/golangci-lint/cmd/golangci-lint - run: From a4870e0b038cc5db340877ac5999d32f7cc7e6b3 Mon Sep 17 00:00:00 2001 From: Danny Thomson Date: Fri, 7 Feb 2020 14:49:03 -0800 Subject: [PATCH 3/6] Move kustomize to /usr/local/bin --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 963a39b19e..f25775f359 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,7 @@ jobs: - restore_cache: keys: - v3-pkg-cache - - run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash + - run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash && mv kustomize /usr/local/bin/ - run: go get github.com/jstemmer/go-junit-report - run: go get github.com/golangci/golangci-lint/cmd/golangci-lint - run: From 5104f16ae4a3847135ae4ff496480c525a0b6fab Mon Sep 17 00:00:00 2001 From: Danny Thomson Date: Fri, 7 Feb 2020 14:59:15 -0800 Subject: [PATCH 4/6] Brew install kustomize --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f25775f359..7cf97241c5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,7 @@ jobs: - restore_cache: keys: - v3-pkg-cache - - run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash && mv kustomize /usr/local/bin/ + - run: brew install kustomize - run: go get github.com/jstemmer/go-junit-report - run: go get github.com/golangci/golangci-lint/cmd/golangci-lint - run: From 2911dc022d01ab30558578fe549f4b5890004f78 Mon Sep 17 00:00:00 2001 From: Danny Thomson Date: Fri, 7 Feb 2020 15:03:27 -0800 Subject: [PATCH 5/6] Install kustomize at home dir --- .circleci/config.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7cf97241c5..1df3c9f71d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,11 @@ jobs: - restore_cache: keys: - v3-pkg-cache - - run: brew install kustomize + - run: + name: Install kustomize + command: | + cd $HOME + curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash - run: go get github.com/jstemmer/go-junit-report - run: go get github.com/golangci/golangci-lint/cmd/golangci-lint - run: From ba1f259cb07c544a6bb937851aa6df8a50ed41b3 Mon Sep 17 00:00:00 2001 From: Danny Thomson Date: Fri, 7 Feb 2020 15:11:00 -0800 Subject: [PATCH 6/6] Move kustomize to /usr/local/bin/ --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1df3c9f71d..b36b6d50e2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,8 +17,8 @@ jobs: - run: name: Install kustomize command: | - cd $HOME curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash + sudo mv kustomize /usr/local/bin/ - run: go get github.com/jstemmer/go-junit-report - run: go get github.com/golangci/golangci-lint/cmd/golangci-lint - run: