Skip to content

Commit

Permalink
api/resource: add new test for inline options.
Browse files Browse the repository at this point in the history
  • Loading branch information
elisshafer committed Nov 5, 2022
1 parent 44da033 commit c68667e
Showing 1 changed file with 160 additions and 3 deletions.
163 changes: 160 additions & 3 deletions api/krusty/generatormergeandreplace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,161 @@ configMapGenerator:
- name: configmap-in-overlay
literals:
- hello=world
- name: configmap-in-base
behavior: replace
literals:
- foo=override-bar
secretGenerator:
- name: secret-in-base
behavior: merge
literals:
- proxy=haproxy
`)
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
note: This is a test annotation
labels:
app: mynginx
env: staging
org: example.com
team: override-foo
name: staging-team-foo-nginx
spec:
selector:
matchLabels:
app: mynginx
env: staging
org: example.com
team: override-foo
template:
metadata:
annotations:
note: This is a test annotation
labels:
app: mynginx
env: staging
org: example.com
team: override-foo
spec:
containers:
- image: nginx
name: nginx
volumeMounts:
- mountPath: /tmp/ps
name: nginx-persistent-storage
volumes:
- gcePersistentDisk:
pdName: nginx-persistent-storage
name: nginx-persistent-storage
- configMap:
name: staging-configmap-in-overlay-dc6fm46dhm
name: configmap-in-overlay
- configMap:
name: staging-team-foo-configmap-in-base-hc6g9dk6g9
name: configmap-in-base
---
apiVersion: v1
kind: Service
metadata:
annotations:
note: This is a test annotation
labels:
app: mynginx
env: staging
org: example.com
team: override-foo
name: staging-team-foo-nginx
spec:
ports:
- port: 80
selector:
app: mynginx
env: staging
org: example.com
team: override-foo
---
apiVersion: v1
data:
foo: override-bar
kind: ConfigMap
metadata:
annotations:
note: This is a test annotation
labels:
app: mynginx
env: staging
org: example.com
team: override-foo
name: staging-team-foo-configmap-in-base-hc6g9dk6g9
---
apiVersion: v1
data:
password: c29tZXB3
proxy: aGFwcm94eQ==
username: YWRtaW4=
kind: Secret
metadata:
annotations:
note: This is a test annotation
labels:
app: mynginx
env: staging
org: example.com
team: override-foo
name: staging-team-foo-secret-in-base-k2k4692t9g
type: Opaque
---
apiVersion: v1
data:
hello: world
kind: ConfigMap
metadata:
labels:
env: staging
team: override-foo
name: staging-configmap-in-overlay-dc6fm46dhm
`)
}

func TestMergeAndReplaceDisableNameSuffixHashGenerators(t *testing.T) {
th := kusttest_test.MakeHarness(t)
makeBaseWithGenerators(th)
th.WriteF("overlay/deployment.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
template:
spec:
volumes:
- name: nginx-persistent-storage
emptyDir: null
gcePersistentDisk:
pdName: nginx-persistent-storage
- configMap:
name: configmap-in-overlay
name: configmap-in-overlay
`)
th.WriteK("overlay", `
namePrefix: staging-
commonLabels:
env: staging
team: override-foo
patchesStrategicMerge:
- deployment.yaml
resources:
- ../app
configMapGenerator:
- name: configmap-in-overlay
literals:
- hello=world
options:
disableNameSuffixHash: true
- name: configmap-in-base
behavior: replace
literals:
Expand All @@ -346,6 +501,8 @@ secretGenerator:
behavior: merge
literals:
- proxy=haproxy
options:
disableNameSuffixHash: true
`)
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
Expand Down Expand Up @@ -388,7 +545,7 @@ spec:
pdName: nginx-persistent-storage
name: nginx-persistent-storage
- configMap:
name: staging-configmap-in-overlay-dc6fm46dhm
name: staging-configmap-in-overlay
name: configmap-in-overlay
- configMap:
name: staging-team-foo-configmap-in-base
Expand Down Expand Up @@ -442,7 +599,7 @@ metadata:
env: staging
org: example.com
team: override-foo
name: staging-team-foo-secret-in-base-k2k4692t9g
name: staging-team-foo-secret-in-base
type: Opaque
---
apiVersion: v1
Expand All @@ -453,7 +610,7 @@ metadata:
labels:
env: staging
team: override-foo
name: staging-configmap-in-overlay-dc6fm46dhm
name: staging-configmap-in-overlay
`)
}

Expand Down

0 comments on commit c68667e

Please sign in to comment.