diff --git a/.cruft.json b/.cruft.json new file mode 100644 index 0000000..25cd441 --- /dev/null +++ b/.cruft.json @@ -0,0 +1,20 @@ +{ + "template": "https://github.com/vshn/appcat-cookiecutter", + "commit": "5309ae05edb3c118e23e64e8ec0bed2b6768ac86", + "checkout": null, + "context": { + "cookiecutter": { + "app_name": "provider-minio", + "component_repo": "vshn/component-appcat", + "push_upbound": true, + "push_package": true, + "push_image": false, + "_copy_without_render": [ + ".github/workflows/cruft-update.yml", + ".github/changelog-configuration.json" + ], + "_template": "https://github.com/vshn/appcat-cookiecutter" + } + }, + "directory": null +} diff --git a/.github/changelog-configuration.json b/.github/changelog-configuration.json index 8c93e7b..02c9648 100644 --- a/.github/changelog-configuration.json +++ b/.github/changelog-configuration.json @@ -4,25 +4,19 @@ { "title": "## 🚀 Features", "labels": [ - "enhancement" - ] - }, - { - "title": "## 🛠️ Minor Changes", - "labels": [ - "change" + "minor" ] }, { "title": "## 🔎 Breaking Changes", "labels": [ - "breaking" + "major" ] }, { "title": "## 🐛 Fixes", "labels": [ - "bug" + "patch" ] }, { diff --git a/.github/workflows/cruft-update.yml b/.github/workflows/cruft-update.yml new file mode 100644 index 0000000..8f68d18 --- /dev/null +++ b/.github/workflows/cruft-update.yml @@ -0,0 +1,79 @@ +# /.github/workflows/cruft-update.yml +name: Update repository with Cruft +permissions: + contents: write + pull-requests: write + actions: write +on: + schedule: + - cron: "0 * * * *" # Once per hour + workflow_dispatch: {} + +jobs: + update: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + include: + - add-paths: . + body: Use this to merge the changes to this repository. + branch: cruft/update + commit-message: "chore: accept new Cruft update" + title: New updates detected with Cruft + - add-paths: .cruft.json + body: Use this to reject the changes in this repository. + branch: cruft/reject + commit-message: "chore: reject new Cruft update" + title: Reject new updates detected with Cruft + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.COMPONENT_ACCESS_TOKEN }} + + - uses: actions/setup-python@v5 + with: + python-version: "3.10" + + - name: Install Cruft + run: pip3 install cruft + + - name: Check if update is available + continue-on-error: false + id: check + run: | + CHANGES=0 + if [ -f .cruft.json ]; then + if ! cruft check; then + CHANGES=1 + fi + else + echo "No .cruft.json file" + fi + + echo "has_changes=$CHANGES" >> "$GITHUB_OUTPUT" + + - name: Run update if available + if: steps.check.outputs.has_changes == '1' + run: | + git config --global user.email "githubbot@vshn.ch" + git config --global user.name "GitHubBot" + + cruft update --skip-apply-ask --refresh-private-variables + git restore --staged . + + - name: Create pull request + if: steps.check.outputs.has_changes == '1' + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.COMPONENT_ACCESS_TOKEN }} + add-paths: ${{ matrix.add-paths }} + commit-message: ${{ matrix.commit-message }} + branch: ${{ matrix.branch }} + delete-branch: true + title: ${{ matrix.title }} + labels: dependency + body: | + This is an autogenerated PR. ${{ matrix.body }} + + [Cruft](https://cruft.github.io/cruft/) has detected updates from the Cookiecutter repository. diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..8f44024 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,217 @@ +name: PR Automation + +on: + pull_request: {} + pull_request_target: + types: + - closed + branches: + - master + +env: + APP_NAME: provider-minio + COMPONENT_REPO: vshn/component-appcat + PUSH_UPBOUND: "True" + PUSH_PACKAGE: "True" + PUSH_IMAGE: "False" + +jobs: + check-labels: + # Act doesn't set a pull request number by default, so we skip if it's 0 + if: github.event.pull_request.number != 0 + name: Check labels + runs-on: ubuntu-latest + steps: + - uses: docker://agilepathway/pull-request-label-checker:v1.6.51 + with: + one_of: major,minor,patch,documentation,dependency + repo_token: ${{ secrets.GITHUB_TOKEN }} + publish-branch-images: + if: github.event.action != 'closed' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Determine Go version from go.mod + run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV + + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - uses: actions/cache@v4 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Extract escaped branch name + shell: bash + run: echo "branch=$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | sed 's/\//_/g' )" >> $GITHUB_OUTPUT + id: extract_branch + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build branch and push image + if: env.PUSH_IMAGE == 'true' + run: make docker-push-branchtag -e IMG_TAG="${{ steps.extract_branch.outputs.branch }}" + + - name: Build branch and push package + if: env.PUSH_PACKAGE == 'True' + run: make package-push-branchtag -e IMG_TAG="${{ steps.extract_branch.outputs.branch }}" + + - name: Login to Upbound + if: env.PUSH_UPBOUND == 'true' + uses: docker/login-action@v3 + with: + registry: xpkg.upbound.io + username: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }} + password: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW }} + + - name: Build branch and push package to upbound + if: env.PUSH_UPBOUND == 'true' && env.PUSH_PACKAGE == 'true' + run: make package-push-branchtag -e IMG_TAG="${{ steps.extract_branch.outputs.branch }}" -e IMG_REPO=xpkg.upbound.io + + open-pr-component: + if: github.event.action == 'opened' + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + repository: ${{ env.COMPONENT_REPO }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract branch name + shell: bash + run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT + id: extract_branch + + - name: Update defaults.yml and create branch + run: | + yq e '.parameters.appcat.images.${{ env.APP_NAME }}.tag="${{ steps.extract_branch.outputs.branch }}"' class/defaults.yml | diff -B class/defaults.yml - | patch class/defaults.yml - || true + + git --no-pager diff + + - name: Generate new golden + # Act uses the host's docker to run containers, but then + # they can't access the files that were previously cloned. + if: github.event.pull_request.number != 0 + run: | + make gen-golden-all + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.COMPONENT_ACCESS_TOKEN }} + title: 'PR for ${{ env.APP_NAME }} on ${{ steps.extract_branch.outputs.branch }}' + body: "${{ github.event.pull_request.body}}\nLink: ${{ github.event.pull_request.url }}" + branch: "${{ env.APP_NAME }}/${{ github.event.pull_request.number }}/${{ steps.extract_branch.outputs.branch }}" + base: master + draft: false + create-release: + if: github.event.pull_request.merged + runs-on: ubuntu-latest + steps: + - name: Check for patch label + if: contains(github.event.pull_request.labels.*.name, 'patch') || contains(github.event.pull_request.labels.*.name, 'dependency') || contains(github.event.pull_request.labels.*.name, 'documentation') + id: patch + run: | + echo "set=true" >> $GITHUB_OUTPUT + - name: Check for minor label + if: contains(github.event.pull_request.labels.*.name, 'minor') + id: minor + run: | + echo "set=true" >> $GITHUB_OUTPUT + - name: Check for major label + if: contains(github.event.pull_request.labels.*.name, 'major') + id: major + run: | + echo "set=true" >> $GITHUB_OUTPUT + + - uses: actions/checkout@v4 + with: + # Make sure we use the right commit to tag + ref: ${{ github.event.pull_request.merge_commit_sha }} + # We also need to use the personal access token here. As subsequent + # actions will not trigger by tags/pushes that use `GITHUB_TOKEN` + # https://github.com/orgs/community/discussions/25702#discussioncomment-3248819 + token: ${{ secrets.COMPONENT_ACCESS_TOKEN }} + # This is broken in checkout@v4... + # https://github.com/actions/checkout/issues/1781 + fetch-tags: true + + - name: fetch tags + run: | + git fetch --tags + echo "latest tag: $(git describe --tags "$(git rev-list --tags --max-count=1)")" + echo "TAG_VERSION=$(git describe --tags "$(git rev-list --tags --max-count=1)")" >> $GITHUB_ENV + + - name: Extract branch name + shell: bash + run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT + id: extract_branch + + # We only run this if any of the release tags is set. + # For docs and deps we don't do automagic releases + - name: Increase Tag + id: tag + run: | + patch=${{ steps.patch.outputs.set }} + minor=${{ steps.minor.outputs.set }} + major=${{ steps.major.outputs.set }} + + major_ver=$(echo '${{ env.TAG_VERSION }}' | cut -d "." -f1) + minor_ver=$(echo '${{ env.TAG_VERSION }}' | cut -d "." -f2) + patch_ver=$(echo '${{ env.TAG_VERSION }}' | cut -d "." -f3) + + major_ver="${major_ver:1}" + + # Check for patch label + [ ! -z "$patch" ] && [ -z "$minor" ] && [ -z "$major" ] && ((patch_ver++)) || true + + # check for minor label + if [ ! -z "$minor" ] && [ -z "$major" ]; then + ((minor_ver++)) + patch_ver=0 + fi + + # Check for major label + if [ ! -z "$major" ]; then + ((major_ver++)) + minor_ver=0 + patch_ver=0 + fi + + tag="v$major_ver.$minor_ver.$patch_ver" + echo "new tag $tag" + git tag $tag + git push --tags + echo tag=$tag >> $GITHUB_OUTPUT + + - name: Checkout component + uses: actions/checkout@v4 + with: + repository: ${{ env.COMPONENT_REPO }} + token: ${{ secrets.COMPONENT_ACCESS_TOKEN }} + ref: "${{ env.APP_NAME }}/${{ github.event.pull_request.number }}/${{ steps.extract_branch.outputs.branch }}" + + - name: Update tag and run golden + run: | + yq e '.parameters.appcat.images.${{ env.APP_NAME }}.tag="${{ steps.tag.outputs.tag }}"' class/defaults.yml | diff -B class/defaults.yml - | patch class/defaults.yml - || true + make gen-golden-all + + - name: Commit & Push changes + uses: actions-js/push@master + with: + github_token: ${{ secrets.COMPONENT_ACCESS_TOKEN }} + branch: "${{ env.APP_NAME }}/${{ github.event.pull_request.number }}/${{ steps.extract_branch.outputs.branch }}" + message: "Update tag" + repository: ${{ env.COMPONENT_REPO }} + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dbd4a71..85d06bc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,69 +5,88 @@ on: tags: - "*" +env: + APP_NAME: provider-minio + PUSH_UPBOUND: "True" + PUSH_PACKAGE: "True" + PUSH_IMAGE: "False" + SUFFIX: "/controller" + jobs: - goreleaser: + dist: runs-on: ubuntu-latest steps: - - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 + + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Determine Go version from go.mod - run: echo "GO_VERSION=$(go mod edit -json | jq -r .Go)" >> $GITHUB_ENV + run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go- + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Push docker image + if: env.PUSH_IMAGE == 'true' + run: make docker-push -e IMG_TAG=${GITHUB_REF##*/} -e APP_NAME=${{ env.APP_NAME }} + + - name: Build and push function package + if: env.PUSH_PACKAGE == 'true' + run: make package-push -e IMG_TAG=${GITHUB_REF##*/} -e APP_NAME=${{ env.APP_NAME }} + - name: Login to Upbound - uses: docker/login-action@v2 + if: env.PUSH_UPBOUND == 'true' + uses: docker/login-action@v3 with: registry: xpkg.upbound.io username: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }} password: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW }} - - name: Login to ghcr.io - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Push package image - run: make package-push -e IMG_TAG=${GITHUB_REF##*/} + - name: Build branch and push package to upbound + if: env.PUSH_UPBOUND == 'true' && env.PUSH_PACKAGE == 'true' + run: make package-push -e IMG_TAG=${GITHUB_REF##*/} -e APP_NAME=${{ env.APP_NAME }} -e IMG_REPO=xpkg.upbound.io - name: Build changelog from PRs with labels id: build_changelog - uses: mikepenz/release-changelog-builder-action@v4 + uses: mikepenz/release-changelog-builder-action@v5 with: configuration: ".github/changelog-configuration.json" # PreReleases still get a changelog, but the next full release gets a diff since the last full release, - # combining possible changelogs of all previous PreReleases in between. - # PreReleases show a partial changelog since last PreRelease. + # combining possible changelogs of all previous PreReleases in between. PreReleases show a partial changelog + # since last PreRelease. ignorePreReleases: "${{ !contains(github.ref, '-rc') }}" outputFile: .github/release-notes.md env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Publish releases - uses: goreleaser/goreleaser-action@v4 + uses: goreleaser/goreleaser-action@v6 with: args: release --release-notes .github/release-notes.md env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CONTAINER_REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }}/controller + IMAGE_NAME: ${{ github.repository }}${{ env.SUFFIX }} + diff --git a/.gitignore b/.gitignore index 501a249..4ca2705 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ /provider-minio *.out /package/*.xpkg -/package/crossplane.yaml /kubeconfig __debug* @@ -17,4 +16,5 @@ __debug* # work /.work/ -.vscode/ \ No newline at end of file +.vscode/ +.kind diff --git a/Makefile b/Makefile index 1ac953c..da299d0 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,8 @@ include Makefile.vars.mk # Other makefiles include kind/kind.mk -include package/package.mk include test/local.mk +-include ci.mk # Following includes do not print warnings or error if files aren't found # Optional Documentation module. @@ -27,19 +27,13 @@ help: ## Show this help @grep -E -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' .PHONY: build -build: build-bin build-docker ## All-in-one build +build: build-bin docker-build ## All-in-one build .PHONY: build-bin build-bin: export CGO_ENABLED = 0 build-bin: fmt vet ## Build binary @go build -o $(BIN_FILENAME) . -.PHONY: build-docker -build-docker: build-bin ## Build docker image - env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ - go build -o ${BIN_FILENAME} - $(DOCKER_CMD) build -t $(CONTAINER_IMG) . - .PHONY: test test: test-go ## All-in-one test @@ -73,7 +67,7 @@ generate: ## Generate additional code and artifacts .PHONY: clean clean: kind-clean ## Cleans local build artifacts - docker rmi $(CONTAINER_IMG) || true + docker rmi $(IMG) || true rm -rf docs/node_modules $(docs_out_dir) dist .cache $(WORK_DIR) $(golangci_bin): | $(go_bin) diff --git a/Makefile.vars.mk b/Makefile.vars.mk index 5a97da0..df6e22e 100644 --- a/Makefile.vars.mk +++ b/Makefile.vars.mk @@ -14,21 +14,16 @@ $(go_bin): ## BUILD:docker DOCKER_CMD ?= docker -CONTAINER_REGISTRY ?= ghcr.io -UPBOUND_CONTAINER_REGISTRY ?= xpkg.upbound.io GIT_TAG = $(shell git symbolic-ref -q --short HEAD || git describe --tags --exact-match) IMG_TAG = $(subst /,_,$(GIT_TAG)) # Image URL to use all building/pushing image targets -CONTAINER_IMG ?= $(CONTAINER_REGISTRY)/$(PROJECT_OWNER)/$(PROJECT_NAME)/controller:$(IMG_TAG) LOCAL_PACKAGE_IMG = localhost:5000/$(PROJECT_OWNER)/$(PROJECT_NAME)/package:$(IMG_TAG) -GHCR_PACKAGE_IMG ?= $(CONTAINER_REGISTRY)/$(PROJECT_OWNER)/$(PROJECT_NAME)/provider:$(IMG_TAG) -UPBOUND_PACKAGE_IMG ?= $(UPBOUND_CONTAINER_REGISTRY)/$(PROJECT_OWNER)/$(PROJECT_NAME):$(IMG_TAG) ## KIND:setup # https://hub.docker.com/r/kindest/node/tags -KIND_NODE_VERSION ?= v1.26.6 +KIND_NODE_VERSION ?= v1.28.9 KIND_IMAGE ?= docker.io/kindest/node:$(KIND_NODE_VERSION) KIND ?= go run sigs.k8s.io/kind KIND_KUBECONFIG ?= $(kind_dir)/kind-kubeconfig diff --git a/ci.mk b/ci.mk new file mode 100644 index 0000000..719fd55 --- /dev/null +++ b/ci.mk @@ -0,0 +1,63 @@ +# Image URL to use all building/pushing image targets +IMG_TAG ?= latest +APP_NAME ?= provider-minio +ORG ?= vshn +IMG_REPO ?= ghcr.io +IMG ?= $(IMG_REPO)/$(ORG)/$(APP_NAME):$(IMG_TAG) +DOCKER_CMD ?= docker + +# Upbound push config +UPBOUND_CONTAINER_REGISTRY ?= xpkg.upbound.io +UPBOUND_PACKAGE_IMG ?= $(UPBOUND_CONTAINER_REGISTRY)/$(ORG)/$(APP_NAME):$(IMG_TAG) + +# For alpine image it is required the following env before building the application +DOCKER_IMAGE_GOOS = linux +DOCKER_IMAGE_GOARCH = amd64 + +.PHONY: docker-build +docker-build: + env CGO_ENABLED=0 GOOS=$(DOCKER_IMAGE_GOOS) GOARCH=$(DOCKER_IMAGE_GOARCH) \ + go build -o ${BIN_FILENAME} + docker build --platform $(DOCKER_IMAGE_GOOS)/$(DOCKER_IMAGE_GOARCH) -t ${IMG} . + +.PHONY: docker-build-branchtag +docker-build-branchtag: export IMG_TAG=$(shell git rev-parse --abbrev-ref HEAD | sed 's/\//_/g') +docker-build-branchtag: docker-build ## Build docker image with current branch name + +.PHONY: docker-push +docker-push: docker-build ## Push docker image with the manager. + docker push ${IMG} + +.PHONY: docker-push-branchtag +docker-push-branchtag: export IMG_TAG=$(shell git rev-parse --abbrev-ref HEAD | sed 's/\//_/g') +docker-push-branchtag: docker-build-branchtag docker-push ## Push docker image with current branch name + +.PHONY: package-build +package-build: docker-build + rm -f package/*.xpkg + go run github.com/crossplane/crossplane/cmd/crank@v1.16.0 xpkg build -f package --verbose --embed-runtime-image=${IMG} -o package/package.xpkg + +.PHONY: package-push +package-push: package-build + go run github.com/crossplane/crossplane/cmd/crank@v1.16.0 xpkg push -f package/package.xpkg ${IMG} --verbose + +.PHONY: package-build-branchtag +package-build-branchtag: export IMG_TAG=$(shell git rev-parse --abbrev-ref HEAD | sed 's/\//_/g') +package-build-branchtag: docker-build-branchtag package-build + +.PHONY: package-push-package-branchtag +package-push-package-branchtag: export IMG_TAG=$(shell git rev-parse --abbrev-ref HEAD | sed 's/\//_/g') +package-push-branchtag: package-build-branchtag package-push + +.PHONY: docker-build-local +docker-build-local: export IMG_REPO=localhost:5000 +docker-build-local: + $(MAKE) docker-build + +.PHONY: package-build-local +package-build-local: export IMG_REPO=localhost:5000 +package-build-local: docker-build-local package-build + +.PHONY: package-push-local +package-push-local: export IMG_REPO=localhost:5000 +package-push-local: package-build-local package-push diff --git a/kind/config.yaml b/kind/config.yaml index e84013b..abc6243 100644 --- a/kind/config.yaml +++ b/kind/config.yaml @@ -1,5 +1,9 @@ kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 +containerdConfigPatches: + - |- + [plugins."io.containerd.grpc.v1.cri".registry] + config_path = "/etc/containerd/certs.d" nodes: - role: control-plane kubeadmConfigPatches: diff --git a/kind/kind.mk b/kind/kind.mk index f849565..3a8e312 100644 --- a/kind/kind.mk +++ b/kind/kind.mk @@ -1,4 +1,4 @@ -kind_dir ?= $(WORK_DIR)/kind +kind_dir ?= $(PWD)/.kind kind_bin = $(go_bin)/kind # Prepare kind binary @@ -8,8 +8,7 @@ $(kind_bin): export GOBIN = $(go_bin) $(kind_bin): | $(go_bin) go install sigs.k8s.io/kind@latest -$(kind_dir): - @mkdir -p $@ +mirror_sentinel = $(kind_dir)/mirror_sentinel .PHONY: kind kind: export KUBECONFIG = $(KIND_KUBECONFIG) @@ -21,24 +20,25 @@ kind-setup: $(KIND_KUBECONFIG) ## Creates the kind cluster .PHONY: kind-setup-ingress kind-setup-ingress: export KUBECONFIG = $(KIND_KUBECONFIG) -kind-setup-ingress: kind-setup ## Install NGINX as ingress controller onto kind cluster (localhost:8081) +kind-setup-ingress: kind-setup ## Install NGINX as ingress controller onto kind cluster (localhost:8088) kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml .PHONY: kind-load-image # We fix the arch to linux/amd64 since kind runs in amd64 even on Mac/arm. kind-load-image: export GOOS = linux kind-load-image: export GOARCH = amd64 -kind-load-image: kind-setup build-docker ## Load the container image onto kind cluster - @$(kind_bin) load docker-image --name $(KIND_CLUSTER) $(CONTAINER_IMG) +kind-load-image: kind-setup docker-build ## Load the container image onto kind cluster + @$(kind_bin) load docker-image --name $(KIND_CLUSTER) $(IMG) .PHONY: kind-clean kind-clean: export KUBECONFIG = $(KIND_KUBECONFIG) kind-clean: ## Removes the kind Cluster @$(kind_bin) delete cluster --name $(KIND_CLUSTER) || true - @rm -rf $(kind_dir) $(kind_bin) + docker rm -f kind-registry + rm -rf $(kind_dir) $(kind_bin) $(KIND_KUBECONFIG): export KUBECONFIG = $(KIND_KUBECONFIG) -$(KIND_KUBECONFIG): $(kind_bin) | $(kind_dir) +$(KIND_KUBECONFIG): $(kind_bin) $(kind_bin) create cluster \ --name $(KIND_CLUSTER) \ --image $(KIND_IMAGE) \ @@ -50,3 +50,19 @@ $(KIND_KUBECONFIG): $(kind_bin) | $(kind_dir) @echo "Setup finished. To interact with the local dev cluster, set the KUBECONFIG environment variable as follows:" @echo "export KUBECONFIG=$$(realpath "$(KIND_KUBECONFIG)")" @echo ======= + +.PHONY: mirror-setup +mirror-setup: $(mirror_sentinel) ## Installs an image registry required for the package image in kind cluster. + +$(mirror_sentinel): export KUBECONFIG = $(KIND_KUBECONFIG) +$(mirror_sentinel): + + REGISTRY_DIR="/etc/containerd/certs.d/registry.registry-system.svc.cluster.local:5000" && \ + REGISTRY_HOST='[host."http://localhost:30500"]' && \ + for node in $$(kind get nodes -n $(KIND_CLUSTER)); do \ + echo $$node ; \ + docker exec "$${node}" mkdir -p "$${REGISTRY_DIR}" ; \ + echo "$${REGISTRY_HOST}" | docker exec -i "$${node}" cp /dev/stdin "$${REGISTRY_DIR}/hosts.toml" ; \ + done + + @touch $@ diff --git a/package/crossplane.yaml.template b/package/crossplane.yaml similarity index 94% rename from package/crossplane.yaml.template rename to package/crossplane.yaml index ac5b544..5ed81c6 100644 --- a/package/crossplane.yaml.template +++ b/package/crossplane.yaml @@ -17,7 +17,6 @@ metadata: [vshn/provider-minio](https://github.com/vshn/provider-minio/issues) repo. spec: controller: - image: ghcr.io/vshn/provider-minio/controller:latest permissionRequests: [] crossplane: version: ">=v1.9.0" diff --git a/package/package.mk b/package/package.mk deleted file mode 100644 index 8433f5c..0000000 --- a/package/package.mk +++ /dev/null @@ -1,53 +0,0 @@ - - -mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) -package_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path)))) - -crossplane_bin = $(go_bin)/kubectl-crossplane - -# Build kubectl-crossplane plugin -$(crossplane_bin):export GOBIN = $(go_bin) -$(crossplane_bin): | $(go_bin) - go install github.com/crossplane/crossplane/cmd/crank@latest - @mv $(go_bin)/crank $@ - -.PHONY: package -package: ## All-in-one packaging and releasing -package: package-push - -.PHONY: package-provider-local -package-provider-local: export CONTROLLER_IMG = $(CONTAINER_IMG) -package-provider-local: $(crossplane_bin) generate ## Build Crossplane package for local installation in kind-cluster - @rm -rf package/*.xpkg - @yq e '.spec.controller.image=strenv(CONTROLLER_IMG)' $(package_dir)/crossplane.yaml.template > $(package_dir)/crossplane.yaml - @$(crossplane_bin) xpkg build -f $(package_dir) - @echo Package file: $$(ls $(package_dir)/*.xpkg) - -.PHONY: package-provider -package-provider: export CONTROLLER_IMG = $(CONTAINER_IMG) -package-provider: $(crossplane_bin) generate build-docker ## Build Crossplane package for Upbound Marketplace - @rm -rf package/*.xpkg - @yq e 'del(.spec)' $(package_dir)/crossplane.yaml.template > $(package_dir)/crossplane.yaml - $(crossplane_bin) xpkg build --package-root=$(package_dir) --embed-runtime-image=$(CONTROLLER_IMG) -o $(package_dir)/provider-minio.xpkg - -.PHONY: .local-package-push -.local-package-push: pkg_file = $(shell ls $(package_dir)/*.xpkg) -.local-package-push: $(crossplane_bin) package-provider-local - $(crossplane_bin) xpkg push -f $(pkg_file) $(LOCAL_PACKAGE_IMG) - -.PHONY: .ghcr-package-push -.ghcr-package-push: pkg_file = $(package_dir)/provider-minio.xpkg -.ghcr-package-push: $(crossplane_bin) package-provider - $(crossplane_bin) xpkg push -f $(pkg_file) $(GHCR_PACKAGE_IMG) - -.PHONY: .upbound-package-push -.upbound-package-push: pkg_file = $(package_dir)/provider-minio.xpkg -.upbound-package-push: package-provider - $(crossplane_bin) xpkg push -f $(pkg_file) $(UPBOUND_PACKAGE_IMG) - -.PHONY: package-push -package-push: .ghcr-package-push .upbound-package-push ## Push Crossplane package to container registries - -.PHONY: .package-clean -.package-clean: - rm -f $(crossplane_bin) package/*.xpkg diff --git a/test/local.mk b/test/local.mk index 332289c..09b39af 100644 --- a/test/local.mk +++ b/test/local.mk @@ -10,10 +10,10 @@ INTEGRATION_TEST_DEBUG_OUTPUT ?= false .PHONY: local-install local-install: export KUBECONFIG = $(KIND_KUBECONFIG) # for ControllerConfig: -local-install: export INTERNAL_PACKAGE_IMG = registry.registry-system.svc.cluster.local:5000/$(PROJECT_OWNER)/$(PROJECT_NAME)/package:$(IMG_TAG) -local-install: kind-load-image crossplane-setup registry-setup .local-package-push minio-setup ## Install Operator in local cluster +local-install: export INTERNAL_PACKAGE_IMG = registry.registry-system.svc.cluster.local:5000/$(ORG)/$(APP_NAME):$(IMG_TAG) +local-install: kind-load-image crossplane-setup registry-setup minio-setup mirror-setup package-push-local ## Install Operator in local cluster yq e '.spec.metadata.annotations."local.dev/installed"="$(shell date)"' test/controllerconfig-minio.yaml | kubectl apply -f - - yq e '.spec.package=strenv(INTERNAL_PACKAGE_IMG)' test/provider-minio.yaml | kubectl apply -f - + yq e '.spec.package="${INTERNAL_PACKAGE_IMG}"' test/provider-minio.yaml | kubectl apply -f - kubectl wait --for condition=Healthy provider.pkg.crossplane.io/provider-minio --timeout 60s kubectl -n crossplane-system wait --for condition=Ready $$(kubectl -n crossplane-system get pods -o name -l pkg.crossplane.io/provider=provider-minio) --timeout 60s @@ -127,10 +127,7 @@ $(webhook_cert): $(webhook_key) ### with KUTTL (https://kuttl.dev) ### -kuttl_bin = $(go_bin)/kubectl-kuttl -$(kuttl_bin): export GOBIN = $(go_bin) -$(kuttl_bin): | $(go_bin) - go install github.com/kudobuilder/kuttl/cmd/kubectl-kuttl@latest +kuttl_bin = go run github.com/kudobuilder/kuttl/cmd/kubectl-kuttl@main mc_bin = $(go_bin)/mc $(mc_bin): export GOBIN = $(go_bin) @@ -138,7 +135,7 @@ $(mc_bin): | $(go_bin) go install github.com/minio/mc@latest test-e2e: export KUBECONFIG = $(KIND_KUBECONFIG) -test-e2e: $(kuttl_bin) $(mc_bin) local-install provider-config install-crd ## E2E tests +test-e2e: $(mc_bin) local-install provider-config install-crd ## E2E tests # let's give the provider some time to properly start. # Especially the webhooks can take a bit longer to be ready and then cause the whole run to fail sleep 5