Skip to content

Update 02-rbac.yaml #75

Update 02-rbac.yaml

Update 02-rbac.yaml #75

Workflow file for this run

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