Skip to content

Commit 7502649

Browse files
authored
ci: move k8s to run in pr check workflow (#2139)
This commit removes the k8s workflow and adds a composite action which can be used in PR check workflows allowing it to run under one job Signed-off-by: Vibhu Prashar <[email protected]>
1 parent 2e3afdf commit 7502649

File tree

3 files changed

+156
-151
lines changed

3 files changed

+156
-151
lines changed

.github/k8s/action.yaml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Build and Deploy on K8s
2+
description: Builds and deploys Kepler to a Kubernetes cluster on VM
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Install Docker
8+
shell: bash
9+
run: |
10+
sudo apt-get update
11+
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
12+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
13+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
14+
sudo apt-get update
15+
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
16+
sudo usermod -aG docker $USER
17+
18+
- name: Verify Docker installation
19+
shell: bash
20+
run: |
21+
docker ps
22+
docker --version
23+
24+
- name: Install Kind
25+
shell: bash
26+
run: |
27+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-linux-amd64
28+
chmod +x ./kind
29+
sudo mv ./kind /usr/local/bin/kind
30+
31+
- name: Verify Kind installation
32+
shell: bash
33+
run: |
34+
kind version
35+
36+
- name: Install Kubectl
37+
shell: bash
38+
run: |
39+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
40+
chmod +x ./kubectl
41+
sudo mv ./kubectl /usr/local/bin/kubectl
42+
43+
- name: Verify Kubectl installation
44+
shell: bash
45+
run: |
46+
kubectl version --client
47+
48+
- name: Checkout source
49+
uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0
52+
53+
- name: Setup Go
54+
uses: actions/[email protected]
55+
with:
56+
go-version-file: go.mod
57+
cache: false
58+
59+
- name: Build image
60+
shell: bash
61+
run: |
62+
make image
63+
env:
64+
IMG_BASE: localhost:5001
65+
VERSION: dev
66+
67+
- name: Setup Kind cluster
68+
shell: bash
69+
run: |
70+
make cluster-up
71+
72+
- name: Push image
73+
shell: bash
74+
run: |
75+
make push
76+
env:
77+
IMG_BASE: localhost:5001
78+
VERSION: dev
79+
80+
- name: Enable fake cpu meter
81+
shell: bash
82+
run: |
83+
sed -i '/fake-cpu-meter:/{n;s/enabled: false/enabled: true/}' manifests/k8s/configmap.yaml
84+
85+
- name: Deploy Kepler
86+
shell: bash
87+
run: |
88+
make deploy
89+
env:
90+
IMG_BASE: localhost:5001
91+
VERSION: dev
92+
93+
- name: Verify Kepler deployment
94+
shell: bash
95+
run: |
96+
kubectl rollout status daemonset/kepler -n kepler --timeout=5m
97+
98+
# TODO: Move this once we add validator tool to the repo
99+
- name: Validate metric endpoint
100+
id: validate
101+
shell: bash
102+
run: |
103+
kubectl port-forward service/kepler 28282:28282 -n kepler &
104+
sleep 20 # sleep for 20 seconds to give the service time to start
105+
106+
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:28282/metrics)
107+
[[ $HTTP_STATUS -ne 200 ]] && echo "HTTP status code is not 200" && exit 1
108+
109+
curl -s -o /tmp/metrics.txt http://localhost:28282/metrics
110+
111+
for metric in kepler_process_cpu_watts \
112+
kepler_node_cpu_info \
113+
kepler_node_cpu_watts \
114+
kepler_node_cpu_joules_total \
115+
kepler_node_cpu_active_joules_total \
116+
kepler_node_cpu_idle_joules_total \
117+
kepler_node_cpu_active_watts \
118+
kepler_node_cpu_idle_watts \
119+
kepler_process_cpu_joules_total \
120+
kepler_container_cpu_joules_total \
121+
kepler_container_cpu_watts; do
122+
echo "Checking metric: $metric"
123+
if ! grep -q "$metric" /tmp/metrics.txt; then
124+
echo "Metric $metric not found"
125+
exit 1
126+
fi
127+
done
128+
129+
- name: Run must gather
130+
if: failure()
131+
shell: bash
132+
run: |
133+
echo "::group::Get pods in kepler namespace"
134+
kubectl get pods -n kepler || true
135+
echo "::endgroup::"
136+
137+
echo "::group::Get pods in monitoring namespace"
138+
kubectl get pods -n monitoring || true
139+
echo "::endgroup::"
140+
141+
echo "::group::Get logs for kepler daemonset"
142+
kubectl logs daemonset/kepler -n kepler || true
143+
echo "::endgroup::"
144+
145+
echo "::group::Fetch metrics from localhost:28282"
146+
curl -s http://localhost:28282/metrics || true
147+
echo "::endgroup::"

.github/workflows/k8s.yaml

Lines changed: 0 additions & 151 deletions
This file was deleted.

.github/workflows/pr-checks.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,12 @@ jobs:
113113
uses: ./.github/publish-image
114114
with:
115115
registry: localhost:5001
116+
117+
build-and-deploy:
118+
runs-on: ubuntu-latest
119+
steps:
120+
- name: Checkout source
121+
uses: actions/checkout@v4
122+
123+
- name: Build and Deploy Kepler on K8s
124+
uses: ./.github/k8s

0 commit comments

Comments
 (0)