diff --git a/README.md b/README.md index 4f200cd99..b6364ca11 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,6 @@ apiVersion: hmc.mirantis.com/v1alpha1 kind: Management metadata: name: hmc - namespace: hmc-system spec: core: capi: @@ -76,7 +75,7 @@ There are two options to override the default management configuration of HMC: 1. Update the `Management` object after the HMC installation using `kubectl`: - `kubectl --kubeconfig -n hmc-system edit management` + `kubectl --kubeconfig edit management` 2. Deploy HMC skipping the default `Management` object creation and provide your own `Management` configuration: @@ -90,9 +89,9 @@ configuration: `--set="controller.createManagement=false"` - * Create `hmc-system/hmc` `Management` object after HMC installation: + * Create `hmc` `Management` object after HMC installation: - `kubectl --kubeconfig -n hmc-system create -f management.yaml` + `kubectl --kubeconfig create -f management.yaml` ## Deploy a managed cluster @@ -243,7 +242,7 @@ spec: 1. Remove the Management object: -`kubectl delete management.hmc hmc -n hmc-system` +`kubectl delete management.hmc hmc` > Note: make sure you have no HMC ManagedCluster objects left in the cluster prior to Management deletion diff --git a/api/v1alpha1/management_types.go b/api/v1alpha1/management_types.go index cdf86cf38..535d0a96e 100644 --- a/api/v1alpha1/management_types.go +++ b/api/v1alpha1/management_types.go @@ -131,7 +131,7 @@ type ComponentStatus struct { //+kubebuilder:object:root=true //+kubebuilder:subresource:status -// +kubebuilder:resource:shortName=hmc-mgmt;mgmt +// +kubebuilder:resource:shortName=hmc-mgmt;mgmt,scope=Cluster // Management is the Schema for the managements API type Management struct { diff --git a/internal/controller/deployment_controller.go b/internal/controller/deployment_controller.go index 8537c388c..00f20029f 100644 --- a/internal/controller/deployment_controller.go +++ b/internal/controller/deployment_controller.go @@ -80,7 +80,7 @@ func (r *ManagedClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reque if managedCluster.Status.ObservedGeneration == 0 { mgmt := &hmc.Management{} - mgmtRef := types.NamespacedName{Namespace: hmc.ManagementNamespace, Name: hmc.ManagementName} + mgmtRef := types.NamespacedName{Name: hmc.ManagementName} if err := r.Get(ctx, mgmtRef, mgmt); err != nil { l.Error(err, "Failed to get Management object") return ctrl.Result{}, err diff --git a/internal/controller/deployment_controller_test.go b/internal/controller/deployment_controller_test.go index 5ad9c34ca..59a4c4ea4 100644 --- a/internal/controller/deployment_controller_test.go +++ b/internal/controller/deployment_controller_test.go @@ -97,8 +97,7 @@ var _ = Describe("ManagedCluster Controller", func() { if err != nil && errors.IsNotFound(err) { management = &hmc.Management{ ObjectMeta: metav1.ObjectMeta{ - Name: hmc.ManagementName, - Namespace: hmc.ManagementNamespace, + Name: hmc.ManagementName, }, Spec: hmc.ManagementSpec{}, } diff --git a/internal/controller/management_controller.go b/internal/controller/management_controller.go index 862561012..8f69c9f0d 100644 --- a/internal/controller/management_controller.go +++ b/internal/controller/management_controller.go @@ -75,7 +75,7 @@ func (r *ManagementReconciler) Update(ctx context.Context, management *hmc.Manag finalizersUpdated := controllerutil.AddFinalizer(management, hmc.ManagementFinalizer) if finalizersUpdated { if err := r.Client.Update(ctx, management); err != nil { - return ctrl.Result{}, fmt.Errorf("failed to update Management %s/%s: %w", management.Namespace, management.Name, err) + return ctrl.Result{}, fmt.Errorf("failed to update Management %s: %w", management.Name, err) } return ctrl.Result{}, nil } @@ -117,10 +117,10 @@ func (r *ManagementReconciler) Update(ctx context.Context, management *hmc.Manag continue } - _, _, err = helm.ReconcileHelmRelease(ctx, r.Client, component.HelmReleaseName(), management.Namespace, component.Config, + _, _, err = helm.ReconcileHelmRelease(ctx, r.Client, component.HelmReleaseName(), hmc.ManagementNamespace, component.Config, nil, template.Status.ChartRef, defaultReconcileInterval, component.dependsOn) if err != nil { - errMsg := fmt.Sprintf("error reconciling HelmRelease %s/%s: %s", management.Namespace, component.Template, err) + errMsg := fmt.Sprintf("error reconciling HelmRelease %s/%s: %s", hmc.ManagementNamespace, component.Template, err) updateComponentsStatus(detectedComponents, &detectedProviders, component.Template, template.Status, errMsg) errs = errors.Join(errs, errors.New(errMsg)) continue @@ -132,8 +132,8 @@ func (r *ManagementReconciler) Update(ctx context.Context, management *hmc.Manag management.Status.AvailableProviders = detectedProviders management.Status.Components = detectedComponents if err := r.Status().Update(ctx, management); err != nil { - errs = errors.Join(errs, fmt.Errorf("failed to update status for Management %s/%s: %w", - management.Namespace, management.Name, err)) + errs = errors.Join(errs, fmt.Errorf("failed to update status for Management %s: %w", + management.Name, err)) } if errs != nil { l.Error(errs, "Multiple errors during Management reconciliation") diff --git a/internal/controller/release_controller.go b/internal/controller/release_controller.go index afdccdb76..5bda1e8b9 100644 --- a/internal/controller/release_controller.go +++ b/internal/controller/release_controller.go @@ -112,13 +112,11 @@ func (p *Poller) ensureManagement(ctx context.Context) error { mgmtObj := &hmc.Management{ ObjectMeta: metav1.ObjectMeta{ Name: hmc.ManagementName, - Namespace: hmc.ManagementNamespace, Finalizers: []string{hmc.ManagementFinalizer}, }, } err := p.Get(ctx, client.ObjectKey{ - Name: hmc.ManagementName, - Namespace: hmc.ManagementNamespace, + Name: hmc.ManagementName, }, mgmtObj) if err != nil { if !apierrors.IsNotFound(err) { diff --git a/internal/telemetry/tracker.go b/internal/telemetry/tracker.go index d2fb022de..8eebaaca4 100644 --- a/internal/telemetry/tracker.go +++ b/internal/telemetry/tracker.go @@ -61,7 +61,7 @@ func (t *Tracker) Tick(ctx context.Context) { func (t *Tracker) trackManagedClusterHeartbeat(ctx context.Context) error { mgmt := &v1alpha1.Management{} - mgmtRef := types.NamespacedName{Namespace: v1alpha1.ManagementNamespace, Name: v1alpha1.ManagementName} + mgmtRef := types.NamespacedName{Name: v1alpha1.ManagementName} err := t.Get(ctx, mgmtRef, mgmt) if err != nil { return err diff --git a/internal/webhook/managedcluster_webhook.go b/internal/webhook/managedcluster_webhook.go index 38b71b911..d61d49c75 100644 --- a/internal/webhook/managedcluster_webhook.go +++ b/internal/webhook/managedcluster_webhook.go @@ -145,7 +145,7 @@ func (v *ManagedClusterValidator) isTemplateValid(ctx context.Context, template func (v *ManagedClusterValidator) verifyProviders(ctx context.Context, template *v1alpha1.Template) error { requiredProviders := template.Status.Providers management := &v1alpha1.Management{} - managementRef := types.NamespacedName{Name: v1alpha1.ManagementName, Namespace: v1alpha1.ManagementNamespace} + managementRef := types.NamespacedName{Name: v1alpha1.ManagementName} if err := v.Get(ctx, managementRef, management); err != nil { return err } diff --git a/templates/hmc/templates/crds/hmc.mirantis.com_managements.yaml b/templates/hmc/templates/crds/hmc.mirantis.com_managements.yaml index f739401d5..cd6c68a95 100644 --- a/templates/hmc/templates/crds/hmc.mirantis.com_managements.yaml +++ b/templates/hmc/templates/crds/hmc.mirantis.com_managements.yaml @@ -15,7 +15,7 @@ spec: - hmc-mgmt - mgmt singular: management - scope: Namespaced + scope: Cluster versions: - name: v1alpha1 schema: diff --git a/test/objects/management/management.go b/test/objects/management/management.go index f3270f23b..c32604143 100644 --- a/test/objects/management/management.go +++ b/test/objects/management/management.go @@ -21,8 +21,7 @@ import ( ) const ( - DefaultName = "hmc" - DefaultNamespace = "hmc-system" + DefaultName = "hmc" ) type Opt func(management *v1alpha1.Management) @@ -30,8 +29,7 @@ type Opt func(management *v1alpha1.Management) func NewManagement(opts ...Opt) *v1alpha1.Management { p := &v1alpha1.Management{ ObjectMeta: metav1.ObjectMeta{ - Name: DefaultName, - Namespace: DefaultNamespace, + Name: DefaultName, }, } @@ -47,12 +45,6 @@ func WithName(name string) Opt { } } -func WithNamespace(namespace string) Opt { - return func(p *v1alpha1.Management) { - p.Namespace = namespace - } -} - func WithCoreComponents(core *v1alpha1.Core) Opt { return func(p *v1alpha1.Management) { p.Spec.Core = core