| 1 |
// Copyright 2019 The Kubernetes Authors. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package krusty_test |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" |
| 10 |
) |
| 11 |
|
| 12 |
func makeStatefulSetKustomization(th kusttest_test.Harness) { |
| 13 |
th.WriteK(".", ` |
| 14 |
commonLabels: |
| 15 |
notIn: arrays |
| 16 |
resources: |
| 17 |
- statefulset.yaml |
| 18 |
- statefulset-with-template.yaml |
| 19 |
`) |
| 20 |
th.WriteF("statefulset.yaml", ` |
| 21 |
kind: StatefulSet |
| 22 |
apiVersion: apps/v1 |
| 23 |
metadata: |
| 24 |
name: test |
| 25 |
labels: |
| 26 |
notIn: arrays |
| 27 |
spec: |
| 28 |
serviceName: test |
| 29 |
replicas: 1 |
| 30 |
selector: |
| 31 |
matchLabels: |
| 32 |
app: test |
| 33 |
template: |
| 34 |
metadata: |
| 35 |
labels: |
| 36 |
app: test |
| 37 |
spec: |
| 38 |
containers: |
| 39 |
- name: nginx |
| 40 |
image: registry.k8s.io/nginx-slim:0.8 |
| 41 |
ports: |
| 42 |
- containerPort: 80 |
| 43 |
name: web |
| 44 |
`) |
| 45 |
th.WriteF("statefulset-with-template.yaml", ` |
| 46 |
kind: StatefulSet |
| 47 |
apiVersion: apps/v1 |
| 48 |
metadata: |
| 49 |
name: persisted-test |
| 50 |
labels: |
| 51 |
notIn: arrays |
| 52 |
spec: |
| 53 |
serviceName: test |
| 54 |
replicas: 1 |
| 55 |
selector: |
| 56 |
matchLabels: |
| 57 |
app: test |
| 58 |
template: |
| 59 |
metadata: |
| 60 |
labels: |
| 61 |
app: test |
| 62 |
spec: |
| 63 |
containers: |
| 64 |
- name: nginx |
| 65 |
image: registry.k8s.io/nginx-slim:0.8 |
| 66 |
ports: |
| 67 |
- containerPort: 80 |
| 68 |
name: web |
| 69 |
volumeMounts: |
| 70 |
- name: www |
| 71 |
mountPath: /usr/share/nginx/html |
| 72 |
- name: data |
| 73 |
mountPath: /usr/share/nginx/data |
| 74 |
volumeClaimTemplates: |
| 75 |
- metadata: |
| 76 |
name: www |
| 77 |
spec: |
| 78 |
accessModes: [ "ReadWriteOnce" ] |
| 79 |
storageClassName: my-storage-class |
| 80 |
resources: |
| 81 |
requests: |
| 82 |
storage: 1Gi |
| 83 |
- metadata: |
| 84 |
name: data |
| 85 |
spec: |
| 86 |
accessModes: [ "ReadWriteOnce" ] |
| 87 |
storageClassName: my-storage-class |
| 88 |
resources: |
| 89 |
requests: |
| 90 |
storage: 100Gi |
| 91 |
`) |
| 92 |
} |
| 93 |
|
| 94 |
func TestTransformersNoCreateArrays(t *testing.T) { |
| 95 |
th := kusttest_test.MakeHarness(t) |
| 96 |
makeStatefulSetKustomization(th) |
| 97 |
m := th.Run(".", th.MakeDefaultOptions()) |
| 98 |
th.AssertActualEqualsExpected(m, ` |
| 99 |
apiVersion: apps/v1 |
| 100 |
kind: StatefulSet |
| 101 |
metadata: |
| 102 |
labels: |
| 103 |
notIn: arrays |
| 104 |
name: test |
| 105 |
spec: |
| 106 |
replicas: 1 |
| 107 |
selector: |
| 108 |
matchLabels: |
| 109 |
app: test |
| 110 |
notIn: arrays |
| 111 |
serviceName: test |
| 112 |
template: |
| 113 |
metadata: |
| 114 |
labels: |
| 115 |
app: test |
| 116 |
notIn: arrays |
| 117 |
spec: |
| 118 |
containers: |
| 119 |
- image: registry.k8s.io/nginx-slim:0.8 |
| 120 |
name: nginx |
| 121 |
ports: |
| 122 |
- containerPort: 80 |
| 123 |
name: web |
| 124 |
--- |
| 125 |
apiVersion: apps/v1 |
| 126 |
kind: StatefulSet |
| 127 |
metadata: |
| 128 |
labels: |
| 129 |
notIn: arrays |
| 130 |
name: persisted-test |
| 131 |
spec: |
| 132 |
replicas: 1 |
| 133 |
selector: |
| 134 |
matchLabels: |
| 135 |
app: test |
| 136 |
notIn: arrays |
| 137 |
serviceName: test |
| 138 |
template: |
| 139 |
metadata: |
| 140 |
labels: |
| 141 |
app: test |
| 142 |
notIn: arrays |
| 143 |
spec: |
| 144 |
containers: |
| 145 |
- image: registry.k8s.io/nginx-slim:0.8 |
| 146 |
name: nginx |
| 147 |
ports: |
| 148 |
- containerPort: 80 |
| 149 |
name: web |
| 150 |
volumeMounts: |
| 151 |
- mountPath: /usr/share/nginx/html |
| 152 |
name: www |
| 153 |
- mountPath: /usr/share/nginx/data |
| 154 |
name: data |
| 155 |
volumeClaimTemplates: |
| 156 |
- metadata: |
| 157 |
labels: |
| 158 |
notIn: arrays |
| 159 |
name: www |
| 160 |
spec: |
| 161 |
accessModes: |
| 162 |
- ReadWriteOnce |
| 163 |
resources: |
| 164 |
requests: |
| 165 |
storage: 1Gi |
| 166 |
storageClassName: my-storage-class |
| 167 |
- metadata: |
| 168 |
labels: |
| 169 |
notIn: arrays |
| 170 |
name: data |
| 171 |
spec: |
| 172 |
accessModes: |
| 173 |
- ReadWriteOnce |
| 174 |
resources: |
| 175 |
requests: |
| 176 |
storage: 100Gi |
| 177 |
storageClassName: my-storage-class |
| 178 |
`) |
| 179 |
} |