diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..995bb4e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +on: + pull_request: + push: + branches: + - main + +jobs: + render: + permissions: + contents: read + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + persist-credentials: 'false' + + - name: Install Helm + uses: azure/setup-helm@v5 + + - name: Lint chart + run: helm lint charts/restinthemiddle --set config.targetHostDsn=http://example.com + + - name: Render chart with value combinations + run: | + set -euo pipefail + BASE="--set config.targetHostDsn=http://example.com" + render() { + echo "=== helm template $* ===" + # shellcheck disable=SC2086 + helm template ci charts/restinthemiddle $BASE "$@" > /dev/null + } + render + render --set ingress.enabled=true + render --set ingress.enabled=true --set ingress.className=nginx + render --set autoscaling.enabled=true + render --set service.type=NodePort + render --set service.type=LoadBalancer + render --set serviceAccount.create=true + render --set service.portOverride=80 + render --set ingress.enabled=true --set autoscaling.enabled=true --set serviceAccount.create=true diff --git a/charts/restinthemiddle/Chart.yaml b/charts/restinthemiddle/Chart.yaml index f987a0e..e6c7594 100644 --- a/charts/restinthemiddle/Chart.yaml +++ b/charts/restinthemiddle/Chart.yaml @@ -3,3 +3,5 @@ name: restinthemiddle description: Deploy the HTTP logging proxy with ease type: application version: 1.1.10 +# autoscaling/v2 requires Kubernetes >= 1.23 +kubeVersion: ">=1.23.0-0" diff --git a/charts/restinthemiddle/README.md b/charts/restinthemiddle/README.md index 7ea5aac..2f6026a 100644 --- a/charts/restinthemiddle/README.md +++ b/charts/restinthemiddle/README.md @@ -4,12 +4,15 @@ Deploy the HTTP logging proxy with ease +## Requirements + +Kubernetes: `>=1.23.0-0` + ## Values | Key | Type | Default | Description | |-----|------|---------|-------------| | affinity | object | `{}` | | -| applicationName | string | `"restinthemiddle"` | | | autoscaling.enabled | bool | `false` | Handle with care! Autoscaling will make sense only if you have centralized logging. | | autoscaling.maxReplicas | int | `2` | | | autoscaling.minReplicas | int | `1` | | @@ -43,7 +46,6 @@ Deploy the HTTP logging proxy with ease | ingress.hosts[0].paths[0].pathType | string | `"ImplementationSpecific"` | | | ingress.tls | list | `[]` | | | nameOverride | string | `""` | | -| namespace | string | `"default"` | | | nodeSelector | object | `{}` | | | podAnnotations | object | `{}` | | | podLabels | object | `{}` | | diff --git a/charts/restinthemiddle/templates/NOTES.txt b/charts/restinthemiddle/templates/NOTES.txt index a3ad555..ead8836 100644 --- a/charts/restinthemiddle/templates/NOTES.txt +++ b/charts/restinthemiddle/templates/NOTES.txt @@ -11,9 +11,9 @@ 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 the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "restinthemiddle.fullname" . }}' + You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "restinthemiddle.fullname" . }}' export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "restinthemiddle.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") - echo http://$SERVICE_IP:{{ .Values.service.port }} + echo http://$SERVICE_IP:{{ .Values.service.portOverride | default .Values.config.listenPort }} {{- else if contains "ClusterIP" .Values.service.type }} export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "restinthemiddle.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}") diff --git a/charts/restinthemiddle/templates/_helpers.tpl b/charts/restinthemiddle/templates/_helpers.tpl index 7669c0c..7d73372 100644 --- a/charts/restinthemiddle/templates/_helpers.tpl +++ b/charts/restinthemiddle/templates/_helpers.tpl @@ -51,12 +51,14 @@ app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} {{/* -Create the name of the service account to use +Create the name of the service account to use. +Empty when no service account is created and none is named, so the +pod falls back to the namespace default implicitly. */}} {{- define "restinthemiddle.serviceAccountName" -}} {{- if .Values.serviceAccount.create }} {{- default (include "restinthemiddle.fullname" .) .Values.serviceAccount.name }} {{- else }} -{{- default "default" .Values.serviceAccount.name }} +{{- .Values.serviceAccount.name }} {{- end }} {{- end }} diff --git a/charts/restinthemiddle/templates/configmap.yaml b/charts/restinthemiddle/templates/configmap.yaml index cb67f72..968b719 100644 --- a/charts/restinthemiddle/templates/configmap.yaml +++ b/charts/restinthemiddle/templates/configmap.yaml @@ -1,10 +1,7 @@ -{{- if .Values.config -}} apiVersion: v1 kind: ConfigMap metadata: name: {{ include "restinthemiddle.fullname" . }} - namespace: {{ .Release.Namespace }} data: config.yaml: | {{- toYaml .Values.config | nindent 4 }} -{{- end }} diff --git a/charts/restinthemiddle/templates/deployment.yaml b/charts/restinthemiddle/templates/deployment.yaml index 30e3cbd..f7552f1 100644 --- a/charts/restinthemiddle/templates/deployment.yaml +++ b/charts/restinthemiddle/templates/deployment.yaml @@ -1,7 +1,6 @@ apiVersion: apps/v1 kind: Deployment metadata: - namespace: {{ .Release.Namespace }} name: {{ include "restinthemiddle.fullname" . }} labels: {{- include "restinthemiddle.labels" . | nindent 4 }} @@ -29,21 +28,21 @@ spec: imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} - serviceAccountName: {{ include "restinthemiddle.serviceAccountName" . }} + {{- with include "restinthemiddle.serviceAccountName" . }} + serviceAccountName: {{ . }} + {{- end }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: - name: {{ template "restinthemiddle.name" . }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} - image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Values.image.tag }}" + image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - containerPort: {{ .Values.config.listenPort }} protocol: TCP name: listen-port -# livenessProbe: {} -# readinessProbe: {} resources: {{- toYaml .Values.resources | nindent 12 }} volumeMounts: diff --git a/charts/restinthemiddle/templates/hpa.yaml b/charts/restinthemiddle/templates/hpa.yaml index a91e04f..4131a78 100644 --- a/charts/restinthemiddle/templates/hpa.yaml +++ b/charts/restinthemiddle/templates/hpa.yaml @@ -1,5 +1,5 @@ {{- if .Values.autoscaling.enabled }} -apiVersion: autoscaling/v2beta1 +apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: {{ include "restinthemiddle.fullname" . }} @@ -17,12 +17,16 @@ spec: - type: Resource resource: name: cpu - targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} {{- end }} {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} - type: Resource resource: name: memory - targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} {{- end }} {{- end }} diff --git a/charts/restinthemiddle/templates/ingress.yaml b/charts/restinthemiddle/templates/ingress.yaml index 65d8af8..0c1d4c6 100644 --- a/charts/restinthemiddle/templates/ingress.yaml +++ b/charts/restinthemiddle/templates/ingress.yaml @@ -1,18 +1,7 @@ {{- if .Values.ingress.enabled -}} {{- $fullName := include "restinthemiddle.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") }} - {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} - {{- end }} -{{- end }} -{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +{{- $svcPort := .Values.service.portOverride | default .Values.config.listenPort -}} apiVersion: networking.k8s.io/v1 -{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} -apiVersion: networking.k8s.io/v1beta1 -{{- else -}} -apiVersion: extensions/v1beta1 -{{- end }} kind: Ingress metadata: name: {{ $fullName }} @@ -23,8 +12,8 @@ metadata: {{- toYaml . | nindent 4 }} {{- end }} spec: - {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} - ingressClassName: {{ .Values.ingress.className }} + {{- with .Values.ingress.className }} + ingressClassName: {{ . }} {{- end }} {{- if .Values.ingress.tls }} tls: @@ -43,19 +32,12 @@ spec: paths: {{- range .paths }} - path: {{ .path }} - {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} - pathType: {{ .pathType }} - {{- end }} + pathType: {{ .pathType | default "ImplementationSpecific" }} backend: - {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} service: name: {{ $fullName }} port: number: {{ $svcPort }} - {{- else }} - serviceName: {{ $fullName }} - servicePort: {{ $svcPort }} - {{- end }} {{- end }} {{- end }} {{- end }} diff --git a/charts/restinthemiddle/values.yaml b/charts/restinthemiddle/values.yaml index 038b029..51b1a7a 100644 --- a/charts/restinthemiddle/values.yaml +++ b/charts/restinthemiddle/values.yaml @@ -1,6 +1,3 @@ -namespace: default -applicationName: restinthemiddle - image: registry: docker.io repository: jdschulze/restinthemiddle