From e5c71d00289bf2cbad41b2dbff084ecadb72be24 Mon Sep 17 00:00:00 2001 From: Isaac Dorfman Date: Tue, 10 May 2022 17:08:19 +0300 Subject: [PATCH 1/2] clusterctl integration --- .github/workflows/create_release.yaml | 73 +++++++++++++++++++++++++ .gitignore | 1 + Makefile | 20 +++++-- clusterctl-settings.json | 2 +- config/crd/kustomization.yaml | 5 ++ config/default/kustomization.yaml | 7 ++- config/default/manager_image_patch.yaml | 2 +- config/kubevirtci/kustomization.yaml | 7 ++- config/manager/kustomization.yaml | 2 +- e2e/create-cluster_test.go | 2 +- metadata.yaml | 2 +- 11 files changed, 111 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/create_release.yaml diff --git a/.github/workflows/create_release.yaml b/.github/workflows/create_release.yaml new file mode 100644 index 000000000..075eeb1a8 --- /dev/null +++ b/.github/workflows/create_release.yaml @@ -0,0 +1,73 @@ +on: + push: + tags: + - "v*" + +name: Upload Release Asset + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: build image + shell: bash + env: + QUAY_TOKEN: ${{secrets.QUAY_TOKEN}} + REGISTRY: "quay.io/capk" + TAG: ${{ github.ref_name }} + run: | + echo $QUAY_TOKEN | docker login -u="capk+capk_robot" quay.io --password-stdin + make docker-build + make docker-push + build: + name: Upload Release Asset + needs: build-and-push-image + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: '1.17' + - name: Install kustomize + run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash + - name: Create infrastructure components + env: + REGISTRY: "quay.io/capk" + IMAGE_NAME: "capk-manager-amd64" + TAG: ${{ github.ref_name }} + run: | + make create-infrastructure-components + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + - name: Upload infrastructure-components.yaml + id: upload-infrastructure-components + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps + asset_path: ./infrastructure-components.yaml + asset_name: infrastructure-components.yaml + asset_content_type: text/plain + - name: Upload metadata.yaml + id: upload-metadata + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps + asset_path: ./metadata.yaml + asset_name: metadata.yaml + asset_content_type: text/plain \ No newline at end of file diff --git a/.gitignore b/.gitignore index 04cb57a9d..b3107d924 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ cluster-up/ hack/tools/bin/ bin/ .idea/ +infrastructure-components.yaml \ No newline at end of file diff --git a/Makefile b/Makefile index 1809f7905..4ccb1ef84 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ # If you update this file, please follow: # https://suva.sh/posts/well-documented-makefiles/ -ROOT = $$GOPATH/pkg/mod/sigs.k8s.io/cluster-api@v0.3.11-0.20210525210043-6c7878e7b4a9 +ROOT = $$(go env GOPATH)/pkg/mod/sigs.k8s.io/cluster-api@v0.3.11-0.20210525210043-6c7878e7b4a9 .DEFAULT_GOAL:=help TARGET ?= target @@ -50,10 +50,8 @@ endif CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/controller-gen) CONVERSION_GEN := $(abspath $(TOOLS_BIN_DIR)/conversion-gen) GOTESTSUM := $(abspath $(TOOLS_BIN_DIR)/gotestsum) -KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/kustomize) - -$(KUSTOMIZE): # Build kustomize from tools folder. - $(MAKE) -C $(ROOT) kustomize +KUSTOMIZE_IMAGE = k8s.gcr.io/kustomize/kustomize:v3.8.7 +KUSTOMIZE ?= docker run $(KUSTOMIZE_IMAGE) # Define Docker related variables. Releases should modify and double check these vars. REGISTRY ?= 127.0.0.1:5000 @@ -244,6 +242,18 @@ else sed -i -e 's@imagePullPolicy: .*@imagePullPolicy: '"$(PULL_POLICY)"'@' ./config/default/manager_pull_policy.yaml endif +## -------------------------------------- +## Deployment +## -------------------------------------- +##> infrastructure-components.yaml +set_controller_image: + echo setting controller image to be ${CONTROLLER_IMG}:${TAG} + cd config/default && kustomize edit set image controller=${CONTROLLER_IMG}:${TAG} + +create-infrastructure-components: generate-manifests set_controller_image + kustomize build config/default > infrastructure-components.yaml + + ## -------------------------------------- ## Cleanup / Verification ## -------------------------------------- diff --git a/clusterctl-settings.json b/clusterctl-settings.json index 7f22cd69e..9a0b7e406 100644 --- a/clusterctl-settings.json +++ b/clusterctl-settings.json @@ -1,5 +1,5 @@ { - "name": "infrastructure-kubevirt", + "name": "kubevirt", "config": { "componentsFile": "infrastructure-components.yaml", "nextVersion": "v0.1.0" diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 81b7d4569..bcaede6b6 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -1,4 +1,9 @@ commonLabels: + cluster.x-k8s.io/provider: kubevirt + cluster.x-k8s.io/v1alpha1: v1alpha1 + cluster.x-k8s.io/v1alpha2: v1alpha1 + cluster.x-k8s.io/v1alpha3: v1alpha1 + cluster.x-k8s.io/v1alpha4: v1alpha1 cluster.x-k8s.io/v1beta1: v1alpha1 # This kustomization.yaml is not intended to be run by itself, diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index d9bbb1f63..035dc18e8 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -3,7 +3,12 @@ namespace: capk-system namePrefix: capk- commonLabels: - cluster.x-k8s.io/provider: "infrastructure-kubevirt" + cluster.x-k8s.io/provider: "kubevirt" + cluster.x-k8s.io/v1alpha1: v1alpha1 + cluster.x-k8s.io/v1alpha2: v1alpha1 + cluster.x-k8s.io/v1alpha3: v1alpha1 + cluster.x-k8s.io/v1alpha4: v1alpha1 + cluster.x-k8s.io/v1beta1: v1alpha1 resources: - namespace.yaml diff --git a/config/default/manager_image_patch.yaml b/config/default/manager_image_patch.yaml index 25419e08c..d14d9f922 100644 --- a/config/default/manager_image_patch.yaml +++ b/config/default/manager_image_patch.yaml @@ -8,5 +8,5 @@ spec: spec: containers: # Change the value of image field below to your controller image URL - - image: gcr.io/k8s-staging-cluster-api/capk-manager:dev + - image: controller name: manager diff --git a/config/kubevirtci/kustomization.yaml b/config/kubevirtci/kustomization.yaml index d9bbb1f63..035dc18e8 100644 --- a/config/kubevirtci/kustomization.yaml +++ b/config/kubevirtci/kustomization.yaml @@ -3,7 +3,12 @@ namespace: capk-system namePrefix: capk- commonLabels: - cluster.x-k8s.io/provider: "infrastructure-kubevirt" + cluster.x-k8s.io/provider: "kubevirt" + cluster.x-k8s.io/v1alpha1: v1alpha1 + cluster.x-k8s.io/v1alpha2: v1alpha1 + cluster.x-k8s.io/v1alpha3: v1alpha1 + cluster.x-k8s.io/v1alpha4: v1alpha1 + cluster.x-k8s.io/v1beta1: v1alpha1 resources: - namespace.yaml diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 5c5f0b84c..2e6cc7976 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,2 +1,2 @@ resources: -- manager.yaml +- manager.yaml \ No newline at end of file diff --git a/e2e/create-cluster_test.go b/e2e/create-cluster_test.go index 9c57b3290..fe3cda5be 100644 --- a/e2e/create-cluster_test.go +++ b/e2e/create-cluster_test.go @@ -259,7 +259,7 @@ var _ = Describe("CreateCluster", func() { } return nil - }, 10*time.Minute, 5*time.Second).Should(Succeed(), "cluster should have control plane initialized") + }, 20*time.Minute, 5*time.Second).Should(Succeed(), "cluster should have control plane initialized") By("Waiting on cluster's control plane to be ready") Eventually(func() error { diff --git a/metadata.yaml b/metadata.yaml index 1045d3d75..0fe4fb548 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -6,6 +6,6 @@ apiVersion: clusterctl.cluster.x-k8s.io/v1alpha3 kind: Metadata releaseSeries: - - major: 0 + - major: 1 minor: 1 contract: v1beta1 From 7f597e1cff22843691817bf88c77e1495f18ef0d Mon Sep 17 00:00:00 2001 From: Isaac Dorfman Date: Tue, 10 May 2022 17:08:25 +0300 Subject: [PATCH 2/2] Fixed a linting problem --- controllers/kubevirtcluster_controller.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/controllers/kubevirtcluster_controller.go b/controllers/kubevirtcluster_controller.go index 0adf06384..887757137 100644 --- a/controllers/kubevirtcluster_controller.go +++ b/controllers/kubevirtcluster_controller.go @@ -84,8 +84,6 @@ func (r *KubevirtClusterReconciler) Reconcile(goctx gocontext.Context, req ctrl. return ctrl.Result{}, nil } - log = log.WithValues("cluster", cluster.Name) - // Create the cluster context for this request. clusterContext := &context.ClusterContext{ Context: goctx,