Skip to content

Commit

Permalink
Fix usage of default function for service type and fix usage of Jobs …
Browse files Browse the repository at this point in the history
…and StatefulSets
  • Loading branch information
danduk82 authored Jan 8, 2024
1 parent 7eb50fb commit f1b50fd
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 67 deletions.
22 changes: 13 additions & 9 deletions templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{{- range $serviceName, $serviceDefinition := .Values.services }}
{{- if eq $serviceDefinition.enabled true }}
---
{{- if eq ( default "Deployment" $serviceDefinition.type ) "Job" }}
apiVersion: batch/v1
{{- else }}
apiVersion: apps/v1
kind: {{ ( default $serviceDefinition.type "Deployment" ) }}
{{- end }}
kind: {{ $serviceDefinition.type | default "Deployment" }}
metadata:
name: {{ include "common.fullname" ( dict "root" $ "service" $serviceDefinition "serviceName" $serviceName ) }}
{{- include "common.metadata" ( dict "root" $ "service" $serviceDefinition "serviceName" $serviceName ) | nindent 2 }}
spec:
{{- if eq ( default $serviceDefinition.type "Deployment" ) "Deployment" }}
{{- if eq ( default "Deployment" $serviceDefinition.type ) "Deployment" }}
{{- if $serviceDefinition.replicaCount }}
replicas: {{ $serviceDefinition.replicaCount }}
{{- end }}
Expand All @@ -32,7 +36,7 @@ spec:
selector:
matchLabels: {{- include "common.selectorLabels" ( dict "root" $ "service" $serviceDefinition "serviceName" $serviceName ) | nindent 6 }}
{{- end }}
{{- if eq ( default $serviceDefinition.type "Deployment" ) "StatefulSet" }}
{{- if eq ( default "Deployment" $serviceDefinition.type ) "StatefulSet" }}
{{- if $serviceDefinition.serviceName }}
serviceName: {{ $serviceDefinition.serviceName }}
{{- end }}
Expand All @@ -49,12 +53,12 @@ spec:
podManagementPolicy: {{ $serviceDefinition.podManagementPolicy }}
{{- end }}
{{- if $serviceDefinition.ordinals }}
ordinals: {{ $serviceDefinition.ordinals }}
ordinals: {{ toYaml $serviceDefinition.ordinals | nindent 6 }}
{{- end }}
selector:
matchLabels: {{- include "common.selectorLabels" ( dict "root" $ "service" $serviceDefinition "serviceName" $serviceName ) | nindent 6 }}
{{- with $serviceDefinition.persistentVolumeClaimRetentionPolicy }}
persistentVolumeClaimRetentionPolicy: {{ . }}
persistentVolumeClaimRetentionPolicy: {{ toYaml . | nindent 6 }}
{{- end }}
{{- with $serviceDefinition.updateStrategy }}
updateStrategy: {{ toYaml . | nindent 6 }}
Expand All @@ -63,7 +67,7 @@ spec:
volumeClaimTemplates: {{ toYaml . | nindent 6 }}
{{- end }}
{{- end }}
{{- if eq ( default $serviceDefinition.type "Deployment" ) "Job" }}
{{- if eq ( default "Deployment" $serviceDefinition.type ) "Job" }}
{{- if $serviceDefinition.backoffLimit }}
backoffLimit: {{ $serviceDefinition.backoffLimit }}
{{- end }}
Expand Down Expand Up @@ -97,14 +101,14 @@ spec:
{{- with $serviceDefinition.podFailurePolicy }}
podFailurePolicy: {{ toYaml . | nindent 6 }}
{{- end }}
{{- with $serviceDefinition.selector }}
selector: {{ toYaml . | nindent 6 }}
{{- end }}
{{- end }}
template:
metadata: {{- include "common.podMetadata" ( dict "root" $ "service" $serviceDefinition "serviceName" $serviceName ) | nindent 6 }}
spec:
{{- include "common.podConfig" ( dict "root" $ "service" $serviceDefinition "serviceName" $serviceName ) | nindent 6 }}
{{- with $serviceDefinition.restartPolicy }}
restartPolicy: {{ . }}
{{- end }}
{{- if and (hasKey $serviceDefinition "initContainers") ($serviceDefinition.initContainers) }}
initContainers:
{{- range $name, $config := $serviceDefinition.initContainers }}
Expand Down
106 changes: 62 additions & 44 deletions tests/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -745,31 +745,51 @@ spec:
---
# Source: custom-pod/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
metadata:
name: custom-custom-pod-job-all
name: custom-custom-pod-nginx
labels:
helm.sh/chart: custom-pod
app.kubernetes.io/version: "1.0"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: job-all
app.kubernetes.io/component: nginx
spec:
revisionHistoryLimit: 3
strategy:
type: RollingUpdate
serviceName: nginx
replicas: 3
minReadySeconds: 10
podManagementPolicy: Parallel
ordinals:
start: 0
selector:
matchLabels:
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: job-all
app.kubernetes.io/component: nginx
persistentVolumeClaimRetentionPolicy:
whenDeleted: Retain
whenScaled: Delete
updateStrategy:
rollingUpdate:
partition: 0
type: RollingUpdate
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: my-storage-class
template:
metadata:
labels:
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: job-all
app.kubernetes.io/component: nginx
spec:
serviceAccountName: default
securityContext:
Expand All @@ -789,31 +809,28 @@ spec:
---
# Source: custom-pod/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
metadata:
name: custom-custom-pod-job-min
name: custom-custom-pod-statefulset-min
labels:
helm.sh/chart: custom-pod
app.kubernetes.io/version: "1.0"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: job-min
app.kubernetes.io/component: statefulset-min
spec:
revisionHistoryLimit: 3
strategy:
type: RollingUpdate
selector:
matchLabels:
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: job-min
app.kubernetes.io/component: statefulset-min
template:
metadata:
labels:
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: job-min
app.kubernetes.io/component: statefulset-min
spec:
serviceAccountName: default
securityContext:
Expand All @@ -832,40 +849,48 @@ spec:
null
---
# Source: custom-pod/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
apiVersion: batch/v1
kind: Job
metadata:
name: custom-custom-pod-nginx
name: custom-custom-pod-job-all
labels:
helm.sh/chart: custom-pod
app.kubernetes.io/version: "1.0"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: nginx
app.kubernetes.io/component: job-all
spec:
replicas: 3
revisionHistoryLimit: 3
strategy:
type: RollingUpdate
minReadySeconds: 10
selector:
matchLabels:
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: nginx
backoffLimit: 5
completions: 10
parallelism: 3
completionMode: Indexed
activeDeadlineSeconds: 600
ttlSecondsAfterFinished: 600
podFailurePolicy:
rules:
- action: FailJob
onExitCodes:
containerName: main
operator: In
values:
- 42
- action: Ignore
onPodConditions:
- type: DisruptionTarget
template:
metadata:
labels:
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: nginx
app.kubernetes.io/component: job-all
spec:
serviceAccountName: default
securityContext:
{}
affinity:
null
restartPolicy: Never
containers:
- name: main
securityContext:
Expand All @@ -878,38 +903,31 @@ spec:
null
---
# Source: custom-pod/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
apiVersion: batch/v1
kind: Job
metadata:
name: custom-custom-pod-statefulset-min
name: custom-custom-pod-job-min
labels:
helm.sh/chart: custom-pod
app.kubernetes.io/version: "1.0"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: statefulset-min
app.kubernetes.io/component: job-min
spec:
revisionHistoryLimit: 3
strategy:
type: RollingUpdate
selector:
matchLabels:
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: statefulset-min
template:
metadata:
labels:
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: statefulset-min
app.kubernetes.io/component: job-min
spec:
serviceAccountName: default
securityContext:
{}
affinity:
null
restartPolicy: Never
containers:
- name: main
securityContext:
Expand Down
16 changes: 9 additions & 7 deletions tests/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ services:
podManagementPolicy: Parallel
ordinals:
start: 0
end: 2
updateStrategy:
type: RollingUpdate
rollingUpdate:
Expand All @@ -285,6 +284,9 @@ services:
job-min:
enabled: true
type: Job
# not available in k8s <= 1.27
# podReplacementPolicy: OnFailure
restartPolicy: Never
containers:
main:
image:
Expand All @@ -298,11 +300,14 @@ services:
completions: 10
parallelism: 3
completionMode: Indexed
backoffLimitPerIndex: 1
maxFailedIndexes: 5
# not available in k8s <= 1.27
# backoffLimitPerIndex: 1
# maxFailedIndexes: 5
activeDeadlineSeconds: 600
ttlSecondsAfterFinished: 600
podReplacementPolicy: Failed
# not available in k8s <= 1.27
# podReplacementPolicy: OnFailure
restartPolicy: Never
podFailurePolicy:
rules:
- action: FailJob
Expand All @@ -314,9 +319,6 @@ services:
onPodConditions:
- type: DisruptionTarget # indicates Pod disruption
suspend: false
selector:
matchLabels:
app: nginx
containers:
main:
image:
Expand Down
4 changes: 2 additions & 2 deletions values.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@
- **`strategy`** _(object)_: The deployment strategy. Cannot contain additional properties.
- **`type`** _(string)_: The type of the strategy.
- **`rollingUpdate`** _(object)_: The rolling update strategy.
- **`selector`** _(object)_: The selector of the job.
- **`suspend`** _(boolean)_: Suspend the job.
- **`template`** _(boolean)_: Create the service keys in the self object.
- **`template`** _(boolean)_: Create the service keys in the self ConfigMap even if the service is disabled.
- **`ttlSecondsAfterFinished`** _(integer)_: The number of seconds before the job is deleted.
- **`backoffLimit`** _(integer)_: The number of backoff limit.
- **`podReplacementPolicy`** _(string)_: The Pod replacement policy.
- **`restartPolicy`** _(string)_: The Pod restart policy.
- **`podFailurePolicy`** _(object)_: The Pod failure policy.
- **`activeDeadlineSeconds`** _(integer)_: The number of seconds before the job is deleted.
- **`ordinals`** _(object)_: The ordinals of the stateful set.
Expand Down
10 changes: 5 additions & 5 deletions values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -473,17 +473,13 @@
}
}
},
"selector": {
"type": "object",
"description": "The selector of the job"
},
"suspend": {
"type": "boolean",
"description": "Suspend the job"
},
"template": {
"type": "boolean",
"description": "Create the service keys in the self object"
"description": "Create the service keys in the self ConfigMap even if the service is disabled"
},
"ttlSecondsAfterFinished": {
"type": "integer",
Expand All @@ -497,6 +493,10 @@
"type": "string",
"description": "The Pod replacement policy"
},
"restartPolicy": {
"type": "string",
"description": "The Pod restart policy"
},
"podFailurePolicy": {
"type": "object",
"description": "The Pod failure policy"
Expand Down

0 comments on commit f1b50fd

Please sign in to comment.