Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rollout transformer for pod affinity. add new v0.7 name references and testing #399

Merged
merged 6 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docs/features/kustomize.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

configurations:
- rollout-transform.yaml
- ../rollout-transform.yaml

namePrefix: my-

Expand Down
37 changes: 20 additions & 17 deletions docs/features/kustomize/rollout-transform.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
152 changes: 152 additions & 0 deletions test/kustomize/rollout/expected.yaml
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions test/kustomize/rollout/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading