diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 6e4c1351..5c5f0b84 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,8 +1,2 @@ resources: - manager.yaml -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -images: -- name: controller - newName: ghcr.io/mirantis/boundless-operator - newTag: tpt diff --git a/controllers/addon_controller.go b/controllers/addon_controller.go index 5847c7ed..a7779771 100644 --- a/controllers/addon_controller.go +++ b/controllers/addon_controller.go @@ -2,7 +2,6 @@ package controllers import ( "context" - "github.com/mirantis/boundless-operator/pkg/helm" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" @@ -12,6 +11,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log" boundlessv1alpha1 "github.com/mirantis/boundless-operator/api/v1alpha1" + "github.com/mirantis/boundless-operator/pkg/helm" ) // AddonReconciler reconciles a Addon object @@ -44,7 +44,6 @@ func (r *AddonReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl err = r.Get(ctx, req.NamespacedName, instance) if err != nil { msg := "failed to get MkeAddon instance" - logger.Info("err is ", "err", err) if errors.IsNotFound(err) { // Ignore request. logger.Info(msg, "Name", req.Name, "Requeue", false) @@ -80,7 +79,7 @@ func (r *AddonReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl // The object is being deleted if controllerutil.ContainsFinalizer(instance, addonFinalizerName) { // our finalizer is present, so lets delete the helm chart - if err := hc.DeleteHelmChart(chart, req.Namespace); err != nil { + if err := hc.DeleteHelmChart(chart, instance.Spec.Namespace); err != nil { // if fail to delete the helm chart here, return with error // so that it can be retried return ctrl.Result{}, err @@ -98,8 +97,7 @@ func (r *AddonReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl } logger.Info("Creating Addon HelmChart resource", "Name", chart.Name, "Version", chart.Version) - logger.Info("req Namespace", "req.Namespace", req.Namespace) - if err2 := hc.CreateHelmChart(chart, req.Namespace); err2 != nil { + if err2 := hc.CreateHelmChart(chart, instance.Spec.Namespace); err2 != nil { logger.Error(err, "failed to install addon", "Name", chart.Name, "Version", chart.Version) return ctrl.Result{Requeue: true}, err2 } diff --git a/controllers/blueprint_controller.go b/controllers/blueprint_controller.go index 758f35dd..69b3e7d0 100644 --- a/controllers/blueprint_controller.go +++ b/controllers/blueprint_controller.go @@ -17,6 +17,8 @@ import ( boundlessv1alpha1 "github.com/mirantis/boundless-operator/api/v1alpha1" ) +const boundlessSystemNamespace = "boundless-system" + // BlueprintReconciler reconciles a Blueprint object type BlueprintReconciler struct { client.Client @@ -73,9 +75,7 @@ func (r *BlueprintReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( } for _, addon := range instance.Spec.Components.Addons { - logger.Info("namespaces", "Addon namespace", addon.Namespace, "instance namespace", instance.Namespace) if addon.Namespace == "" { - logger.Info("settingz addon namespace ot instance namespace") addon.Namespace = instance.Namespace } @@ -128,14 +128,14 @@ func (r *BlueprintReconciler) deleteAddons(ctx context.Context, logger logr.Logg return nil } -func (r *BlueprintReconciler) createOrUpdateAddon(ctx context.Context, logger logr.Logger, obj client.Object) error { - err := r.createNamespaceIfNotExist(ctx, logger, obj.GetNamespace()) +func (r *BlueprintReconciler) createOrUpdateAddon(ctx context.Context, logger logr.Logger, addon *boundlessv1alpha1.Addon) error { + err := r.createNamespaceIfNotExist(ctx, logger, addon.Spec.Namespace) if err != nil { return err } existing := &boundlessv1alpha1.Addon{} - err = r.Get(ctx, client.ObjectKey{Name: obj.GetName(), Namespace: obj.GetNamespace()}, existing) + err = r.Get(ctx, client.ObjectKey{Name: addon.GetName(), Namespace: addon.GetNamespace()}, existing) if err != nil { if client.IgnoreNotFound(err) != nil { return err @@ -144,30 +144,25 @@ func (r *BlueprintReconciler) createOrUpdateAddon(ctx context.Context, logger lo if existing.Name != "" { logger.Info("Add-on already exists. Updating", "Name", existing.Name) - obj.SetResourceVersion(existing.GetResourceVersion()) - err = r.Update(ctx, obj) + addon.SetResourceVersion(existing.GetResourceVersion()) + err = r.Update(ctx, addon) if err != nil { return fmt.Errorf("failed to update add-on %s: %w", existing.Name, err) } return nil } - logger.Info("Creating add-on", "Name", obj.GetName()) - err = r.Create(ctx, obj) + logger.Info("Creating add-on", "Name", addon.GetName()) + err = r.Create(ctx, addon) if err != nil { - return fmt.Errorf("failed to create add-on %s: %w", obj.GetName(), err) + return fmt.Errorf("failed to create add-on %s: %w", addon.GetName(), err) } return nil } func (r *BlueprintReconciler) createOrUpdateIngress(ctx context.Context, logger logr.Logger, obj client.Object) error { - err := r.createNamespaceIfNotExist(ctx, logger, obj.GetNamespace()) - if err != nil { - return err - } - existing := &boundlessv1alpha1.Ingress{} - err = r.Get(ctx, client.ObjectKey{Name: obj.GetName(), Namespace: obj.GetNamespace()}, existing) + err := r.Get(ctx, client.ObjectKey{Name: obj.GetName(), Namespace: obj.GetNamespace()}, existing) if err != nil { if client.IgnoreNotFound(err) != nil { return err @@ -197,7 +192,7 @@ func ingressResource(spec *boundlessv1alpha1.IngressSpec, namespace string) *bou return &boundlessv1alpha1.Ingress{ ObjectMeta: metav1.ObjectMeta{ Name: name, - Namespace: namespace, + Namespace: boundlessSystemNamespace, }, Spec: boundlessv1alpha1.IngressSpec{ Enabled: spec.Enabled, @@ -213,7 +208,7 @@ func addonResource(spec *boundlessv1alpha1.AddonSpec) *boundlessv1alpha1.Addon { return &boundlessv1alpha1.Addon{ ObjectMeta: metav1.ObjectMeta{ Name: name, - Namespace: spec.Namespace, + Namespace: boundlessSystemNamespace, }, Spec: boundlessv1alpha1.AddonSpec{ Name: spec.Name, diff --git a/controllers/ingress_controller.go b/controllers/ingress_controller.go index 0ab8d25a..68893fd9 100644 --- a/controllers/ingress_controller.go +++ b/controllers/ingress_controller.go @@ -115,7 +115,7 @@ func (r *IngressReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct hc := helm.NewHelmChartController(r.Client, logger) logger.Info("Creating HelmChart resource", "Name", chart.Name, "Version", chart.Version) - if err2 := hc.CreateHelmChart(chart, req.Namespace); err2 != nil { + if err2 := hc.CreateHelmChart(chart, instance.Namespace); err2 != nil { logger.Error(err, "failed to install ingress controller", "Controller Type", instance.Spec.Provider, "Version", "v1alpha1") return ctrl.Result{Requeue: true}, err2 } diff --git a/pkg/helm/chart.go b/pkg/helm/chart.go index c0577f5c..c5d10158 100644 --- a/pkg/helm/chart.go +++ b/pkg/helm/chart.go @@ -112,8 +112,7 @@ func (hc *Controller) createOrUpdateHelmChart(chart helmv1.HelmChart) error { err = hc.client.Update(ctx, &chart) hc.logger.Info("helm chart updated", "ChartName", chart.GetName()) } else { - hc.logger.Info("helm chart does not exists, creating", "ChartName", chart.GetName()) - hc.logger.Info("helm chart being created in ", "Namespace", chart.GetNamespace()) + hc.logger.Info("helm chart does not exists, creating", "ChartName", chart.GetName(), "Namespace", chart.GetNamespace()) err = hc.client.Create(ctx, &chart) if err != nil { return err