Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/e2e-test-pipeline #15

Merged
merged 32 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,81 @@
# 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"
Fovty marked this conversation as resolved.
Show resolved Hide resolved
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
with:
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
68 changes: 68 additions & 0 deletions .github/workflows/end2end.yml
Original file line number Diff line number Diff line change
@@ -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"

4 changes: 2 additions & 2 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 9 additions & 9 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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 }}

Expand All @@ -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 }}
Expand All @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion chart/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -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 }}"
10 changes: 5 additions & 5 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
12 changes: 6 additions & 6 deletions chart/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -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:
- ""
Expand Down Expand Up @@ -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" . }}
10 changes: 4 additions & 6 deletions chart/values.yaml
Original file line number Diff line number Diff line change
@@ -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
Fovty marked this conversation as resolved.
Show resolved Hide resolved

arguments:
- --interval=60
Expand Down Expand Up @@ -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
Loading