Skip to content

Commit

Permalink
chart/generic-chart syncup
Browse files Browse the repository at this point in the history
  • Loading branch information
uk-navi-ci committed Jun 17, 2024
1 parent 651dbd9 commit 4cfd32f
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 59 deletions.
69 changes: 50 additions & 19 deletions charts/generic-chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ For other templates re-use named definitions as follows:

Below are supported parameters.

## Test chart

Test chart based on generic-chart is located in resources.

Chart is tested using [pipeline](https://gitlab.2gis.ru/traffic/cicd-pipelines/-/blob/master/pipelines/single-chart.yml). See `.gitlab-ci.yml`.

### Values

#### Common settings
Expand All @@ -47,23 +53,25 @@ Below are supported parameters.
| `nameOverride` | Base name to use in all the Kubernetes entities deployed by this chart. | `""` |
| `fullnameOverride` | Base fullname to use in all the Kubernetes entities deployed by this chart. | `""` |

#### Deployment settings

| Name | Description | Value |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ----- |
| `labels` | Custom labels to set to Deployment resource | `{}` |
| `annotations` | Custom annotations to set to Deployment resource | `{}` |
| `replicaCount` | A replica count for the pod | `1` |
| `revisionHistoryLimit` | Number of replica sets to keep for deployment rollbacks | `1` |
| `strategy` | Deployment [strategy](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy). Undergoes template rendering | `{}` |
| `podAnnotations` | Kubernetes [pod annotations](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/) | `{}` |
| `imagePullSecrets` | Kubernetes image pull secrets | `[]` |
| `podSecurityContext` | Kubernetes [pod security context](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) | `{}` |
| `priorityClassName` | Kubernetes [Pod Priority](https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#priorityclass) class name | `""` |
| `terminationGracePeriodSeconds` | Maximum time allowed for graceful shutdown | `60` |
| `nodeSelector` | Kubernetes [node selectors](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector) | `{}` |
| `affinity` | Kubernetes pod [affinity settings](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity) | `{}` |
| `tolerations` | Kubernetes [tolerations](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/) settings | `[]` |
#### [Deployment](https://kubernetes.io/docs/tasks/run-application/run-stateless-application-deployment/) settings

| Name | Description | Value |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------- |
| `labels` | Custom labels to set to Deployment resource | `{}` |
| `annotations` | Custom annotations to set to Deployment resource | `{}` |
| `replicaCount` | A replica count for the pod | `1` |
| `revisionHistoryLimit` | Number of replica sets to keep for deployment rollbacks | `1` |
| `strategy` | Deployment [strategy](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy). Undergoes template rendering | `{}` |
| `podAnnotations` | Kubernetes [pod annotations](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/) | `{}` |
| `imagePullSecrets` | Kubernetes image pull secrets | `[]` |
| `podSecurityContext` | Kubernetes [pod security context](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) | `{}` |
| `priorityClassName` | Kubernetes [Pod Priority](https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#priorityclass) class name | `""` |
| `terminationGracePeriodSeconds` | Maximum time allowed for graceful shutdown | `60` |
| `nodeSelector` | Kubernetes [node selectors](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector) | `{}` |
| `affinity` | Kubernetes pod [affinity settings](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity) | `{}` |
| `tolerations` | Kubernetes [tolerations](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/) settings | `[]` |
| `enableServiceLinks` | Services injection into containers environment | `false` |
| `restartPolicy` | Kubernetes pod [restart policy](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy) | `""` |

#### Kubernetes [Horizontal Pod Autoscaling](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/) settings

Expand Down Expand Up @@ -97,7 +105,7 @@ Below are supported parameters.
| `pdb.minAvailable` | How many pods must be available after the eviction. | `""` |
| `pdb.maxUnavailable` | How many pods can be unavailable after the eviction. | `1` |

#### Service settings
#### [Service](https://kubernetes.io/docs/concepts/services-networking/service/) settings

| Name | Description | Value |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
Expand All @@ -107,10 +115,33 @@ Below are supported parameters.
| `service.clusterIP` | Controls Service cluster IP allocation. Cannot be changed after resource creation. | `""` |
| `service.port` | Service port. | `80` |

#### Service account settings
#### [Service account](https://kubernetes.io/docs/concepts/security/service-accounts/) settings

| Name | Description | Value |
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ------ |
| `serviceAccount.create` | Specifies whether a service account should be created. | `true` |
| `serviceAccount.annotations` | Annotations to add to the service account. | `{}` |
| `serviceAccount.name` | The name of the service account to use. If not set and create is true, a name is generated using the fullname template. | `""` |

#### [CronJob](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/) settings

| Name | Description | Value |
| ------------------------------------ | --------------------------------------------------------------- | ------- |
| `cronJob.suspend` | Suspend execution of Jobs. | `false` |
| `cronJob.schedule` | Schedule follows the Cron syntax. | `""` |
| `cronJob.startingDeadlineSeconds` | Defines a deadline (in whole seconds) for starting the Job. | `""` |
| `cronJob.concurrencyPolicy` | Concurrent executions of a Job that is created by this CronJob. | `""` |
| `cronJob.successfulJobsHistoryLimit` | How many completed Jobs should be kept. | `""` |
| `cronJob.failedJobsHistoryLimit` | How many failed Jobs should be kept. | `""` |

#### [Job](https://kubernetes.io/docs/concepts/workloads/controllers/job/) settings

| Name | Description | Value |
| -------------------------- | ----------------------------------------------------------------------------------------------------------------- | ----- |
| `job.backoffLimit` | Number of retries before considering a Job as failed. | `""` |
| `job.backoffLimitPerIndex` | Maximal number of pod failures per index. | `""` |
| `job.podFailurePolicy` | Pod failure policy. | `""` |
| `job.completions` | Number of successful pods for completion Job. | `""` |
| `job.completionMode` | Completion mode (NonIndexed or Indexed). | `""` |
| `job.parallelism` | Number of pods running at any instant. | `""` |
| `job.restartPolicy` | Kubernetes pod [restart policy](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy) | `""` |
34 changes: 34 additions & 0 deletions charts/generic-chart/templates/_cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{- define "generic-chart.cronjob.tpl" }}
{{ $ctx := .ctx }}
{{ $cronJob := .cronJob }}
apiVersion: {{ include "generic-chart.capabilities.cronjob.apiVersion" $ctx }}
kind: CronJob
metadata:
name: {{ include "generic-chart.fullname" $ctx }}{{ include "generic-chart.getSuffix" $cronJob }}
labels:
{{- include "generic-chart.labels" $ctx | nindent 4 }}
{{- with $ctx.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}{{- /* labels */}}
{{- with $ctx.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}{{- /* annotations */}}
spec:
schedule: {{ required "A valid cronJob.schedule entry required" $cronJob.schedule | quote }}
suspend: {{ ($cronJob).suspend }}
{{- if ($cronJob).startingDeadlineSeconds }}
startingDeadlineSeconds: {{ ($cronJob).startingDeadlineSeconds }}
{{- end }}
{{- if ($cronJob).concurrencyPolicy }}
concurrencyPolicy: {{ ($cronJob).concurrencyPolicy }}
{{- end }}
{{- if ($cronJob).successfulJobsHistoryLimit }}
successfulJobsHistoryLimit: {{ ($cronJob).successfulJobsHistoryLimit }}
{{- end }}
{{- if ($cronJob).failedJobsHistoryLimit }}
failedJobsHistoryLimit: {{ ($cronJob).failedJobsHistoryLimit }}
{{- end }}
jobTemplate:
{{- include "generic-chart.job_spec.tpl" . | nindent 4 }}
{{- end }}
39 changes: 4 additions & 35 deletions charts/generic-chart/templates/_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,8 @@ spec:
matchLabels:
{{- include "generic-chart.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}{{- /* podAnnotations */}}
labels:
{{- include "generic-chart.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}{{- /* imagePullSecrets */}}
serviceAccountName: {{ include "generic-chart.serviceAccountName" . }}
{{- with .Values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}{{- /* podSecurityContext */}}
{{- with .Values.priorityClassName }}
priorityClassName: {{ . }}
{{- end }}{{- /* priorityClassName */}}
{{- with .Values.terminationGracePeriodSeconds }}
terminationGracePeriodSeconds: {{ . | default 60 }}
{{- end }}{{- /* terminationGracePeriodSeconds */}}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}{{- /* nodeSelector */}}
{{- if .Values.affinity }}
affinity:
{{- include "tplvalues.render" ( dict "value" .Values.affinity "context" . ) | nindent 8 }}
{{- end }}{{- /* affinity */}}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}{{- /* tolerations */}}
{{ include "generic-chart.pod_spec.tpl" . | nindent 4 }}
{{- with .Values.restartPolicy }}
restartPolicy: {{ . }}
{{- end }}{{- /* restartPolicy */}}
{{- end }} {{- /* define */}}
22 changes: 21 additions & 1 deletion charts/generic-chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Usage:
"value" .Values.vpa.containerName
"context" .) }}
{{- else }}
{{- .Chart.Name }}
{{- .Chart.Name | replace "_" "-" }}
{{- end }}
{{- end -}}

Expand Down Expand Up @@ -145,3 +145,23 @@ containerResource:
container: {{ include "generic-chart.containerName" . }}
{{- end -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for cronjob.
*/}}
{{- define "generic-chart.capabilities.cronjob.apiVersion" -}}
{{- if semverCompare "<1.21-0" (include "generic-chart.capabilities.kubeVersion" .) -}}
{{- print "batch/v1beta1" -}}
{{- else -}}
{{- print "batch/v1" -}}
{{- end -}}
{{- end -}}

{{/*
Return the suffix from .suffix.
*/}}
{{- define "generic-chart.getSuffix" -}}
{{- if .suffix -}}
{{- printf "-%s" (toString .suffix) -}}
{{- end -}}
{{- end -}}
18 changes: 18 additions & 0 deletions charts/generic-chart/templates/_job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- define "generic-chart.job.tpl" -}}
{{ $ctx := .ctx }}
{{ $job := .job }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "generic-chart.fullname" $ctx }}{{ include "generic-chart.getSuffix" $job }}
labels:
{{- include "generic-chart.labels" $ctx | nindent 4 }}
{{- with $ctx.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}{{- /* labels */}}
{{- with $ctx.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}{{- /* annotations */}}
{{ include "generic-chart.job_spec.tpl" . }}
{{- end }}
28 changes: 28 additions & 0 deletions charts/generic-chart/templates/_job_spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- define "generic-chart.job_spec.tpl" -}}
{{ $ctx := .ctx }}
{{ $job := .job }}
spec:
{{- if ($job).backoffLimit }}
backoffLimit: {{ ($job).backoffLimit }}
{{- end }}
{{- if ($job).backoffLimitPerIndex }}
backoffLimitPerIndex: {{ ($job).backoffLimitPerIndex }}
{{- end }}
{{- if ($job).podFailurePolicy }}
podFailurePolicy: {{ ($job).podFailurePolicy }}
{{- end }}
{{- if ($job).completions }}
completions: {{ ($job).completions }}
{{- end }}
{{- if ($job).completionMode }}
completionMode: {{ ($job).completionMode }}
{{- end }}
{{- if ($job).parallelism }}
parallelism: {{ ($job).parallelism }}
{{- end }}
template:
{{- include "generic-chart.pod_spec.tpl" $ctx | nindent 4 }}
{{- with ($job).restartPolicy }}
restartPolicy: {{ . }}
{{- end }}{{- /* restartPolicy */}}
{{- end }}
43 changes: 43 additions & 0 deletions charts/generic-chart/templates/_pod_spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- define "generic-chart.pod_spec.tpl" -}}
{{- /*
apiVersion: v1
kind: Pod
metadata:
*/ -}}
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}{{- /* podAnnotations */}}
labels:
{{- include "generic-chart.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}{{- /* imagePullSecrets */}}
serviceAccountName: {{ include "generic-chart.serviceAccountName" . }}
{{- with .Values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}{{- /* podSecurityContext */}}
{{- with .Values.priorityClassName }}
priorityClassName: {{ . }}
{{- end }}{{- /* priorityClassName */}}
{{- with .Values.terminationGracePeriodSeconds }}
terminationGracePeriodSeconds: {{ . | default 60 }}
{{- end }}{{- /* terminationGracePeriodSeconds */}}
enableServiceLinks: {{ .Values.enableServiceLinks | default false }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}{{- /* nodeSelector */}}
{{- if .Values.affinity }}
affinity:
{{- include "tplvalues.render" ( dict "value" .Values.affinity "context" . ) | nindent 8 }}
{{- end }}{{- /* affinity */}}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}{{- /* tolerations */}}
{{- end }} {{- /* define */}}
Loading

0 comments on commit 4cfd32f

Please sign in to comment.