@@ -114,35 +114,12 @@ func TestInstanceConfigMap(t *testing.T) {
114
114
func TestInstancePod (t * testing.T ) {
115
115
t .Parallel ()
116
116
117
- cluster := new (v1beta1.PostgresCluster )
118
- err := cluster .Default (context .Background (), nil )
119
- assert .NilError (t , err )
120
- cluster .Name = "some-such"
121
- cluster .Spec .PostgresVersion = 11
122
- cluster .Spec .Image = "image"
123
- cluster .Spec .ImagePullPolicy = corev1 .PullAlways
124
- clusterConfigMap := new (corev1.ConfigMap )
125
- clusterPodService := new (corev1.Service )
126
- instanceCertificates := new (corev1.Secret )
127
- instanceConfigMap := new (corev1.ConfigMap )
128
- instanceSpec := new (v1beta1.PostgresInstanceSetSpec )
129
- patroniLeaderService := new (corev1.Service )
130
- template := new (corev1.PodTemplateSpec )
131
- template .Spec .Containers = []corev1.Container {{Name : "database" }}
132
-
133
- call := func () error {
134
- return InstancePod (context .Background (),
135
- cluster , clusterConfigMap , clusterPodService , patroniLeaderService ,
136
- instanceSpec , instanceCertificates , instanceConfigMap , template )
137
- }
138
-
139
- assert .NilError (t , call ())
140
-
141
- assert .DeepEqual (t , template .ObjectMeta , metav1.ObjectMeta {
142
- Labels : map [string ]string {naming .LabelPatroni : "some-such-ha" },
143
- })
144
-
145
- assert .Assert (t , cmp .MarshalMatches (template .Spec , `
117
+ tests := map [string ]struct {
118
+ expectedSpec string
119
+ labels map [string ]string
120
+ }{
121
+ "version >=2.7.0 specified" : {
122
+ expectedSpec : `
146
123
containers:
147
124
- command:
148
125
- patroni
@@ -221,7 +198,127 @@ volumes:
221
198
path: ~postgres-operator/patroni.ca-roots
222
199
- key: patroni.crt-combined
223
200
path: ~postgres-operator/patroni.crt+key
224
- ` ))
201
+ ` ,
202
+ labels : map [string ]string {
203
+ "pgv2.percona.com/version" : "2.7.0" ,
204
+ },
205
+ },
206
+ "version <2.7.0 specified" : {
207
+ labels : map [string ]string {
208
+ "pgv2.percona.com/version" : "2.6.0" ,
209
+ },
210
+ expectedSpec : `
211
+ containers:
212
+ - command:
213
+ - patroni
214
+ - /etc/patroni
215
+ env:
216
+ - name: PATRONI_NAME
217
+ valueFrom:
218
+ fieldRef:
219
+ apiVersion: v1
220
+ fieldPath: metadata.name
221
+ - name: PATRONI_KUBERNETES_POD_IP
222
+ valueFrom:
223
+ fieldRef:
224
+ apiVersion: v1
225
+ fieldPath: status.podIP
226
+ - name: PATRONI_KUBERNETES_PORTS
227
+ value: |
228
+ []
229
+ - name: PATRONI_POSTGRESQL_CONNECT_ADDRESS
230
+ value: $(PATRONI_NAME).:5432
231
+ - name: PATRONI_POSTGRESQL_LISTEN
232
+ value: '*:5432'
233
+ - name: PATRONI_POSTGRESQL_CONFIG_DIR
234
+ value: /pgdata/pg11
235
+ - name: PATRONI_POSTGRESQL_DATA_DIR
236
+ value: /pgdata/pg11
237
+ - name: PATRONI_RESTAPI_CONNECT_ADDRESS
238
+ value: $(PATRONI_NAME).:8008
239
+ - name: PATRONI_RESTAPI_LISTEN
240
+ value: '*:8008'
241
+ - name: PATRONICTL_CONFIG_FILE
242
+ value: /etc/patroni
243
+ livenessProbe:
244
+ failureThreshold: 3
245
+ httpGet:
246
+ path: /liveness
247
+ port: 8008
248
+ scheme: HTTPS
249
+ initialDelaySeconds: 3
250
+ periodSeconds: 10
251
+ successThreshold: 1
252
+ timeoutSeconds: 5
253
+ name: database
254
+ readinessProbe:
255
+ failureThreshold: 3
256
+ httpGet:
257
+ path: /readiness
258
+ port: 8008
259
+ scheme: HTTPS
260
+ initialDelaySeconds: 3
261
+ periodSeconds: 10
262
+ successThreshold: 1
263
+ timeoutSeconds: 5
264
+ resources: {}
265
+ volumeMounts:
266
+ - mountPath: /etc/patroni
267
+ name: patroni-config
268
+ readOnly: true
269
+ volumes:
270
+ - name: patroni-config
271
+ projected:
272
+ sources:
273
+ - configMap:
274
+ items:
275
+ - key: patroni.yaml
276
+ path: ~postgres-operator_cluster.yaml
277
+ - configMap:
278
+ items:
279
+ - key: patroni.yaml
280
+ path: ~postgres-operator_instance.yaml
281
+ - secret:
282
+ items:
283
+ - key: patroni.ca-roots
284
+ path: ~postgres-operator/patroni.ca-roots
285
+ - key: patroni.crt-combined
286
+ path: ~postgres-operator/patroni.crt+key
287
+ ` ,
288
+ },
289
+ }
290
+ for name , tt := range tests {
291
+ t .Run (name , func (t * testing.T ) {
292
+ cluster := new (v1beta1.PostgresCluster )
293
+ err := cluster .Default (context .Background (), nil )
294
+ assert .NilError (t , err )
295
+ cluster .Name = "some-such"
296
+ cluster .Spec .PostgresVersion = 11
297
+ cluster .Spec .Image = "image"
298
+ cluster .Spec .ImagePullPolicy = corev1 .PullAlways
299
+ clusterConfigMap := new (corev1.ConfigMap )
300
+ clusterPodService := new (corev1.Service )
301
+ instanceCertificates := new (corev1.Secret )
302
+ instanceConfigMap := new (corev1.ConfigMap )
303
+ instanceSpec := new (v1beta1.PostgresInstanceSetSpec )
304
+ patroniLeaderService := new (corev1.Service )
305
+ template := new (corev1.PodTemplateSpec )
306
+ template .Spec .Containers = []corev1.Container {{Name : "database" }}
307
+ cluster .Labels = tt .labels
308
+
309
+ call := func () error {
310
+ return InstancePod (context .Background (),
311
+ cluster , clusterConfigMap , clusterPodService , patroniLeaderService ,
312
+ instanceSpec , instanceCertificates , instanceConfigMap , template )
313
+ }
314
+ assert .NilError (t , call ())
315
+
316
+ assert .DeepEqual (t , template .ObjectMeta , metav1.ObjectMeta {
317
+ Labels : map [string ]string {naming .LabelPatroni : "some-such-ha" },
318
+ })
319
+ assert .Assert (t , cmp .MarshalMatches (template .Spec , tt .expectedSpec ))
320
+ })
321
+ }
225
322
}
226
323
227
324
func TestPodIsPrimary (t * testing.T ) {
0 commit comments