From a4542d32fff0863ee918571f0e3d163383c7ed63 Mon Sep 17 00:00:00 2001 From: Vibhav Bobade Date: Fri, 30 Jun 2023 22:09:48 +0530 Subject: [PATCH] fix: helmrepository creation errors out because it already exists --- Makefile | 2 +- chart/Chart.yaml | 2 +- controllers/uffizzicluster_controller.go | 21 ++++++++++++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 00771b0c..5442a407 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ # To re-generate a bundle for another specific version without changing the standard setup, you can: # - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2) # - use environment variables to overwrite this value (e.g export VERSION=0.0.2) -VERSION ?= 0.0.16 +VERSION ?= 0.0.17 # CHANNELS define the bundle channels used in the bundle. # Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable") diff --git a/chart/Chart.yaml b/chart/Chart.yaml index a1443291..0a086bae 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -10,7 +10,7 @@ version: 0.1.2 # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "v0.0.16" +appVersion: "v0.0.17" dependencies: - name: common repository: https://charts.bitnami.com/bitnami diff --git a/controllers/uffizzicluster_controller.go b/controllers/uffizzicluster_controller.go index c55d631c..eacc818f 100644 --- a/controllers/uffizzicluster_controller.go +++ b/controllers/uffizzicluster_controller.go @@ -24,6 +24,7 @@ import ( v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" @@ -88,11 +89,21 @@ const ( func (r *UffizziClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { logger := log.FromContext(ctx) - // create the loft helm repo if it is not already created - err := r.createLoftHelmRepo(ctx, req) - // check if error is because the HelmRepository already exists - if err != nil && !k8serrors.IsAlreadyExists(err) { - logger.Error(err, "error while creating HelmRepository for Loft") + loftHelmRepo := &fluxsourcev1.HelmRepository{} + err := r.Get(ctx, types.NamespacedName{ + Name: LOFT_HELM_REPO, + Namespace: req.Namespace, + }, loftHelmRepo) + + // check if error is because the HelmRepository does not exist + if err != nil && k8serrors.IsNotFound(err) { + // create the loft helm repo if it is not already created + logger.Info("HelmRepository for Loft created") + err := r.createLoftHelmRepo(ctx, req) + // check if error is because the HelmRepository already exists + if err != nil && !k8serrors.IsAlreadyExists(err) { + logger.Error(err, "error while creating HelmRepository for Loft") + } } // Fetch the UffizziCluster instance in question