diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 00000000..f1b219b4 --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 00000000..5c5a8086 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,48 @@ +name: Build and Deploy + +on: [push, pull_request] + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Install dependencies + run: | + # Install kind + curl -sLo kind "$(curl -sL https://api.github.com/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: Create Kubernetes cluster + run: | + kind create cluster + kind export kubeconfig + + - name: Load Docker image into kind cluster + run: | + make docker-build IMG=checkpoint-restore-operator:ci + kind load docker-image checkpoint-restore-operator:ci + + - name: Deploy to Kubernetes + run: | + make install + make deploy IMG=checkpoint-restore-operator:ci + + - 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 diff --git a/.github/workflows/verify.yaml b/.github/workflows/verify.yaml new file mode 100644 index 00000000..c6f4ad3c --- /dev/null +++ b/.github/workflows/verify.yaml @@ -0,0 +1,74 @@ +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@v5 + with: + go-version: '1.21' + + - name: Install ShellCheck and shfmt + run: | + sudo apt update + sudo apt install -y shellcheck shfmt + + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: latest + only-new-issues: true + args: --timeout=5m + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: codespell + uses: codespell-project/actions-codespell@v2 + with: + skip: vendor,*.svg + + - name: ShellCheck and shfmt + run: | + shellcheck ./test/*.sh + shfmt -d ./test/*.sh + + gomod: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.21' + + - name: verify go.mod/go.sum + run: | + make vendor + git diff --exit-code + + 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 diff --git a/Makefile b/Makefile index 58e7ec6d..9fc9592e 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/test/wait_for_deployment.sh b/test/wait_for_deployment.sh new file mode 100755 index 00000000..9b72d28d --- /dev/null +++ b/test/wait_for_deployment.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +wait_for_deployment() { + local deployment_name="$1" + timeout=60 # 5 minutes (60 * 5 sec) + 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"