From 52570696ce348c1dd01c22009b5e753729195c7d Mon Sep 17 00:00:00 2001 From: Alice Rum Date: Thu, 1 Jul 2021 12:01:45 +0200 Subject: [PATCH] BUILD-179: upgrade operator-sdk, github actions operator-sdk and controller-gen were both upgraded to latest released versions. Besides that, Makefile has been modified in order to introduce bundle operator image building, pushing and deploying. make ko-publish // create operator image and push to registry make bundle bundle-build bundle-push // create bundle image and push to registry Set `IMAGE_REPO` variable to push to a different registry Set `TAG` variable to change images tags (for example, use `latest` without changing the version in bundle manifest) --- .github/workflows/bundle.yml | 87 +++++++++++++++++++ .github/workflows/release.yaml | 41 +++++++++ .gitignore | 4 +- Makefile | 33 ++++--- PROJECT | 8 +- bundle.Dockerfile | 9 +- .../operator.clusterserviceversion.yaml | 7 +- ...erator.shipwright.io_shipwrightbuilds.yaml | 19 ++-- bundle/metadata/annotations.yaml | 11 ++- ...erator.shipwright.io_shipwrightbuilds.yaml | 2 +- config/manager/kustomization.yaml | 2 +- .../bases/operator.clusterserviceversion.yaml | 3 +- hack/install-operator-sdk.sh | 2 +- 13 files changed, 194 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/bundle.yml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/bundle.yml b/.github/workflows/bundle.yml new file mode 100644 index 000000000..abd13dc5b --- /dev/null +++ b/.github/workflows/bundle.yml @@ -0,0 +1,87 @@ +on: + pull_request: + branches: [ main ] + push: + branches: [ main ] +name: ci/github +jobs: + checksecret: + name: Check if REGISTRY_USERNAME is set in github secrets + runs-on: ubuntu-latest + outputs: + is_registry_username_set: ${{ steps.checksecret_job.outputs.is_registry_username_set }} + steps: + - name: Check if REGISTRY_USERNAME is set + id: checksecret_job + env: + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + run: | + echo "is_registry_username_set: ${{ env.REGISTRY_USERNAME != '' }}" + echo "::set-output name=is_registry_username_set::${{ env.REGISTRY_USERNAME != '' }}" + + bundle-build: + needs: [ checksecret ] + if: needs.checksecret.outputs.is_registry_username_set == 'true' + strategy: + fail-fast: false + matrix: + go-version: [ 1.16.x ] + os: [ ubuntu-latest ] + kubernetes: + - v1.20.7 + max-parallel: 2 + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Check out Code + uses: actions/checkout@v2 + - name: Install kubectl + uses: azure/setup-kubectl@v1 + with: + version: ${{ matrix.kubernetes }} + - name: Create kind cluster + uses: helm/kind-action@v1.1.0 + with: + version: v0.10.0 + node_image: kindest/node:${{ matrix.kubernetes }} + cluster_name: kind + wait: 120s + - name: Verify kind cluster + run: | + echo "# Using KinD context..." + kubectl config use-context "kind-kind" + echo "# KinD nodes:" + kubectl get nodes + - name: Login to the docker registry + env: + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + run: echo "$REGISTRY_PASSWORD" | docker login --username "$REGISTRY_USERNAME" --password-stdin quay.io + - name: Make and push Operator image + env: + IMAGE_REPO: quay.io/shipwright + TAG: pr-${{ github.event.number }} + run: | + make ko-publish IMAGE_REPO=ko.local + + docker tag ko.local/operator:${TAG} $IMAGE_REPO/operator-pr:${TAG} + docker push $IMAGE_REPO/operator-pr:${TAG} + - name: Make and push Bundle image + env: + IMAGE_REPO: quay.io/shipwright + TAG: pr-${{ github.event.number }} + BUNDLE_IMG_NAME: operator-bundle-pr + OPERATOR_IMG_NAME: operator-pr + run: | + make bundle-push + - name: Install OLM + run: ./bin/operator-sdk olm install + - name: Deploy Operator Bundle Image via subscription + env: + TAG: pr-${{ github.event.number }} + run: | + ./bin/operator-sdk run bundle \ + quay.io/shipwright/operator-bundle-pr:$TAG \ \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 000000000..109784b27 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,41 @@ +name: Release + +on: + workflow_dispatch: + inputs: + release: + description: 'Desired tag' + required: true + tags: + description: 'Previous tag' + required: true + +jobs: + release: + if: ${{ github.repository == 'shipwright-io/operator' }} + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Go + uses: actions/setup-go@v2 + + - name: Login to docker + env: + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + run: | + echo "$REGISTRY_PASSWORD" | docker login --username "$REGISTRY_USERNAME" --password-stdin + + - name: Build and upload Operator Image + env: + VERSION: ${{ github.events.input.release }} + run: | + make ko-publish + + - name: Build and upload Operator Bundle Image + env: + VERSION: ${{ github.events.input.release }} + run: | + make bundle-push diff --git a/.gitignore b/.gitignore index cde3eed61..0965be276 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ - # Binaries for programs and plugins *.exe *.exe~ @@ -8,6 +7,9 @@ bin testbin/* +# OS specific files +**/.DS_Store + # Test binary, build with `go test -c` *.test diff --git a/Makefile b/Makefile index 2eb658d4f..d46a872fc 100644 --- a/Makefile +++ b/Makefile @@ -24,10 +24,6 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) endif BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) -# BUNDLE_IMG defines the image:tag used for the bundle. -# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=/:) -BUNDLE_IMG ?= quay.io/shipwright/operator-bundle:$(VERSION) - # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false" @@ -40,9 +36,19 @@ endif CONTAINER_ENGINE ?= docker IMAGE_REPO ?= quay.io/shipwright -TAG ?= latest +TAG ?= $(VERSION) IMAGE_PUSH ?= true +BUNDLE_IMG_NAME ?= operator-bundle +OPERATOR_IMG_NAME ?= operator + +# Image URL to use all building/pushing image targets +IMG ?= $(IMAGE_REPO)/$(OPERATOR_IMG_NAME):$(TAG) + +# BUNDLE_IMG defines the image:tag used for the bundle. +# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=/:) +BUNDLE_IMG ?= $(IMAGE_REPO)/$(BUNDLE_IMG_NAME):$(TAG) + # operating-system type and architecture based on golang OS ?= $(shell go env GOOS) ARCH ?= $(shell go env GOARCH) @@ -74,7 +80,7 @@ uninstall: manifests kustomize # Deploy controller in the configured Kubernetes cluster in ~/.kube/config deploy: manifests kustomize - cd config/manager && $(KUSTOMIZE) edit set image controller="${IMAGE_REPO}/operator:${TAG}" + cd config/manager && $(KUSTOMIZE) edit set image controller="$(IMG)" $(KUSTOMIZE) build config/default | kubectl apply -f - # UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config @@ -85,9 +91,6 @@ undeploy: SED_BIN ?= sed manifests: controller-gen $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases - # Fix pluralization of ShipwrightBuilds in generated manifests - # This can be removed when operator-sdk is upgraded to v1.5.x - SED_BIN=${SED_BIN} hack/fix-plurals.sh # Verify manifests were generated and committed to git verify-manifests: manifests @@ -129,7 +132,7 @@ ko-publish: ko # Download controller-gen locally if necessary CONTROLLER_GEN = $(shell pwd)/bin/controller-gen controller-gen: - $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1) + $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.1) # Download kustomize locally if necessary KUSTOMIZE = $(shell pwd)/bin/kustomize @@ -159,15 +162,21 @@ endef .PHONY: bundle bundle: manifests kustomize operator-sdk $(OPERATOR_SDK) generate kustomize manifests -q - cd config/manager && $(KUSTOMIZE) edit set image controller="${IMAGE_REPO}/operator:${TAG}" + cd config/manager && $(KUSTOMIZE) edit set image controller="${IMG}" $(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) $(OPERATOR_SDK) bundle validate ./bundle + # Verify bundle manifests were generated and committed to git verify-bundle: bundle hack/check-git-status.sh bundle # Build the bundle image. .PHONY: bundle-build -bundle-build: +bundle-build: bundle $(CONTAINER_ENGINE) build -f bundle.Dockerfile -t $(BUNDLE_IMG) . + +# Push the bundle image to the registry +.PHONY: bundle-push +bundle-push: bundle-build + $(CONTAINER_ENGINE) push $(BUNDLE_IMG) \ No newline at end of file diff --git a/PROJECT b/PROJECT index f8f3bc133..a130003bf 100644 --- a/PROJECT +++ b/PROJECT @@ -3,11 +3,15 @@ layout: go.kubebuilder.io/v3 projectName: operator repo: github.com/shipwright-io/operator resources: -- crdVersion: v1 +- api: + crdVersion: v1 + controller: true + domain: shipwright.io group: operator kind: ShipwrightBuild + path: github.com/shipwright-io/operator/api/v1alpha1 version: v1alpha1 -version: 3-alpha +version: "3" plugins: manifests.sdk.operatorframework.io/v2: {} scorecard.sdk.operatorframework.io/v2: {} diff --git a/bundle.Dockerfile b/bundle.Dockerfile index 08069f004..68893ede1 100644 --- a/bundle.Dockerfile +++ b/bundle.Dockerfile @@ -1,15 +1,20 @@ FROM scratch +# Core bundle labels. LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ LABEL operators.operatorframework.io.bundle.package.v1=operator LABEL operators.operatorframework.io.bundle.channels.v1=alpha -LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.4.2 +LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.9.0+git LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1 LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3 -LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ + +# Labels for testing. LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1 +LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ + +# Copy files to locations specified by labels. COPY bundle/manifests /manifests/ COPY bundle/metadata /metadata/ COPY bundle/tests/scorecard /tests/scorecard/ diff --git a/bundle/manifests/operator.clusterserviceversion.yaml b/bundle/manifests/operator.clusterserviceversion.yaml index 6d79fc9b0..7d4b67a0d 100644 --- a/bundle/manifests/operator.clusterserviceversion.yaml +++ b/bundle/manifests/operator.clusterserviceversion.yaml @@ -16,7 +16,7 @@ metadata: } ] capabilities: Basic Install - operators.operatorframework.io/builder: operator-sdk-v1.4.2 + operators.operatorframework.io/builder: operator-sdk-v1.9.0+git operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 name: operator.v0.0.1 namespace: placeholder @@ -24,7 +24,8 @@ spec: apiservicedefinitions: {} customresourcedefinitions: owned: - - description: ShipwrightBuild represents the deployment of Shipwright's build controller on a Kubernetes cluster. + - description: ShipwrightBuild represents the deployment of Shipwright's build + controller on a Kubernetes cluster. displayName: Shipwright Build kind: ShipwrightBuild name: shipwrightbuilds.operator.shipwright.io @@ -241,7 +242,7 @@ spec: - --health-probe-bind-address=:8081 - --metrics-bind-address=127.0.0.1:8080 - --leader-elect - image: quay.io/shipwright/operator:latest + image: quay.io/shipwright/operator:0.0.1 livenessProbe: httpGet: path: /healthz diff --git a/bundle/manifests/operator.shipwright.io_shipwrightbuilds.yaml b/bundle/manifests/operator.shipwright.io_shipwrightbuilds.yaml index 35a1ea339..d173e5130 100644 --- a/bundle/manifests/operator.shipwright.io_shipwrightbuilds.yaml +++ b/bundle/manifests/operator.shipwright.io_shipwrightbuilds.yaml @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.4.1 + controller-gen.kubebuilder.io/version: v0.6.1 creationTimestamp: null name: shipwrightbuilds.operator.shipwright.io spec: @@ -17,21 +17,28 @@ spec: - name: v1alpha1 schema: openAPIV3Schema: - description: ShipwrightBuild represents the deployment of Shipwright's build controller on a Kubernetes cluster. + description: ShipwrightBuild represents the deployment of Shipwright's build + controller on a Kubernetes cluster. properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: type: object spec: - description: ShipwrightBuildSpec defines the configuration of a Shipwright Build deployment. + description: ShipwrightBuildSpec defines the configuration of a Shipwright + Build deployment. properties: targetNamespace: - description: TargetNamespace is the target namespace where Shipwright's build controller will be deployed. + description: TargetNamespace is the target namespace where Shipwright's + build controller will be deployed. type: string type: object status: diff --git a/bundle/metadata/annotations.yaml b/bundle/metadata/annotations.yaml index ef72008a4..6df32e056 100644 --- a/bundle/metadata/annotations.yaml +++ b/bundle/metadata/annotations.yaml @@ -1,11 +1,14 @@ annotations: - operators.operatorframework.io.bundle.channels.v1: alpha - operators.operatorframework.io.bundle.manifests.v1: manifests/ + # Core bundle annotations. operators.operatorframework.io.bundle.mediatype.v1: registry+v1 + operators.operatorframework.io.bundle.manifests.v1: manifests/ operators.operatorframework.io.bundle.metadata.v1: metadata/ operators.operatorframework.io.bundle.package.v1: operator - operators.operatorframework.io.metrics.builder: operator-sdk-v1.4.2 + operators.operatorframework.io.bundle.channels.v1: alpha + operators.operatorframework.io.metrics.builder: operator-sdk-v1.9.0+git operators.operatorframework.io.metrics.mediatype.v1: metrics+v1 operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3 - operators.operatorframework.io.test.config.v1: tests/scorecard/ + + # Annotations for testing. operators.operatorframework.io.test.mediatype.v1: scorecard+v1 + operators.operatorframework.io.test.config.v1: tests/scorecard/ diff --git a/config/crd/bases/operator.shipwright.io_shipwrightbuilds.yaml b/config/crd/bases/operator.shipwright.io_shipwrightbuilds.yaml index 781c5f616..6b1279888 100644 --- a/config/crd/bases/operator.shipwright.io_shipwrightbuilds.yaml +++ b/config/crd/bases/operator.shipwright.io_shipwrightbuilds.yaml @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.4.1 + controller-gen.kubebuilder.io/version: v0.6.1 creationTimestamp: null name: shipwrightbuilds.operator.shipwright.io spec: diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 39432e1c9..cd8898305 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -13,4 +13,4 @@ kind: Kustomization images: - name: controller newName: quay.io/shipwright/operator - newTag: latest + newTag: 0.0.1 diff --git a/config/manifests/bases/operator.clusterserviceversion.yaml b/config/manifests/bases/operator.clusterserviceversion.yaml index af9a33522..646f3b4db 100644 --- a/config/manifests/bases/operator.clusterserviceversion.yaml +++ b/config/manifests/bases/operator.clusterserviceversion.yaml @@ -10,7 +10,8 @@ spec: apiservicedefinitions: {} customresourcedefinitions: owned: - - description: ShipwrightBuild represents the deployment of Shipwright's build controller on a Kubernetes cluster. + - description: ShipwrightBuild represents the deployment of Shipwright's build + controller on a Kubernetes cluster. displayName: Shipwright Build kind: ShipwrightBuild name: shipwrightbuilds.operator.shipwright.io diff --git a/hack/install-operator-sdk.sh b/hack/install-operator-sdk.sh index a6a03bdaa..a2b7b6ee4 100755 --- a/hack/install-operator-sdk.sh +++ b/hack/install-operator-sdk.sh @@ -9,7 +9,7 @@ set -e DEST="${1:-bin/operator-sdk}" -SDK_VERSION="${SDK_VERSION:-1.4.2}" +SDK_VERSION="${SDK_VERSION:-1.9.1}" OS="${OS:-linux}" ARCH="${ARCH:-amd64}"