-
Notifications
You must be signed in to change notification settings - Fork 4
173 lines (142 loc) · 5.48 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Test
on: [push, pull_request]
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.23
uses: actions/setup-go@v3
with:
go-version: 1.23.x
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: fmt
run: make fmt
test:
strategy:
matrix:
go-version: [1.23.x] # Use valid versions
os: [ubuntu-latest]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Install Dependencies
run: go mod tidy && go mod download
- name: Run Tests
run: make test
kind:
runs-on: ubuntu-latest
needs: [build,test] # Runs after the "build and test " job is completed
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.23 # Adjust as needed
- name: Set up Kubernetes with Kind
uses: helm/[email protected]
with:
cluster_name: kind-cluster
wait: 120s
- name: Verify Kubernetes Cluster
run: kubectl get nodes
- name: Label KinD Node as Linux
run: |
NODE_NAME=$(kubectl get nodes -o jsonpath='{.items[0].metadata.name}')
kubectl label node "$NODE_NAME" kubernetes.io/os=linux --overwrite
- name: Set up Local Registry
run: |
docker network inspect kind >/dev/null 2>&1 || docker network create kind
docker ps | grep kind-registry || docker run -d --restart=always -p 5000:5000 --name kind-registry registry:2
echo "Registry running at localhost:5000"
- name: Connect Registry to Kind
run: |
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: local-registry-hosting
namespace: kube-public
data:
localRegistryHosting.v1: |
host: "localhost:5000"
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
EOF
- name: Check registry status
run: |
docker logs kind-registry
- name: Check registry status
run: |
curl -v http://localhost:5000/v2/
- name: Check out the repo
uses: actions/checkout@v3
- name: build and push linuxptp-daemon image
run: |
docker build -f Dockerfile -t localhost:5000/ghaction-linuxptp-daemon:pr-${{github.event.pull_request.number}} .
docker push localhost:5000/ghaction-linuxptp-daemon:pr-${{github.event.pull_request.number}}
- name: Load Image into Kind Cluster
run: |
kind load docker-image localhost:5000/ghaction-linuxptp-daemon:pr-${{github.event.pull_request.number}} --name kind-cluster
- name: Set PR Number as Environment Variable
run: |
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
- name: Deploy to Kind
run: |
kubectl apply -f deploy/00-ns.yaml
kubectl apply -f deploy/01-sa.yaml
kubectl apply -f deploy/02-rbac.yaml
./hack/gen-configmap-data-source.sh
kubectl create configmap linuxptp-configmap -n openshift-ptp --from-file ./linuxptp-configmap
sed "s/{{PR_NUMBER}}/$PR_NUMBER/g" deploy/linuxptp-daemon.yaml > deployment-temp.yaml
kubectl apply -f deployment-temp.yaml
kubectl get pods -A
- name: Describe Pod for Debugging
run: |
kubectl describe pod -l app=linuxptp-daemon -n openshift-ptp || echo "Failed to describe pod"
- name: Check Image Pull Errors (Retry for 30s)
run: |
end=$((SECONDS+30))
while [ $SECONDS -lt $end ]; do
REASON=$(kubectl get pod -l app=linuxptp-daemon -n openshift-ptp -o jsonpath='{.items[0].status.containerStatuses[*].state.waiting.reason}')
echo "Container Creating Reason: $REASON"
if [ -z "$REASON" ]; then
echo "Container is running or initialized."
break
fi
sleep 5
done
- name: Wait for Logs (30s Timeout)
run: |
END=$((SECONDS+30))
while [ $SECONDS -lt $END ]; do
LOGS=$(kubectl logs ds/linuxptp-daemon -n openshift-ptp 2>/dev/null || echo "No logs yet")
echo "$LOGS"
if [[ "$LOGS" != "No logs yet" ]]; then
echo "Logs detected!"
exit 0
fi
echo "Waiting for logs..."
sleep 5
done
echo "Timeout reached, no logs found!"
exit 1
- name: Wait for DaemonSet to be Ready
run: |
kubectl rollout status ds/linuxptp-daemon -n openshift-ptp --timeout=180s
- name: Check DaemonSet Status
run: |
kubectl get daemonset linuxptp-daemon -n openshift-ptp -o wide
- name: Verify Pods in DaemonSet
run: |
kubectl get pods -n openshift-ptp -o wide
kubectl wait --for=condition=Ready pod -l app=linuxptp-daemon -n openshift-ptp --timeout=120s
- name: Cleanup Kind Cluster
if: always() # Ensures cleanup runs even if previous steps fail
run: kind delete cluster --name kind-cluster