diff --git a/example/k8s/tests/test_image2url_without_rolling_update.jsonnet b/example/k8s/tests/test_image2url_without_rolling_update.jsonnet new file mode 100644 index 0000000..81a75b2 --- /dev/null +++ b/example/k8s/tests/test_image2url_without_rolling_update.jsonnet @@ -0,0 +1,11 @@ +local k8s = import 'k8s.jsonnet'; + +k8s.list([ + k8s.image_to_url( + namespace='example', + name='demo', + host='demo.example.theplant-dev.com', + path='/', + withoutRollingUpdate=true + ), +]) diff --git a/jsonnetlib/k8s.jsonnet b/jsonnetlib/k8s.jsonnet index 5b305e4..ab4288c 100644 --- a/jsonnetlib/k8s.jsonnet +++ b/jsonnetlib/k8s.jsonnet @@ -334,6 +334,7 @@ cfg { maxReplicas=3, targetCPUUtilizationPercentage=75, podSpec=root.podSpec, + withoutRollingUpdate=false, ):: { apiVersion: 'v1', kind: 'List', @@ -359,6 +360,7 @@ cfg { volumes=volumes, terminationGracePeriodSeconds=terminationGracePeriodSeconds, podSpec=podSpec, + withoutRollingUpdate=withoutRollingUpdate, ), root.svc(namespace, name, port, targetPort), root.single_svc_ingress( @@ -476,6 +478,7 @@ cfg { volumes=[], terminationGracePeriodSeconds=root.terminationGracePeriodSeconds, podSpec=root.podSpec, + withoutRollingUpdate=false, ):: { local labels = { app: name }, local probe = if withoutProbe then {} @@ -534,6 +537,19 @@ cfg { }, }, }, + local strategy = if withoutRollingUpdate then { + strategy: { + type: 'Recreate', + }, + } else { + strategy: { + rollingUpdate: { + maxSurge: maxSurge, + maxUnavailable: 0, + }, + type: 'RollingUpdate', + }, + }, apiVersion: 'apps/v1', kind: 'Deployment', metadata: { @@ -543,13 +559,6 @@ cfg { }, spec: { replicas: replicas, - strategy: { - rollingUpdate: { - maxSurge: maxSurge, - maxUnavailable: 0, - }, - type: 'RollingUpdate', - }, selector: { matchLabels: labels, }, @@ -583,7 +592,7 @@ cfg { ], } + affinity + vols + imagePullSecretsRef(imagePullSecrets) + podSpec + graceShutdown, }, - }, + } + strategy, }, pdb(namespace=root.defaultNamespace, name, minAvailable=root.minAvailable):: { diff --git a/test_cases.json b/test_cases.json index 4451aa0..9f8e932 100644 --- a/test_cases.json +++ b/test_cases.json @@ -257,5 +257,18 @@ "expected": "500m" } ] + }, + { + "show_args": "./example/k8s/tests/test_image2url_without_rolling_update.jsonnet", + "asserts": [ + { + "jq_path": ".items[0].spec.strategy.type", + "expected": "Recreate" + }, + { + "jq_path": ".items[0].spec.strategy.rollingUpdate", + "expected": null + } + ] } ]