From 214abb6506ebf68cc6bc797801027601695d2ae7 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Sat, 25 Jan 2025 12:57:09 +0530 Subject: [PATCH 1/2] changes to the manifest and other aspects Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- .gitignore | 1 + Makefile | 3 ++- PROJECT | 2 +- config/default/kustomization.yaml | 37 +++++++++++++++---------------- config/manager/kustomization.yaml | 6 +++++ internal/controller/addons.go | 4 ++-- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index b1d38dd..73d94d7 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ go.work *.swo *~ +dist/ diff --git a/Makefile b/Makefile index b173643..98582c3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ # Image URL to use all building/pushing image targets -IMG ?= controller:latest +IMG_TAG ?= latest +IMG ?= ghcr.io/ksctl/kcm:${IMG_TAG} # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) diff --git a/PROJECT b/PROJECT index e41283b..971fe27 100644 --- a/PROJECT +++ b/PROJECT @@ -10,7 +10,7 @@ repo: github.com/ksctl/kcm resources: - api: crdVersion: v1 - namespaced: true + namespaced: false controller: true domain: ksctl.com group: manage diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index 0f8884a..5e98d6e 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -1,5 +1,5 @@ # Adds namespace to all resources. -namespace: ksctl-system +namespace: kcm-ksctl-system # Value of this field is prepended to the # names of all resources, e.g. a deployment named @@ -15,18 +15,18 @@ namePrefix: kcm- # someName: someValue resources: -- ../crd -- ../rbac -- ../manager -# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in -# crd/kustomization.yaml -#- ../webhook -# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required. -#- ../certmanager -# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. -#- ../prometheus -# [METRICS] Expose the controller manager metrics service. -- metrics_service.yaml + - ../crd + - ../rbac + - ../manager + # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in + # crd/kustomization.yaml + #- ../webhook + # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required. + #- ../certmanager + # [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. + #- ../prometheus + # [METRICS] Expose the controller manager metrics service. + - metrics_service.yaml # [NETWORK POLICY] Protect the /metrics endpoint and Webhook Server with NetworkPolicy. # Only Pod(s) running a namespace labeled with 'metrics: enabled' will be able to gather the metrics. # Only CR(s) which requires webhooks and are applied on namespaces labeled with 'webhooks: enabled' will @@ -35,12 +35,11 @@ resources: # Uncomment the patches line if you enable Metrics patches: -# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443. -# More info: https://book.kubebuilder.io/reference/metrics -- path: manager_metrics_patch.yaml - target: - kind: Deployment - + # [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443. + # More info: https://book.kubebuilder.io/reference/metrics + - path: manager_metrics_patch.yaml + target: + kind: Deployment # Uncomment the patches line if you enable Metrics and CertManager # [METRICS-WITH-CERTS] To enable metrics protected with certManager, uncomment the following line. # This patch will protect the metrics with certManager self-signed certs. diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 5c5f0b8..ad13e96 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,2 +1,8 @@ resources: - manager.yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +images: +- name: controller + newName: controller + newTag: latest diff --git a/internal/controller/addons.go b/internal/controller/addons.go index 25ae369..93c385f 100644 --- a/internal/controller/addons.go +++ b/internal/controller/addons.go @@ -71,12 +71,12 @@ func (r *ClusterAddonReconciler) DeleteNamespaceIfExists(ctx context.Context, na func (r *ClusterAddonReconciler) GetData(ctx context.Context) (*corev1.ConfigMap, error) { cf := &corev1.ConfigMap{} - if err := r.Get(ctx, client.ObjectKey{Namespace: cf.Namespace, Name: cf.Name}, cf); err != nil { + if err := r.Get(ctx, client.ObjectKey{Namespace: "kcm-ksctl-system", Name: "kcm-addons"}, cf); err != nil { if errors.IsNotFound(err) { cf = &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: "kcm-addons", - Namespace: "ksctl-system", + Namespace: "kcm-ksctl-system", }, Data: map[string]string{}, } From a0c99c38bf7220338c371e85ca855ffa6c2fdcaa Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Sat, 25 Jan 2025 13:19:14 +0530 Subject: [PATCH 2/2] feat(ci): added release workflow Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- .github/workflows/release.yml | 61 +++++++++++++++++++++++++++++++++++ Makefile | 3 +- 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..71aa547 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,61 @@ +name: Release + +on: + push: + tags: + - "v*" # Trigger on version tags + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + TAG_NAME: ${{ github.ref_name }} + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write # Needed for creating releases + packages: write # Needed for ghcr.io push + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "stable" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies + run: | + make + + - name: Build installer YAML + run: | + make build-installer IMG=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG_NAME }} + + - name: Build and push Docker images + run: | + make docker-buildx IMG=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG_NAME }} + + - name: Create Release + uses: softprops/action-gh-release@v2 + with: + files: dist/install.yaml + generate_release_notes: true + draft: true + prerelease: false + make_latest: true + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Makefile b/Makefile index 98582c3..b173643 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,5 @@ # Image URL to use all building/pushing image targets -IMG_TAG ?= latest -IMG ?= ghcr.io/ksctl/kcm:${IMG_TAG} +IMG ?= controller:latest # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN))