From 73d592a2edea56467ce910f0267dbbdbf8fc3750 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Mon, 13 Feb 2023 14:35:36 +0200 Subject: [PATCH] rollingup defaults --- .../tests/daemonset/spec_test.yaml | 24 +++++++++++++++++++ .../tests/deployment/spec_test.yaml | 24 +++++++++++++++++++ .../tests/statefulset/spec_test.yaml | 24 +++++++++++++++++++ .../common/1.0.0/docs/workload/daemonset.md | 12 +++++----- .../common/1.0.0/docs/workload/deployment.md | 12 +++++----- .../common/1.0.0/docs/workload/statefulset.md | 12 +++++----- .../templates/lib/workload/_daemonsetSpec.tpl | 13 +++------- .../lib/workload/_deployementSpec.tpl | 13 +++------- .../lib/workload/_statefulsettSpec.tpl | 13 +++------- library/common/1.0.0/values.yaml | 6 +++++ 10 files changed, 105 insertions(+), 48 deletions(-) diff --git a/library/common-test/tests/daemonset/spec_test.yaml b/library/common-test/tests/daemonset/spec_test.yaml index fd325fc9c9..9297f894ea 100644 --- a/library/common-test/tests/daemonset/spec_test.yaml +++ b/library/common-test/tests/daemonset/spec_test.yaml @@ -25,6 +25,30 @@ tests: updateStrategy: type: RollingUpdate + - 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 + content: + replicas: 2 + revisionHistoryLimit: 4 + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + - it: should apply spec correctly set: workload: diff --git a/library/common-test/tests/deployment/spec_test.yaml b/library/common-test/tests/deployment/spec_test.yaml index c5093f5a83..bdc8db1c3d 100644 --- a/library/common-test/tests/deployment/spec_test.yaml +++ b/library/common-test/tests/deployment/spec_test.yaml @@ -26,6 +26,30 @@ 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 + content: + replicas: 2 + revisionHistoryLimit: 4 + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + - it: should apply spec correctly set: workload: diff --git a/library/common-test/tests/statefulset/spec_test.yaml b/library/common-test/tests/statefulset/spec_test.yaml index 74ae3f6976..4ced9ed59b 100644 --- a/library/common-test/tests/statefulset/spec_test.yaml +++ b/library/common-test/tests/statefulset/spec_test.yaml @@ -25,6 +25,30 @@ tests: updateStrategy: type: RollingUpdate + - 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: *statefulSetDoc + isSubset: + path: spec + content: + replicas: 2 + revisionHistoryLimit: 4 + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + partition: 1 + - it: should apply spec correctly set: workload: diff --git a/library/common/1.0.0/docs/workload/daemonset.md b/library/common/1.0.0/docs/workload/daemonset.md index df3f7a0c6b..0b84de38a0 100644 --- a/library/common/1.0.0/docs/workload/daemonset.md +++ b/library/common/1.0.0/docs/workload/daemonset.md @@ -1,11 +1,11 @@ # DaemonSet -| Key | Type | Required | Helm Template | Default | Description | -| :---------------------------------------------------- | :------: | :------: | :-----------: | :-------------: | :------------------------------------------------------------------- | -| workload.[workload-name].strategy | `string` | ❌ | ❌ | `RollingUpdate` | Define the strategy of the workload (OnDelete, RollingUpdate) | -| workload.[workload-name].rollingUpdate | `dict` | ❌ | ❌ | `{}` | Holds the rollingUpdate options, Only when strategy is RollingUpdate | -| workload.[workload-name].rollingUpdate.maxUnavailable | `int` | ❌ | ❌ | | Define the maxUnavailable, Only when strategy is RollingUpdate | -| workload.[workload-name].rollingUpdate.maxSurge | `int` | ❌ | ❌ | | Define the maxSurge, Only when strategy is RollingUpdate | +| Key | Type | Required | Helm Template | Default | Description | +| :---------------------------------------------------- | :------: | :------: | :-----------: | :---------------------------------------------: | :------------------------------------------------------------------- | +| workload.[workload-name].strategy | `string` | ❌ | ❌ | `RollingUpdate` | Define the strategy of the workload (OnDelete, RollingUpdate) | +| workload.[workload-name].rollingUpdate | `dict` | ❌ | ❌ | `{}` | Holds the rollingUpdate options, Only when strategy is RollingUpdate | +| workload.[workload-name].rollingUpdate.maxUnavailable | `int` | ❌ | ❌ | `{{ .Values.fallbackDefaults.maxUnavailable }}` | Define the maxUnavailable, Only when strategy is RollingUpdate | +| workload.[workload-name].rollingUpdate.maxSurge | `int` | ❌ | ❌ | `{{ .Values.fallbackDefaults.maxSurge }}` | Define the maxSurge, Only when strategy is RollingUpdate | --- diff --git a/library/common/1.0.0/docs/workload/deployment.md b/library/common/1.0.0/docs/workload/deployment.md index 59bb3121fb..0980ff7c48 100644 --- a/library/common/1.0.0/docs/workload/deployment.md +++ b/library/common/1.0.0/docs/workload/deployment.md @@ -1,11 +1,11 @@ # Deployment -| Key | Type | Required | Helm Template | Default | Description | -| :---------------------------------------------------- | :------: | :------: | :-----------: | :--------: | :------------------------------------------------------------------- | -| workload.[workload-name].strategy | `string` | ❌ | ❌ | `Recreate` | Define the strategy of the workload (Recreate, RollingUpdate) | -| workload.[workload-name].rollingUpdate | `dict` | ❌ | ❌ | `{}` | Holds the rollingUpdate options, Only when strategy is RollingUpdate | -| workload.[workload-name].rollingUpdate.maxUnavailable | `int` | ❌ | ❌ | | Define the maxUnavailable, Only when strategy is RollingUpdate | -| workload.[workload-name].rollingUpdate.maxSurge | `int` | ❌ | ❌ | | Define the maxSurge, Only when strategy is RollingUpdate | +| Key | Type | Required | Helm Template | Default | Description | +| :---------------------------------------------------- | :------: | :------: | :-----------: | :---------------------------------------------: | :------------------------------------------------------------------- | +| workload.[workload-name].strategy | `string` | ❌ | ❌ | `Recreate` | Define the strategy of the workload (Recreate, RollingUpdate) | +| workload.[workload-name].rollingUpdate | `dict` | ❌ | ❌ | `{}` | Holds the rollingUpdate options, Only when strategy is RollingUpdate | +| workload.[workload-name].rollingUpdate.maxUnavailable | `int` | ❌ | ❌ | `{{ .Values.fallbackDefaults.maxUnavailable }}` | Define the maxUnavailable, Only when strategy is RollingUpdate | +| workload.[workload-name].rollingUpdate.maxSurge | `int` | ❌ | ❌ | `{{ .Values.fallbackDefaults.maxSurge }}` | Define the maxSurge, Only when strategy is RollingUpdate | --- diff --git a/library/common/1.0.0/docs/workload/statefulset.md b/library/common/1.0.0/docs/workload/statefulset.md index 209a0ac692..5c9783e887 100644 --- a/library/common/1.0.0/docs/workload/statefulset.md +++ b/library/common/1.0.0/docs/workload/statefulset.md @@ -1,11 +1,11 @@ # DaemonSet -| Key | Type | Required | Helm Template | Default | Description | -| :---------------------------------------------------- | :------: | :------: | :-----------: | :-------------: | :------------------------------------------------------------------- | -| workload.[workload-name].strategy | `string` | ❌ | ❌ | `RollingUpdate` | Define the strategy of the workload (OnDelete, RollingUpdate) | -| workload.[workload-name].rollingUpdate | `dict` | ❌ | ❌ | `{}` | Holds the rollingUpdate options, Only when strategy is RollingUpdate | -| workload.[workload-name].rollingUpdate.maxUnavailable | `int` | ❌ | ❌ | | Define the maxUnavailable, Only when strategy is RollingUpdate | -| workload.[workload-name].rollingUpdate.partition | `int` | ❌ | ❌ | | Define the partition, Only when strategy is RollingUpdate | +| Key | Type | Required | Helm Template | Default | Description | +| :---------------------------------------------------- | :------: | :------: | :-----------: | :---------------------------------------------: | :------------------------------------------------------------------- | +| workload.[workload-name].strategy | `string` | ❌ | ❌ | `RollingUpdate` | Define the strategy of the workload (OnDelete, RollingUpdate) | +| workload.[workload-name].rollingUpdate | `dict` | ❌ | ❌ | `{}` | Holds the rollingUpdate options, Only when strategy is RollingUpdate | +| workload.[workload-name].rollingUpdate.maxUnavailable | `int` | ❌ | ❌ | `{{ .Values.fallbackDefaults.maxUnavailable }}` | Define the maxUnavailable, Only when strategy is RollingUpdate | +| workload.[workload-name].rollingUpdate.partition | `int` | ❌ | ❌ | `{{ .Values.fallbackDefaults.partition }}` | Define the partition, Only when strategy is RollingUpdate | --- 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 b722a3276d..c0cace1a83 100644 --- a/library/common/1.0.0/templates/lib/workload/_daemonsetSpec.tpl +++ b/library/common/1.0.0/templates/lib/workload/_daemonsetSpec.tpl @@ -13,16 +13,9 @@ objectData: revisionHistoryLimit: {{ $objectData.revisionHistoryLimit | default 3 }} updateStrategy: type: {{ $objectData.strategy | default "RollingUpdate" }} - {{- if and - (eq $objectData.strategy "RollingUpdate") - $objectData.rollingUpdate - (or $objectData.rollingUpdate.maxUnavailable $objectData.rollingUpdate.maxSurge) }} + {{- if eq $objectData.strategy "RollingUpdate" }} rollingUpdate: - {{- with $objectData.rollingUpdate.maxUnavailable }} - maxUnavailable: {{ .}} - {{- end -}} - {{- with $objectData.rollingUpdate.maxSurge }} - maxSurge: {{ . }} - {{- end -}} + maxUnavailable: {{ $objectData.rollingUpdate.maxUnavailable | default $rootCtx.Values.fallbackDefaults.maxUnavailable }} + maxSurge: {{ $objectData.rollingUpdate.maxSurge | default $rootCtx.Values.fallbackDefaults.maxSurge }} {{- 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 816dfd5dcc..75a73b0f0a 100644 --- a/library/common/1.0.0/templates/lib/workload/_deployementSpec.tpl +++ b/library/common/1.0.0/templates/lib/workload/_deployementSpec.tpl @@ -14,16 +14,9 @@ replicas: {{ $objectData.replicas | default 1 }} revisionHistoryLimit: {{ $objectData.revisionHistoryLimit | default 3 }} strategy: type: {{ $objectData.strategy | default "Recreate" }} - {{- if and - (eq $objectData.strategy "RollingUpdate") - $objectData.rollingUpdate - (or $objectData.rollingUpdate.maxUnavailable $objectData.rollingUpdate.maxSurge) }} + {{- if eq $objectData.strategy "RollingUpdate" }} rollingUpdate: - {{- with $objectData.rollingUpdate.maxUnavailable }} - maxUnavailable: {{ .}} - {{- end -}} - {{- with $objectData.rollingUpdate.maxSurge }} - maxSurge: {{ . }} - {{- end -}} + maxUnavailable: {{ $objectData.rollingUpdate.maxUnavailable | default $rootCtx.Values.fallbackDefaults.maxUnavailable }} + maxSurge: {{ $objectData.rollingUpdate.maxSurge | default $rootCtx.Values.fallbackDefaults.maxSurge }} {{- 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 364e1deaa1..8fc1494c4e 100644 --- a/library/common/1.0.0/templates/lib/workload/_statefulsettSpec.tpl +++ b/library/common/1.0.0/templates/lib/workload/_statefulsettSpec.tpl @@ -15,16 +15,9 @@ revisionHistoryLimit: {{ $objectData.revisionHistoryLimit | default 3 }} serviceName: {{ $objectData.name }} updateStrategy: type: {{ $objectData.strategy | default "RollingUpdate" }} - {{- if and - (eq $objectData.strategy "RollingUpdate") - $objectData.rollingUpdate - (or $objectData.rollingUpdate.maxUnavailable $objectData.rollingUpdate.partition) }} + {{- if eq $objectData.strategy "RollingUpdate" }} rollingUpdate: - {{- with $objectData.rollingUpdate.maxUnavailable }} - maxUnavailable: {{ .}} - {{- end -}} - {{- with $objectData.rollingUpdate.partition }} - partition: {{ . }} - {{- end -}} + maxUnavailable: {{ $objectData.rollingUpdate.maxUnavailable | default $rootCtx.Values.fallbackDefaults.maxUnavailable }} + partition: {{ $objectData.rollingUpdate.partition | default $rootCtx.Values.fallbackDefaults.partition }} {{- end -}} {{- end -}} diff --git a/library/common/1.0.0/values.yaml b/library/common/1.0.0/values.yaml index 73791fbc3a..a43f299ee9 100644 --- a/library/common/1.0.0/values.yaml +++ b/library/common/1.0.0/values.yaml @@ -17,6 +17,12 @@ fallbackDefaults: # -- Define a storageClassName that will be used for all PVCs # Can be overruled per PVC storageClass: + # -- Default maxUnavailable + maxUnavailable: 1 + # -- Default maxSurge + maxSurge: 1 + # -- Default partition (StatefulSet only) + partition: 1 # -- Default Service Protocol serviceProtocol: TCP # -- Default Service Type