Skip to content

Commit

Permalink
Add CI Workflow for Building and Deploying Operator
Browse files Browse the repository at this point in the history
 - Add GitHub Actions workflow for building and
   deploying the checkpoint-restore-operator to
   the kind kubernetes cluster
 - Add verification workflows for linting and go
   module checks.

Signed-off-by: Parthiba-Hazra <parthibahazra@gmail.com>
  • Loading branch information
Parthiba-Hazra committed Jun 9, 2024
1 parent 4f69d8b commit da67cfe
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
# Check for updates to Go modules
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
58 changes: 58 additions & 0 deletions .github/workflows/quickstart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build and Deploy

on: [push, pull_request]

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21

- name: Install dependencies
run: |
# Install kind
curl -sLo kind "$(curl -sL https://github.com/gitapi/repos/kubernetes-sigs/kind/releases/latest | jq -r '[.assets[] | select(.name == "kind-linux-amd64")] | first | .browser_download_url')"
chmod +x kind
sudo mv kind /bin/
# Install kubectl
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /bin/
- name: Build Docker image
run: |
sudo -E docker build -t checkpoint-restore-operator:ci .
- name: Delete existing Kubernetes cluster (if any)
run: |
kind delete cluster || true
- name: Create Kubernetes cluster
run: |
kind create cluster
kind export kubeconfig
- name: Load Docker image into kind cluster
run: |
kind load docker-image checkpoint-restore-operator:ci
- name: Deploy to Kubernetes
run: |
make install
make deploy IMG=checkpoint-restore-operator:ci
- name: Add execute permissions to wait_for_deployment.sh
run: chmod +x ./test/wait_for_deployment.sh

- name: Wait for deployments to be ready
run: ./test/wait_for_deployment.sh checkpoint-restore-operator-controller-manager

- name: Check resources
run: kubectl get all -n checkpoint-restore-operator-system
70 changes: 70 additions & 0 deletions .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: verify

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=5m --out-format=colored-line-number
only-new-issues: true
- name: codespell
uses: codespell-project/actions-codespell@v2
with:
skip: vendor,*.svg

gomod:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
- name: verify go.mod/go.sum
run: |
make vendor
git diff --exit-code
- name: Upload go.sum diff if exists
if: failure()
uses: actions/upload-artifact@v3
with:
name: go-sum-diff
path: go.sum.diff

lint_markdown:
runs-on: ubuntu-latest
permissions:
pull-requests: read
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: changes
with:
base: 'main'
filters: |
md:
- 'README.md'
- '.github/workflows/verify.yml'
- name: Lint markdown
if: steps.changes.outputs.md == 'true'
uses: DavidAnson/markdownlint-cli2-action@v10
with:
globs: |
README.md
.github/workflows/verify.yml
- name: Upload Markdown lint results
if: failure()
uses: actions/upload-artifact@v3
with:
name: markdown-lint-results
path: .github/workflows/verify.yml.md-lint-results.txt
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ test: manifests generate fmt vet envtest ## Run tests.
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/main.go

.PHONY: vendor
vendor:
go mod tidy
go mod vendor
go mod verify

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/main.go
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/criu.org_checkpointrestoreoperators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ spec:
served: true
storage: true
subresources:
status: {}
status: {}
25 changes: 25 additions & 0 deletions test/wait_for_deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

wait_for_deployment() {
local deployment_name=$1
timeout=60
i=1
echo "Checking if the ${deployment_name} deployment is ready"
until kubectl -n checkpoint-restore-operator-system get deployment ${deployment_name} -o jsonpath='{.status.conditions[?(@.status=="True")].type}' | grep "Available" 2>/dev/null; do
((i++))
if [[ ${i} -gt ${timeout} ]]; then
echo "The ${deployment_name} deployment has not become ready before the timeout period"
echo "Fetching deployment status and describing pods for debugging:"
kubectl -n checkpoint-restore-operator-system get deployment ${deployment_name}
kubectl -n checkpoint-restore-operator-system describe deployment ${deployment_name}
kubectl -n checkpoint-restore-operator-system get pods
kubectl -n checkpoint-restore-operator-system describe pods
exit 1
fi
echo "Waiting for ${deployment_name} deployment to report a ready status"
sleep 5
done
echo "The ${deployment_name} deployment is ready"
}

wait_for_deployment $1

0 comments on commit da67cfe

Please sign in to comment.