From 596607b291631d862564763bc6d0f7218f669531 Mon Sep 17 00:00:00 2001 From: Rustam Tagaev Date: Mon, 2 Dec 2024 12:25:28 +0300 Subject: [PATCH 1/5] [DO-1377] rename chart --- Chart.yaml | 2 +- README.md | 14 +------------- templates/NOTES.txt | 8 ++++---- templates/_helpers.tpl | 20 ++++++++++---------- templates/deployment.yaml | 10 +++++----- templates/hpa.yaml | 6 +++--- templates/ingress.yaml | 4 ++-- templates/service.yaml | 6 +++--- templates/serviceaccount.yaml | 4 ++-- templates/tests/test-connection.yaml | 6 +++--- values.yaml | 2 +- 11 files changed, 35 insertions(+), 47 deletions(-) diff --git a/Chart.yaml b/Chart.yaml index 57dec39..bc6c4d0 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v2 -name: myHelmChart +name: openresty description: A Helm chart for Kubernetes # A chart can be either an 'application' or a 'library' chart. diff --git a/README.md b/README.md index 060a624..725fdad 100644 --- a/README.md +++ b/README.md @@ -1,13 +1 @@ -# template-helm-chart-repository - -Template for helm chart repositories - -# How-to-use - -Create repository from template - -Replace all names of chart - -``` -sed -i "s/myHelmChart/container-test-validation-server-chart/g" -``` +# OpenResty diff --git a/templates/NOTES.txt b/templates/NOTES.txt index 4487c10..7d03b48 100644 --- a/templates/NOTES.txt +++ b/templates/NOTES.txt @@ -6,16 +6,16 @@ {{- end }} {{- end }} {{- else if contains "NodePort" .Values.service.type }} - export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "myHelmChart.fullname" . }}) + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "openresty.fullname" . }}) export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT {{- else if contains "LoadBalancer" .Values.service.type }} NOTE: It may take a few minutes for the LoadBalancer IP to be available. - You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "myHelmChart.fullname" . }}' - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "myHelmChart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "openresty.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "openresty.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") echo http://$SERVICE_IP:{{ .Values.service.port }} {{- else if contains "ClusterIP" .Values.service.type }} - export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "myHelmChart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "openresty.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") echo "Visit http://127.0.0.1:8080 to use your application" kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index dbe18fc..dc159c4 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -1,7 +1,7 @@ {{/* Expand the name of the chart. */}} -{{- define "myHelmChart.name" -}} +{{- define "openresty.name" -}} {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} {{- end }} @@ -10,7 +10,7 @@ Create a default fully qualified app name. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). If release name contains chart name it will be used as a full name. */}} -{{- define "myHelmChart.fullname" -}} +{{- define "openresty.fullname" -}} {{- if .Values.fullnameOverride }} {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} {{- else }} @@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name. {{/* Create chart name and version as used by the chart label. */}} -{{- define "myHelmChart.chart" -}} +{{- define "openresty.chart" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} {{- end }} {{/* Common labels */}} -{{- define "myHelmChart.labels" -}} -helm.sh/chart: {{ include "myHelmChart.chart" . }} -{{ include "myHelmChart.selectorLabels" . }} +{{- define "openresty.labels" -}} +helm.sh/chart: {{ include "openresty.chart" . }} +{{ include "openresty.selectorLabels" . }} {{- if .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} @@ -45,17 +45,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} {{/* Selector labels */}} -{{- define "myHelmChart.selectorLabels" -}} -app.kubernetes.io/name: {{ include "myHelmChart.name" . }} +{{- define "openresty.selectorLabels" -}} +app.kubernetes.io/name: {{ include "openresty.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} {{/* Create the name of the service account to use */}} -{{- define "myHelmChart.serviceAccountName" -}} +{{- define "openresty.serviceAccountName" -}} {{- if .Values.serviceAccount.create }} -{{- default (include "myHelmChart.fullname" .) .Values.serviceAccount.name }} +{{- default (include "openresty.fullname" .) .Values.serviceAccount.name }} {{- else }} {{- default "default" .Values.serviceAccount.name }} {{- end }} diff --git a/templates/deployment.yaml b/templates/deployment.yaml index b516cfe..4633e55 100644 --- a/templates/deployment.yaml +++ b/templates/deployment.yaml @@ -1,16 +1,16 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ include "myHelmChart.fullname" . }} + name: {{ include "openresty.fullname" . }} labels: - {{- include "myHelmChart.labels" . | nindent 4 }} + {{- include "openresty.labels" . | nindent 4 }} spec: {{- if not .Values.autoscaling.enabled }} replicas: {{ .Values.replicaCount }} {{- end }} selector: matchLabels: - {{- include "myHelmChart.selectorLabels" . | nindent 6 }} + {{- include "openresty.selectorLabels" . | nindent 6 }} template: metadata: {{- with .Values.podAnnotations }} @@ -18,7 +18,7 @@ spec: {{- toYaml . | nindent 8 }} {{- end }} labels: - {{- include "myHelmChart.labels" . | nindent 8 }} + {{- include "openresty.labels" . | nindent 8 }} {{- with .Values.podLabels }} {{- toYaml . | nindent 8 }} {{- end }} @@ -27,7 +27,7 @@ spec: imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} - serviceAccountName: {{ include "myHelmChart.serviceAccountName" . }} + serviceAccountName: {{ include "openresty.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: diff --git a/templates/hpa.yaml b/templates/hpa.yaml index ec163e6..3b28a81 100644 --- a/templates/hpa.yaml +++ b/templates/hpa.yaml @@ -2,14 +2,14 @@ apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: - name: {{ include "myHelmChart.fullname" . }} + name: {{ include "openresty.fullname" . }} labels: - {{- include "myHelmChart.labels" . | nindent 4 }} + {{- include "openresty.labels" . | nindent 4 }} spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment - name: {{ include "myHelmChart.fullname" . }} + name: {{ include "openresty.fullname" . }} minReplicas: {{ .Values.autoscaling.minReplicas }} maxReplicas: {{ .Values.autoscaling.maxReplicas }} metrics: diff --git a/templates/ingress.yaml b/templates/ingress.yaml index 7a11e99..746e4e7 100644 --- a/templates/ingress.yaml +++ b/templates/ingress.yaml @@ -1,5 +1,5 @@ {{- if .Values.ingress.enabled -}} -{{- $fullName := include "myHelmChart.fullname" . -}} +{{- $fullName := include "openresty.fullname" . -}} {{- $svcPort := .Values.service.port -}} {{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} @@ -17,7 +17,7 @@ kind: Ingress metadata: name: {{ $fullName }} labels: - {{- include "myHelmChart.labels" . | nindent 4 }} + {{- include "openresty.labels" . | nindent 4 }} {{- with .Values.ingress.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/templates/service.yaml b/templates/service.yaml index 058630f..3fea8e3 100644 --- a/templates/service.yaml +++ b/templates/service.yaml @@ -1,9 +1,9 @@ apiVersion: v1 kind: Service metadata: - name: {{ include "myHelmChart.fullname" . }} + name: {{ include "openresty.fullname" . }} labels: - {{- include "myHelmChart.labels" . | nindent 4 }} + {{- include "openresty.labels" . | nindent 4 }} spec: type: {{ .Values.service.type }} ports: @@ -12,4 +12,4 @@ spec: protocol: TCP name: http selector: - {{- include "myHelmChart.selectorLabels" . | nindent 4 }} + {{- include "openresty.selectorLabels" . | nindent 4 }} diff --git a/templates/serviceaccount.yaml b/templates/serviceaccount.yaml index d59c62c..206afea 100644 --- a/templates/serviceaccount.yaml +++ b/templates/serviceaccount.yaml @@ -2,9 +2,9 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: {{ include "myHelmChart.serviceAccountName" . }} + name: {{ include "openresty.serviceAccountName" . }} labels: - {{- include "myHelmChart.labels" . | nindent 4 }} + {{- include "openresty.labels" . | nindent 4 }} {{- with .Values.serviceAccount.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/templates/tests/test-connection.yaml b/templates/tests/test-connection.yaml index 2f13615..418d03d 100644 --- a/templates/tests/test-connection.yaml +++ b/templates/tests/test-connection.yaml @@ -1,9 +1,9 @@ apiVersion: v1 kind: Pod metadata: - name: "{{ include "myHelmChart.fullname" . }}-test-connection" + name: "{{ include "openresty.fullname" . }}-test-connection" labels: - {{- include "myHelmChart.labels" . | nindent 4 }} + {{- include "openresty.labels" . | nindent 4 }} annotations: "helm.sh/hook": test spec: @@ -11,5 +11,5 @@ spec: - name: wget image: busybox command: ['wget'] - args: ['{{ include "myHelmChart.fullname" . }}:{{ .Values.service.port }}'] + args: ['{{ include "openresty.fullname" . }}:{{ .Values.service.port }}'] restartPolicy: Never diff --git a/values.yaml b/values.yaml index 7839046..8ae04b0 100644 --- a/values.yaml +++ b/values.yaml @@ -1,4 +1,4 @@ -# Default values for myHelmChart. +# Default values for openresty. # This is a YAML-formatted file. # Declare variables to be passed into your templates. From 421e10a55cbe3dd6f0df5e11b75f24b5e3832c34 Mon Sep 17 00:00:00 2001 From: Rustam Tagaev Date: Mon, 2 Dec 2024 18:47:04 +0300 Subject: [PATCH 2/5] [DO-1377] add configMap --- .gitignore | 2 ++ Chart.yaml | 4 ++-- templates/configmap.yaml | 22 ++++++++++++++++++++++ values.yaml | 12 +++++++++--- 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100644 templates/configmap.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d35a60 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +custom_values.yaml +*.tgz diff --git a/Chart.yaml b/Chart.yaml index bc6c4d0..c13d00f 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: openresty -description: A Helm chart for Kubernetes +description: OpenResty API gateway # A chart can be either an 'application' or a 'library' chart. # @@ -21,4 +21,4 @@ version: 0.1.0 # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "1.16.0" +appVersion: "1.21.4.1" diff --git a/templates/configmap.yaml b/templates/configmap.yaml new file mode 100644 index 0000000..1a11e7a --- /dev/null +++ b/templates/configmap.yaml @@ -0,0 +1,22 @@ +{{ if .Values.configMap.enabled }} +apiVersion: v1 +kind: ConfigMap +metadata: + labels: + app: "{{ template "openresty.fullname" . }}" + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + heritage: "{{ .Release.Service }}" + release: "{{ .Release.Name }}" +{{- with .Values.configMap.annotations }} + annotations: +{{ toYaml . | indent 4 }} +{{- end }} + name: "{{ .Release.Name }}-config" +data: +{{- with .Values.configMap.apiConfig }} + api-gw.conf: {{ toYaml . | indent 4 }} +{{- end }} +{{- with .Values.configMap.luaScript }} + script.lua: {{ toYaml . | indent 4 }} +{{- end }} +{{- end }} diff --git a/values.yaml b/values.yaml index 8ae04b0..6aa76e9 100644 --- a/values.yaml +++ b/values.yaml @@ -5,10 +5,16 @@ replicaCount: 1 image: - repository: nginx + repository: harbor.avroid.tech/devops/openresty pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. - tag: "" + tag: "1.21.4.1-0-alpine" + +configMap: + enabled: false + annotations: {} + apiConfig: "" + luaScript: "" imagePullSecrets: [] nameOverride: "" @@ -16,7 +22,7 @@ fullnameOverride: "" serviceAccount: # Specifies whether a service account should be created - create: true + create: false # Automatically mount a ServiceAccount's API credentials? automount: true # Annotations to add to the service account From 5a48727454be1ccbcb7896dd563d0ce4af6bf785 Mon Sep 17 00:00:00 2001 From: Rustam Tagaev Date: Mon, 2 Dec 2024 19:09:53 +0300 Subject: [PATCH 3/5] [DO-1377] add readme --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 725fdad..adb46e9 100644 --- a/README.md +++ b/README.md @@ -1 +1,25 @@ # OpenResty + +Создание пакета для Helm чарта + +```bash +helm package ./ +``` + +Добавление репозитория + +```bash +helm repo add avroid https://nexus.avroid.tech/repository/devops-helm-release +``` + +Установка репозитория + +```bash +helm install -n api-gateway -f custom_values.yaml openresty ./ +``` + +Обновления приложения + +```bash +helm upgrade -n api-gateway -f custom_values.yaml openresty ./ +``` From 24828331df9d97773ea8ba879e470759e7b37d2b Mon Sep 17 00:00:00 2001 From: Rustam Tagaev Date: Fri, 6 Dec 2024 15:22:05 +0300 Subject: [PATCH 4/5] [DO-1377] add checksum for configmap --- templates/deployment.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/deployment.yaml b/templates/deployment.yaml index 4633e55..3e0b719 100644 --- a/templates/deployment.yaml +++ b/templates/deployment.yaml @@ -17,6 +17,7 @@ spec: annotations: {{- toYaml . | nindent 8 }} {{- end }} + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml" ) . | sha256sum }} labels: {{- include "openresty.labels" . | nindent 8 }} {{- with .Values.podLabels }} From 080e4e77856d8cce0ea8bb2e296f8178d1128e60 Mon Sep 17 00:00:00 2001 From: Rustam Tagaev Date: Fri, 6 Dec 2024 15:28:21 +0300 Subject: [PATCH 5/5] [DO-1377] fix annotation --- templates/deployment.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/deployment.yaml b/templates/deployment.yaml index 3e0b719..1c411ad 100644 --- a/templates/deployment.yaml +++ b/templates/deployment.yaml @@ -13,11 +13,11 @@ spec: {{- include "openresty.selectorLabels" . | nindent 6 }} template: metadata: - {{- with .Values.podAnnotations }} annotations: + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml" ) . | sha256sum }} + {{- with .Values.podAnnotations }} {{- toYaml . | nindent 8 }} {{- end }} - checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml" ) . | sha256sum }} labels: {{- include "openresty.labels" . | nindent 8 }} {{- with .Values.podLabels }}