Skip to content

Commit

Permalink
task: move from kubeval to kubeconform (#73)
Browse files Browse the repository at this point in the history
In the process I also spotted that we're not actually linting/validating
all our schemas, since we run helm template without any values, it's run
without ingress and hpa enabled, so this PR also adds values files which
causes all template files to be exercised.
  • Loading branch information
Christopher Kolstad authored Mar 17, 2023
1 parent 2eb76ca commit 573f4f0
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 94 deletions.
7 changes: 7 additions & 0 deletions .github/helmvalues/unleash-edge/unleash-edge-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
autoscaling:
enabled: true
minReplicas: 1
maxReplicas: 4

ingress:
enabled: true
27 changes: 27 additions & 0 deletions .github/kubeconform.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
#
# use kubeconform to validate helm generated kubernetes manifests
#

set -o errexit
set -o pipefail

echo "Running for K8S schema version: $KUBERNETES_VERSION with Kube conform: $KUBECONFORM_VERSION"
# install kubeconform
curl --silent --show-error --fail --location --output /tmp/kubeconform.tar.gz https://github.com/yannh/kubeconform/releases/download/"${KUBECONFORM_VERSION}"/kubeconform-linux-amd64.tar.gz
sudo tar -C /usr/local/bin -xf /tmp/kubeconform.tar.gz kubeconform

mkdir -p results
echo "Adding bitnami repo so dependency building succeeds"
helm repo add bitnami https://charts.bitnami.com/bitnami
echo "Repo added"
CHART_DIRS="$(git diff --find-renames --name-only "$(git rev-parse --abbrev-ref HEAD)" remotes/origin/main -- charts | grep '[cC]hart.yaml' | sed -e 's#/[Cc]hart.yaml##g')"
for CHART_DIR in ${CHART_DIRS}; do
echo "helm dependency build..."
helm dependency build "${CHART_DIR}"

echo "kubeconforming ${CHART_DIR##charts/} chart ..."
helm template "${CHART_DIR}" -f ./"${CHART_DIR}"/ci/"${CHART_DIR##charts/}"-values.yaml | kubeconform -kubernetes-version "${KUBERNETES_VERSION}" --output=tap > results/"${CHART_DIR##charts/}"-"${KUBERNETES_VERSION}"-result.tap
done

exit 0
30 changes: 0 additions & 30 deletions .github/kubeval.sh

This file was deleted.

73 changes: 43 additions & 30 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Codespell
uses: codespell-project/actions-codespell@master
with:
Expand All @@ -22,26 +22,27 @@ jobs:
check_hidden: true

lint-chart:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@v1
uses: azure/setup-helm@v3
with:
version: v3.8.1
- uses: actions/setup-python@v2
version: v3.11.1
- uses: actions/setup-python@v4
with:
python-version: 3.7
python-version: 3.9
check-latest: true
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.2.1
uses: helm/chart-testing-action@v2.3.1
- name: Run chart-testing (lint)
run: ct lint --config .github/ct.yaml

super-linter:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
Expand All @@ -59,40 +60,51 @@ jobs:
VALIDATE_JSCPD: false
VALIDATE_KUBERNETES_KUBEVAL: false
VALIDATE_YAML: false

kubeval-chart:
runs-on: ubuntu-20.04
kubeconform:
runs-on: ubuntu-latest
needs:
- codespell
- lint-chart
- super-linter
- lint-chart
strategy:
matrix:
k8s:
- v1.22.11
- v1.23.8
- v1.24.2
- 1.23.17
- 1.24.11
- 1.25.7
- 1.26.2
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Fetch history
run: git fetch --prune --unshallow
- name: Run kubeval
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup helm
uses: azure/setup-helm@v3
with:
version: 3.11.1
- name: Run kubeconform tests
run: .github/kubeconform.sh
env:
KUBERNETES_VERSION: ${{ matrix.k8s }}
run: .github/kubeval.sh
KUBECONFORM_VERSION: v0.6.1
- name: Create test summary
uses: test-summary/action@v2
with:
paths: "./results/*.tap"
if: always()

install-chart:
name: install-chart
runs-on: ubuntu-20.04
needs:
- kubeval-chart
- kubeconform
strategy:
matrix:
k8s:
- v1.22.15
- v1.23.12
- v1.24.6
- v1.23.13
- v1.24.7
- v1.25.3
- v1.26.2
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -101,12 +113,13 @@ jobs:
- name: Set up Helm
uses: azure/setup-helm@v1
with:
version: v3.8.1
version: v3.11.1
- uses: actions/setup-python@v4
with:
python-version: 3.7
python-version: 3.9
check-latest: true
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.2.1
uses: helm/chart-testing-action@v2.3.1
- name: Run chart-testing (list-changed)
id: list-changed
run: |
Expand All @@ -115,7 +128,7 @@ jobs:
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Create kind cluster
uses: helm/kind-action@v1.3.0
uses: helm/kind-action@v1.5.0
if: steps.list-changed.outputs.changed == 'true'
with:
config: .github/kind-config.yaml
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Fetch history
run: git fetch --prune --unshallow
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v1
uses: azure/setup-helm@v3
with:
version: v3.5.2
version: 3.11.1

- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.2.0
uses: helm/chart-releaser-action@v1.5.0
with:
charts_repo_url: https://docs.getunleash.io/helm-charts
env:
Expand Down
2 changes: 1 addition & 1 deletion charts/unleash-proxy/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.2
version: 0.3.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
10 changes: 10 additions & 0 deletions charts/unleash-proxy/ci/unleash-proxy-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ingress:
enabled: true

autoscaling:
enabled: true
minReplicas: 1
maxReplicas: 4

edge:
enable: true
1 change: 1 addition & 0 deletions charts/unleash-proxy/features.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions charts/unleash-proxy/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
{{- if .Values.edge.enable }}
kind: ConfigMap
apiVersion: v1
metadata:
name: edge-features
data:
features.json: |-
{{ .Files.Get "features.json" | indent 4}}
{{- end}}
46 changes: 45 additions & 1 deletion charts/unleash-proxy/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ spec:
value: "{{ join "," .Values.proxy.clientKeys }}"
{{- end }}
- name: UNLEASH_URL
value: "{{ .Values.proxy.serverHost }}"
{{- if .Values.edge.enable }}
value: "http://localhost:3063/api"
{{- else }}
value: {{ .Values.proxy.serverHost }}"
{{- end }}
{{- if .Values.proxy.logLevel }}
- name: LOG_LEVEL
value: "{{ .Values.proxy.logLevel }}"
Expand Down Expand Up @@ -93,6 +97,46 @@ spec:
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- if .Values.edge.enable }}
- name: unleash-edge
args:
- "offline"
env:
- name: TOKENS
value: {{ .Values.proxy.apiToken }}
- name: BOOTSTRAP_FILE
value: /data/config/features.json
image: "unleashorg/unleash-edge:v0.5.1"
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 3063
protocol: TCP
livenessProbe:
httpGet:
path: /internal-backstage/health
port: http
readinessProbe:
httpGet:
port: http
path: /internal-backstage/health
resources:
limits:
cpu: 50m
memory: 32Mi
requests:
cpu: 20m
memory: 32Mi
volumeMounts:
- mountPath: "/data/config"
name: edge-features
{{- end }}
{{- if .Values.edge.enable }}
volumes:
- name: edge-features
configMap:
name: edge-features
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
11 changes: 8 additions & 3 deletions charts/unleash-proxy/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "unleash-proxy.fullname" . }}
Expand All @@ -17,12 +17,17 @@ 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 }}
container: application
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
4 changes: 3 additions & 1 deletion charts/unleash-proxy/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ spec:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "unleash-proxy.fullname" . }}:{{ .Values.service.port }}']
args: ['-O -',
"--header='Authorization: {{ .Values.proxy.clientKeys | first }}'",
'{{ include "unleash-proxy.fullname" . }}:{{ .Values.service.port }}/proxy/health']
restartPolicy: Never
2 changes: 2 additions & 0 deletions charts/unleash-proxy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ existingSecrets:
# name: secretname
# key: secretkey

edge:
enable: false
proxy:
serverHost: http://unleash:4242/api
apiToken: "default:development.unleash-insecure-api-token"
Expand Down
2 changes: 1 addition & 1 deletion charts/unleash/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ sources:
- https://github.com/Unleash/unleash
- https://github.com/Unleash/helm-charts
type: application
version: 2.7.7
version: 2.8.0
7 changes: 7 additions & 0 deletions charts/unleash/ci/unleash-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ingress:
enabled: true

autoscaling:
enabled: true
minReplicas: 1
maxReplicas: 4
Loading

0 comments on commit 573f4f0

Please sign in to comment.