diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 53ad5c3..14231a8 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -1,46 +1,64 @@ +# Build and push Image name: Build and push Image + on: push: - branches: - - main + jobs: build: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 + + - name: Set tag + id: set-tag + run: | + SHORT_SHA=$(git rev-parse --short HEAD) + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then + echo "::set-output name=tag1::latest" + echo "::set-output name=tag2::commit-$SHORT_SHA" + else + echo "::set-output name=tag1::dev" + echo "::set-output name=tag2::commit-$SHORT_SHA" + fi + - name: Docker meta id: meta uses: docker/metadata-action@v5 with: images: | - mtr.devops.telekom.de/caas/kube-downscaler-dtag + mtr.devops.telekom.de/caas/py-kube-downscaler ghcr.io/caas-team/py-kube-downscaler tags: | - type=ref,event=tag - type=ref,event=branch - type=ref,event=pr - type=raw,value=dev + ${{ steps.set-tag.outputs.tag1 }} + ${{ steps.set-tag.outputs.tag2 }} + - name: Install Cosign uses: sigstore/cosign-installer@main with: cosign-release: 'v2.2.0' + - name: Set up QEMU uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Login to MTR uses: docker/login-action@v3 with: registry: mtr.devops.telekom.de username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push uses: docker/build-push-action@v5 id: build-push @@ -48,13 +66,16 @@ jobs: context: . platforms: linux/amd64,linux/arm64 push: true - tags: | - mtr.devops.telekom.de/caas/kube-downscaler-dtag:latest - ghcr.io/caas-team/py-kube-downscaler:latest - ${{ steps.meta.outputs.tags }} + tags: ${{ steps.meta.outputs.tags }} + - name: Sign Push run: | cosign sign --key env://COSIGN_KEY --tlog-upload=false ghcr.io/caas-team/py-kube-downscaler@${{ steps.build-push.outputs.digest }} - cosign sign --key env://COSIGN_KEY --tlog-upload=false mtr.devops.telekom.de/caas/kube-downscaler-dtag@${{ steps.build-push.outputs.digest }} + cosign sign --key env://COSIGN_KEY --tlog-upload=false mtr.devops.telekom.de/caas/py-kube-downscaler@${{ steps.build-push.outputs.digest }} env: - COSIGN_KEY: ${{secrets.COSIGN_KEY}} + COSIGN_KEY: ${{ secrets.COSIGN_KEY }} + + call-e2e: + needs: build + uses: ./.github/workflows/end2end.yml + secrets: inherit diff --git a/.github/workflows/end2end.yml b/.github/workflows/end2end.yml new file mode 100644 index 0000000..5891a3f --- /dev/null +++ b/.github/workflows/end2end.yml @@ -0,0 +1,68 @@ +name: End-to-End Testing + +on: + workflow_call: + +jobs: + end2end: + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Set up K3S + uses: debianmaster/actions-k3s@master + with: + version: 'v1.26.9-k3s1' + + - name: Check Metricsserver Deployment + run: | + kubectl -n kube-system rollout status deployment/metrics-server --timeout=60s + STATUS=$(kubectl -n kube-system get deployment metrics-server -o jsonpath={.status.readyReplicas}) + if [[ $STATUS -ne 1 ]] + then + echo "Deployment metrics-server not ready" + kubectl -n kube-system get events + exit 1 + else + echo "Deployment metrics-server OK" + fi + + - name: Setup Helm + run: | + curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash + helm version + + - name: Get Image Tag + id: version + run: echo "value=commit-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Install py-kube-downscaler + run: | + set +e # Disable exit on error + helm upgrade -i py-kube-downscaler \ + --atomic \ + --timeout 180s \ + --set image.tag=${{ steps.version.outputs.value }} \ + ./chart + RESULT=$? + set -e # Re-enable exit on error + if [ $RESULT -ne 0 ]; then + echo "Helm deployment failed, collecting logs and events..." + kubectl describe pods -l app.kubernetes.io/name=py-kube-downscaler + kubectl logs -l app.kubernetes.io/name=py-kube-downscaler --tail=50 + kubectl get events --all-namespaces --sort-by='.lastTimestamp' + exit 1 + fi + + - name: Verify Deployment + run: | + kubectl rollout status deployment/py-kube-downscaler --timeout=60s + STATUS=$(kubectl get deployment py-kube-downscaler -o jsonpath='{.status.readyReplicas}') + if [[ "$STATUS" -ne 1 ]]; then + echo "Deployment py-kube-downscaler not ready" + kubectl get events + exit 1 + fi + echo "Deployment py-kube-downscaler OK" + diff --git a/chart/Chart.yaml b/chart/Chart.yaml index 420ff56..eb6a14a 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 -name: kube-downscaler -description: A Helm chart for deploying kube-downscaler +name: py-kube-downscaler +description: A Helm chart for deploying py-kube-downscaler type: application version: 0.1.0 diff --git a/chart/templates/_helpers.tpl b/chart/templates/_helpers.tpl index 4d6b869..4dacfb9 100644 --- a/chart/templates/_helpers.tpl +++ b/chart/templates/_helpers.tpl @@ -1,7 +1,7 @@ {{/* Expand the name of the chart. */}} -{{- define "kube-downscaler.name" -}} +{{- define "py-kube-downscaler.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 "kube-downscaler.fullname" -}} +{{- define "py-kube-downscaler.fullname" -}} {{- if .Values.fullnameOverride }} {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} {{- else }} @@ -26,30 +26,30 @@ 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 "kube-downscaler.chart" -}} +{{- define "py-kube-downscaler.chart" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} {{- end }} {{/* Common labels */}} -{{- define "kube-downscaler.labels" -}} -application: {{ include "kube-downscaler.name" . }} +{{- define "py-kube-downscaler.labels" -}} +application: {{ include "py-kube-downscaler.name" . }} {{- end }} {{/* Selector labels */}} -{{- define "kube-downscaler.selectorLabels" -}} -application: {{ include "kube-downscaler.name" . }} +{{- define "py-kube-downscaler.selectorLabels" -}} +application: {{ include "py-kube-downscaler.name" . }} {{- end }} {{/* Create the name of the service account to use */}} -{{- define "kube-downscaler.serviceAccountName" -}} +{{- define "py-kube-downscaler.serviceAccountName" -}} {{- if .Values.serviceAccount.create }} -{{- default (include "kube-downscaler.fullname" .) .Values.serviceAccount.name }} +{{- default (include "py-kube-downscaler.fullname" .) .Values.serviceAccount.name }} {{- else }} {{- default "default" .Values.serviceAccount.name }} {{- end }} diff --git a/chart/templates/configmap.yaml b/chart/templates/configmap.yaml index 8dc3b63..8764211 100644 --- a/chart/templates/configmap.yaml +++ b/chart/templates/configmap.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: {{ include "kube-downscaler.name" . }} + name: {{ include "py-kube-downscaler.name" . }} data: # downscale for non-work hours EXCLUDE_NAMESPACES: "{{- join ", " .Values.excludedNamespaces }}" diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index 1b994ef..8cf1ffd 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -2,21 +2,21 @@ apiVersion: apps/v1 kind: Deployment metadata: labels: - {{- include "kube-downscaler.labels" . | nindent 4 }} - name: {{ include "kube-downscaler.name" . }} + {{- include "py-kube-downscaler.labels" . | nindent 4 }} + name: {{ include "py-kube-downscaler.name" . }} spec: {{- if not .Values.autoscaling.enabled }} replicas: {{ .Values.replicaCount }} {{- end }} selector: matchLabels: - {{- include "kube-downscaler.selectorLabels" . | nindent 6 }} + {{- include "py-kube-downscaler.selectorLabels" . | nindent 6 }} template: metadata: labels: - {{- include "kube-downscaler.selectorLabels" . | nindent 8 }} + {{- include "py-kube-downscaler.selectorLabels" . | nindent 8 }} spec: - serviceAccountName: {{ include "kube-downscaler.serviceAccountName" . }} + serviceAccountName: {{ include "py-kube-downscaler.serviceAccountName" . }} containers: - name: {{ .Chart.Name }} image: {{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }} diff --git a/chart/templates/rbac.yaml b/chart/templates/rbac.yaml index 6a7d514..e429138 100644 --- a/chart/templates/rbac.yaml +++ b/chart/templates/rbac.yaml @@ -1,12 +1,12 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: {{ include "kube-downscaler.name" . }} + name: {{ include "py-kube-downscaler.name" . }} --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - name: {{ include "kube-downscaler.name" . }} + name: {{ include "py-kube-downscaler.name" . }} rules: - apiGroups: - "" @@ -93,12 +93,12 @@ rules: apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: - name: {{ include "kube-downscaler.name" . }} + name: {{ include "py-kube-downscaler.name" . }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: {{ include "kube-downscaler.name" . }} + name: {{ include "py-kube-downscaler.name" . }} subjects: - kind: ServiceAccount - name: {{ include "kube-downscaler.name" . }} - namespace: {{ include "kube-downscaler.name" . }} + name: {{ include "py-kube-downscaler.name" . }} + namespace: {{ include "py-kube-downscaler.name" . }} diff --git a/chart/values.yaml b/chart/values.yaml index dede024..aee6cbf 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -1,11 +1,9 @@ replicaCount: 1 image: - # see https://github.com/hjacobs/kube-downscaler/releases - repository: mtr.devops.telekom.de/caas/kube-downscaler + repository: ghcr.io/caas-team/py-kube-downscaler pullPolicy: IfNotPresent - # Overrides the image tag whose default is the chart appVersion. - tag: "23.2.0@sha256:4129e7e7551eb451ee2b43680ef818f3057304ad50888f79ec9722afab6c29ff" + tag: "{{ .Values.image.tag | default .Chart.AppVersion }}" # Dynamically set from CI arguments: - --interval=60 @@ -66,10 +64,10 @@ tolerations: [] affinity: {} # Used to configure the env -configMapName: kube-downscaler +configMapName: py-kube-downscaler # Namespaces being excluded from the 'downscale for non-work hours' # DEFAULT_UPTIME: "Mon-Fri 07:30-20:30 CET" excludedNamespaces: - - kube-downscaler + - py-kube-downscaler - kube-system