diff --git a/library/common-test/tests/daemonset/spec_test.yaml b/library/common-test/tests/daemonset/spec_test.yaml index 28aac14cda..6117291865 100644 --- a/library/common-test/tests/daemonset/spec_test.yaml +++ b/library/common-test/tests/daemonset/spec_test.yaml @@ -24,30 +24,6 @@ tests: revisionHistoryLimit: 3 updateStrategy: type: RollingUpdate - rollingUpdate: - maxSurge: 0 - maxUnavailable: 1 - - - it: should apply defaults to rollingUpdate - set: - workload: - workload-name: - enabled: true - primary: true - type: DaemonSet - replicas: 2 - revisionHistoryLimit: 4 - strategy: RollingUpdate - podSpec: {} - asserts: - - documentIndex: *daemonSetDoc - isSubset: - path: spec.updateStrategy - content: - type: RollingUpdate - rollingUpdate: - maxSurge: 0 - maxUnavailable: 1 - it: should apply spec correctly set: @@ -73,3 +49,45 @@ tests: rollingUpdate: maxSurge: 5 maxUnavailable: 5 + + - it: should apply maxSurge with 0 + set: + workload: + workload-name: + enabled: true + primary: true + type: DaemonSet + strategy: RollingUpdate + rollingUpdate: + maxSurge: 0 + podSpec: {} + asserts: + - documentIndex: *daemonSetDoc + isSubset: + path: spec + content: + updateStrategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 0 + + - it: should apply maxUnavailable with 0 + set: + workload: + workload-name: + enabled: true + primary: true + type: DaemonSet + strategy: RollingUpdate + rollingUpdate: + maxUnavailable: 0 + podSpec: {} + asserts: + - documentIndex: *daemonSetDoc + isSubset: + path: spec + content: + updateStrategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 0 diff --git a/library/common-test/tests/daemonset/validation_test.yaml b/library/common-test/tests/daemonset/validation_test.yaml index 51279882f4..aa80c7e94f 100644 --- a/library/common-test/tests/daemonset/validation_test.yaml +++ b/library/common-test/tests/daemonset/validation_test.yaml @@ -28,22 +28,3 @@ tests: asserts: - failedTemplate: errorMessage: DaemonSet - Expected to be a dictionary, but got [string] - - - it: should fail with both maxSurge and maxUnavailable set to 0 - set: - fallbackDefaults: - maxSurge: 0 - maxUnavailable: 0 - workload: - workload-name: - enabled: true - primary: true - type: DaemonSet - strategy: RollingUpdate - rollingUpdate: - maxSurge: 0 - maxUnavailable: 0 - podSpec: {} - asserts: - - failedTemplate: - errorMessage: DaemonSet - Cannot have and both set to 0 diff --git a/library/common-test/tests/deployment/spec_test.yaml b/library/common-test/tests/deployment/spec_test.yaml index 40d5b04ce0..d525cce779 100644 --- a/library/common-test/tests/deployment/spec_test.yaml +++ b/library/common-test/tests/deployment/spec_test.yaml @@ -26,27 +26,6 @@ tests: strategy: type: Recreate - - it: should apply defaults to rollingUpdate - set: - workload: - workload-name: - enabled: true - primary: true - type: Deployment - replicas: 2 - revisionHistoryLimit: 4 - strategy: RollingUpdate - podSpec: {} - asserts: - - documentIndex: *deploymentDoc - isSubset: - path: spec.strategy - content: - type: RollingUpdate - rollingUpdate: - maxSurge: 0 - maxUnavailable: 1 - - it: should apply spec correctly set: workload: @@ -73,3 +52,45 @@ tests: rollingUpdate: maxSurge: 5 maxUnavailable: 5 + + - it: should apply maxSurge with 0 + set: + workload: + workload-name: + enabled: true + primary: true + type: Deployment + strategy: RollingUpdate + rollingUpdate: + maxSurge: 0 + podSpec: {} + asserts: + - documentIndex: *deploymentDoc + isSubset: + path: spec + content: + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 0 + + - it: should apply maxUnavailable with 0 + set: + workload: + workload-name: + enabled: true + primary: true + type: Deployment + strategy: RollingUpdate + rollingUpdate: + maxUnavailable: 0 + podSpec: {} + asserts: + - documentIndex: *deploymentDoc + isSubset: + path: spec + content: + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 0 diff --git a/library/common-test/tests/deployment/validation_test.yaml b/library/common-test/tests/deployment/validation_test.yaml index 9364238159..2d08f3cc50 100644 --- a/library/common-test/tests/deployment/validation_test.yaml +++ b/library/common-test/tests/deployment/validation_test.yaml @@ -28,22 +28,3 @@ tests: asserts: - failedTemplate: errorMessage: Deployment - Expected to be a dictionary, but got [string] - - - it: should fail with both maxSurge and maxUnavailable set to 0 - set: - fallbackDefaults: - maxSurge: 0 - maxUnavailable: 0 - workload: - workload-name: - enabled: true - primary: true - type: Deployment - strategy: RollingUpdate - rollingUpdate: - maxSurge: 0 - maxUnavailable: 0 - podSpec: {} - asserts: - - failedTemplate: - errorMessage: Deployment - Cannot have and both set to 0 diff --git a/library/common-test/tests/statefulset/spec_test.yaml b/library/common-test/tests/statefulset/spec_test.yaml index be25bdbc07..575a15c244 100644 --- a/library/common-test/tests/statefulset/spec_test.yaml +++ b/library/common-test/tests/statefulset/spec_test.yaml @@ -24,30 +24,6 @@ tests: revisionHistoryLimit: 3 updateStrategy: type: RollingUpdate - rollingUpdate: - maxUnavailable: 1 - partition: 1 - - - it: should apply defaults to rollingUpdate - set: - workload: - workload-name: - enabled: true - primary: true - type: StatefulSet - replicas: 2 - revisionHistoryLimit: 4 - strategy: RollingUpdate - podSpec: {} - asserts: - - documentIndex: *statefulSetDoc - isSubset: - path: spec.updateStrategy - content: - type: RollingUpdate - rollingUpdate: - maxUnavailable: 1 - partition: 1 - it: should apply spec correctly set: @@ -73,3 +49,45 @@ tests: rollingUpdate: partition: 5 maxUnavailable: 5 + + - it: should apply partition with 0 + set: + workload: + workload-name: + enabled: true + primary: true + type: StatefulSet + strategy: RollingUpdate + rollingUpdate: + partition: 0 + podSpec: {} + asserts: + - documentIndex: *statefulSetDoc + isSubset: + path: spec + content: + updateStrategy: + type: RollingUpdate + rollingUpdate: + partition: 0 + + - it: should apply maxUnavailable with 0 + set: + workload: + workload-name: + enabled: true + primary: true + type: StatefulSet + strategy: RollingUpdate + rollingUpdate: + maxUnavailable: 0 + podSpec: {} + asserts: + - documentIndex: *statefulSetDoc + isSubset: + path: spec + content: + updateStrategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 0 diff --git a/library/common/1.0.0/templates/lib/workload/_daemonsetSpec.tpl b/library/common/1.0.0/templates/lib/workload/_daemonsetSpec.tpl index 8afe519b53..feb4502d1d 100644 --- a/library/common/1.0.0/templates/lib/workload/_daemonsetSpec.tpl +++ b/library/common/1.0.0/templates/lib/workload/_daemonsetSpec.tpl @@ -14,17 +14,16 @@ objectData: revisionHistoryLimit: {{ $objectData.revisionHistoryLimit | default 3 }} updateStrategy: type: {{ $strategy }} - {{- if eq $strategy "RollingUpdate" }} - {{- if not $objectData.rollingUpdate -}} {{/* Create the key if it does not exist, to avoid nil pointers */}} - {{- $_ := set $objectData "rollingUpdate" dict -}} - {{- end }} + {{- if and + (eq $objectData.strategy "RollingUpdate") + $objectData.rollingUpdate + (or (hasKey $objectData.rollingUpdate "maxUnavailable") (hasKey $objectData.rollingUpdate "maxSurge")) }} rollingUpdate: - {{- $maxSurge := $objectData.rollingUpdate.maxSurge | default $rootCtx.Values.fallbackDefaults.maxSurge -}} - {{- $maxUnavailable := $objectData.rollingUpdate.maxUnavailable | default $rootCtx.Values.fallbackDefaults.maxUnavailable -}} - {{- if and (eq (int $maxSurge) 0) (eq (int $maxUnavailable) 0) -}} - {{- fail "DaemonSet - Cannot have and both set to 0" -}} - {{- end }} - maxUnavailable: {{ $maxUnavailable }} - maxSurge: {{ $maxSurge }} + {{- if hasKey $objectData.rollingUpdate "maxUnavailable" }} + maxUnavailable: {{ $objectData.rollingUpdate.maxUnavailable }} + {{- end -}} + {{- if hasKey $objectData.rollingUpdate "maxSurge" }} + maxSurge: {{ $objectData.rollingUpdate.maxSurge }} + {{- end -}} {{- end -}} {{- end -}} diff --git a/library/common/1.0.0/templates/lib/workload/_deployementSpec.tpl b/library/common/1.0.0/templates/lib/workload/_deployementSpec.tpl index 87a7e55e4e..6d6862cda1 100644 --- a/library/common/1.0.0/templates/lib/workload/_deployementSpec.tpl +++ b/library/common/1.0.0/templates/lib/workload/_deployementSpec.tpl @@ -15,17 +15,16 @@ replicas: {{ $objectData.replicas | default 1 }} revisionHistoryLimit: {{ $objectData.revisionHistoryLimit | default 3 }} strategy: type: {{ $strategy }} - {{- if eq $strategy "RollingUpdate" }} - {{- if not $objectData.rollingUpdate -}} {{/* Create the key if it does not exist, to avoid nil pointers */}} - {{- $_ := set $objectData "rollingUpdate" dict -}} - {{- end }} + {{- if and + (eq $objectData.strategy "RollingUpdate") + $objectData.rollingUpdate + (or (hasKey $objectData.rollingUpdate "maxUnavailable") (hasKey $objectData.rollingUpdate "partition")) }} rollingUpdate: - {{- $maxSurge := $objectData.rollingUpdate.maxSurge | default $rootCtx.Values.fallbackDefaults.maxSurge -}} - {{- $maxUnavailable := $objectData.rollingUpdate.maxUnavailable | default $rootCtx.Values.fallbackDefaults.maxUnavailable -}} - {{- if and (eq (int $maxSurge) 0) (eq (int $maxUnavailable) 0) -}} - {{- fail "Deployment - Cannot have and both set to 0" -}} - {{- end }} - maxUnavailable: {{ $maxUnavailable }} - maxSurge: {{ $maxSurge }} + {{- if hasKey $objectData.rollingUpdate "maxUnavailable" }} + maxUnavailable: {{ $objectData.rollingUpdate.maxUnavailable }} + {{- end -}} + {{- if hasKey $objectData.rollingUpdate "maxSurge" }} + maxSurge: {{ $objectData.rollingUpdate.maxSurge }} + {{- end -}} {{- end -}} {{- end -}} diff --git a/library/common/1.0.0/templates/lib/workload/_statefulsettSpec.tpl b/library/common/1.0.0/templates/lib/workload/_statefulsettSpec.tpl index 505b26bf6f..99e1307f86 100644 --- a/library/common/1.0.0/templates/lib/workload/_statefulsettSpec.tpl +++ b/library/common/1.0.0/templates/lib/workload/_statefulsettSpec.tpl @@ -16,12 +16,16 @@ revisionHistoryLimit: {{ $objectData.revisionHistoryLimit | default 3 }} serviceName: {{ $objectData.name }} updateStrategy: type: {{ $strategy }} - {{- if eq $strategy "RollingUpdate" }} + {{- if and + (eq $objectData.strategy "RollingUpdate") + $objectData.rollingUpdate + (or (hasKey $objectData.rollingUpdate "maxUnavailable") (hasKey $objectData.rollingUpdate "partition")) }} rollingUpdate: - {{- if not $objectData.rollingUpdate -}} {{/* Create the key if it does not exist, to avoid nil pointers */}} - {{- $_ := set $objectData "rollingUpdate" dict -}} - {{- end }} - maxUnavailable: {{ $objectData.rollingUpdate.maxUnavailable | default $rootCtx.Values.fallbackDefaults.maxUnavailable }} - partition: {{ $objectData.rollingUpdate.partition | default $rootCtx.Values.fallbackDefaults.partition }} + {{- if hasKey $objectData.rollingUpdate "maxUnavailable" }} + maxUnavailable: {{ $objectData.rollingUpdate.maxUnavailable }} + {{- end -}} + {{- if hasKey $objectData.rollingUpdate "partition" }} + partition: {{ $objectData.rollingUpdate.partition }} + {{- end -}} {{- end -}} {{- end -}} diff --git a/library/common/1.0.0/values.yaml b/library/common/1.0.0/values.yaml index 832599f9ba..d5f0fa688e 100644 --- a/library/common/1.0.0/values.yaml +++ b/library/common/1.0.0/values.yaml @@ -17,12 +17,6 @@ fallbackDefaults: # -- Define a storageClassName that will be used for all PVCs # Can be overruled per PVC storageClass: - # -- Default maxUnavailable - maxUnavailable: 1 - # -- Default maxSurge - maxSurge: 0 - # -- Default partition (StatefulSet only) - partition: 1 # -- Default probe type probeType: http # -- Default Service Protocol