diff --git a/api/v1/multiclusterengine_methods.go b/api/v1/multiclusterengine_methods.go index c67a75967..699ab5e0c 100644 --- a/api/v1/multiclusterengine_methods.go +++ b/api/v1/multiclusterengine_methods.go @@ -24,6 +24,8 @@ import ( const ( AssistedService = "assisted-service" + ClusterAPI = "cluster-api" + ClusterAPIPreview = "cluster-api-preview" ClusterLifecycle = "cluster-lifecycle" ClusterManager = "cluster-manager" ClusterProxyAddon = "cluster-proxy-addon" @@ -43,6 +45,8 @@ const ( var allComponents = []string{ AssistedService, + ClusterAPI, + ClusterAPIPreview, ClusterLifecycle, ClusterManager, ClusterProxyAddon, @@ -63,6 +67,7 @@ var allComponents = []string{ // MCEComponents is a slice containing component names specific to the "MCE" category. var MCEComponents = []string{ AssistedService, + ClusterAPIPreview, ClusterLifecycle, ClusterManager, ClusterProxyAddon, diff --git a/controllers/backplaneconfig_controller.go b/controllers/backplaneconfig_controller.go index 229fedfb7..672b6137e 100644 --- a/controllers/backplaneconfig_controller.go +++ b/controllers/backplaneconfig_controller.go @@ -779,6 +779,7 @@ func (r *MultiClusterEngineReconciler) createMetricsServiceMonitor(ctx context.C func (r *MultiClusterEngineReconciler) DeployAlwaysSubcomponents(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { chartsDir := renderer.AlwaysChartsDir + // Renders all templates from charts templates, errs := renderer.RenderCharts(chartsDir, backplaneConfig, r.CacheSpec.ImageOverrides, r.CacheSpec.TemplateOverrides) @@ -893,9 +894,9 @@ func (r *MultiClusterEngineReconciler) ensureNoInternalEngineComponent(ctx conte } func (r *MultiClusterEngineReconciler) fetchChartOrCRDPath(component string, useCRDPath bool) string { - chartDirs := map[string]string{ backplanev1.AssistedService: toggle.AssistedServiceChartDir, + backplanev1.ClusterAPIPreview: toggle.ClusterAPIDir, backplanev1.ClusterLifecycle: toggle.ClusterLifecycleChartDir, backplanev1.ClusterManager: toggle.ClusterManagerChartDir, backplanev1.ClusterProxyAddon: toggle.ClusterProxyAddonDir, @@ -1149,6 +1150,25 @@ func (r *MultiClusterEngineReconciler) ensureToggleableComponents(ctx context.Co errs[backplanev1.ClusterProxyAddon] = err } } + + if backplaneConfig.Enabled(backplanev1.ClusterAPIPreview) { + result, err = r.ensureClusterAPI(ctx, backplaneConfig) + if result != (ctrl.Result{}) { + requeue = true + } + if err != nil { + errs[backplanev1.ClusterAPIPreview] = err + } + } else { + result, err = r.ensureNoClusterAPI(ctx, backplaneConfig) + if result != (ctrl.Result{}) { + requeue = true + } + if err != nil { + errs[backplanev1.ClusterAPIPreview] = err + } + } + if backplaneConfig.Enabled(backplanev1.LocalCluster) { result, err := r.ensureLocalCluster(ctx, backplaneConfig) if result != (ctrl.Result{}) { @@ -2000,7 +2020,10 @@ func ensureCRD(ctx context.Context, c client.Client, crd *unstructured.Unstructu func (r *MultiClusterEngineReconciler) removeDeprecatedRBAC(ctx context.Context) (ctrl.Result, error) { hyperShiftPreviewClusterRoleBinding := &rbacv1.ClusterRoleBinding{} - err := r.Client.Get(ctx, types.NamespacedName{Name: "open-cluster-management:hypershift-preview:hypershift-addon-manager"}, hyperShiftPreviewClusterRoleBinding) + err := r.Client.Get(ctx, + types.NamespacedName{Name: "open-cluster-management:hypershift-preview:hypershift-addon-manager"}, + hyperShiftPreviewClusterRoleBinding) + if err == nil { err = r.Client.Delete(ctx, hyperShiftPreviewClusterRoleBinding) if err != nil { @@ -2011,8 +2034,12 @@ func (r *MultiClusterEngineReconciler) removeDeprecatedRBAC(ctx context.Context) return ctrl.Result{}, err } } + hyperShiftPreviewClusterRole := &rbacv1.ClusterRole{} - err = r.Client.Get(ctx, types.NamespacedName{Name: "open-cluster-management:hypershift-preview:hypershift-addon-manager"}, hyperShiftPreviewClusterRole) + err = r.Client.Get(ctx, + types.NamespacedName{Name: "open-cluster-management:hypershift-preview:hypershift-addon-manager"}, + hyperShiftPreviewClusterRole) + if err == nil { err = r.Client.Delete(ctx, hyperShiftPreviewClusterRole) if err != nil { diff --git a/controllers/toggle_components.go b/controllers/toggle_components.go index 1c07ca406..9c6bb2727 100644 --- a/controllers/toggle_components.go +++ b/controllers/toggle_components.go @@ -385,7 +385,6 @@ func (r *MultiClusterEngineReconciler) ensureDiscovery(ctx context.Context, mce func (r *MultiClusterEngineReconciler) ensureNoDiscovery(ctx context.Context, mce *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - namespacedName := types.NamespacedName{Name: "discovery-operator", Namespace: mce.Spec.TargetNamespace} // Ensure that the InternalHubComponent CR instance is deleted for component in MCE. @@ -419,6 +418,81 @@ func (r *MultiClusterEngineReconciler) ensureNoDiscovery(ctx context.Context, return ctrl.Result{}, nil } +func (r *MultiClusterEngineReconciler) ensureClusterAPI(ctx context.Context, mce *backplanev1.MultiClusterEngine) ( + ctrl.Result, error) { + + namespacedName := types.NamespacedName{Name: "cluster-api", Namespace: mce.Spec.TargetNamespace} + r.StatusManager.RemoveComponent(toggle.DisabledStatus(namespacedName, []*unstructured.Unstructured{})) + r.StatusManager.AddComponent(toggle.EnabledStatus(namespacedName)) + + // Ensure that the InternalHubComponent CR instance is created for component in MCE. + if result, err := r.ensureInternalEngineComponent(ctx, mce, backplanev1.ClusterAPIPreview); err != nil { + return result, err + } + + // Renders all templates from charts + chartPath := r.fetchChartOrCRDPath(backplanev1.ClusterAPIPreview, false) + templates, errs := renderer.RenderChart(chartPath, mce, r.CacheSpec.ImageOverrides, r.CacheSpec.TemplateOverrides) + + if len(errs) > 0 { + for _, err := range errs { + log.Info(err.Error()) + } + return ctrl.Result{RequeueAfter: requeuePeriod}, nil + } + + // Apply deployment config overrides + if result, err := r.applyComponentDeploymentOverrides(mce, templates, backplanev1.ClusterAPIPreview); err != nil { + return result, err + } + + // Applies all templates + for _, template := range templates { + applyReleaseVersionAnnotation(template) + result, err := r.applyTemplate(ctx, mce, template) + if err != nil { + return result, err + } + } + + return ctrl.Result{}, nil +} + +func (r *MultiClusterEngineReconciler) ensureNoClusterAPI(ctx context.Context, + mce *backplanev1.MultiClusterEngine) (ctrl.Result, error) { + namespacedName := types.NamespacedName{Name: "cluster-api", Namespace: mce.Spec.TargetNamespace} + + // Ensure that the InternalHubComponent CR instance is deleted for component in MCE. + if result, err := r.ensureNoInternalEngineComponent(ctx, mce, + backplanev1.ClusterAPIPreview); (result != ctrl.Result{}) || err != nil { + return result, err + } + + // Renders all templates from charts + chartPath := r.fetchChartOrCRDPath(backplanev1.ClusterAPIPreview, false) + templates, errs := renderer.RenderChart(chartPath, mce, r.CacheSpec.ImageOverrides, r.CacheSpec.TemplateOverrides) + + if len(errs) > 0 { + for _, err := range errs { + log.Info(err.Error()) + } + return ctrl.Result{RequeueAfter: requeuePeriod}, nil + } + + r.StatusManager.RemoveComponent(toggle.EnabledStatus(namespacedName)) + r.StatusManager.AddComponent(toggle.DisabledStatus(namespacedName, []*unstructured.Unstructured{})) + + // Deletes all templates + for _, template := range templates { + result, err := r.deleteTemplate(ctx, mce, template) + if err != nil { + log.Error(err, fmt.Sprintf("Failed to delete template: %s", template.GetName())) + return result, err + } + } + return ctrl.Result{}, nil +} + func (r *MultiClusterEngineReconciler) ensureHive(ctx context.Context, mce *backplanev1.MultiClusterEngine) ( ctrl.Result, error) { diff --git a/docs/available-components.md b/docs/available-components.md index 5841cd6d8..af75ed890 100644 --- a/docs/available-components.md +++ b/docs/available-components.md @@ -1,17 +1,19 @@ # Table list of the deployed components -| Name | Description | Enabled | -|---------------------------|----------------------------------------------------------------------------------------------------------------------|---------| -| assisted-service | Installs OpenShift with minimal infrastructure prerequisites and comprehensive pre-flight validations. | True | -| cluster-lifecycle | Provides cluster management capabilities for {ocp-short} and {product-title-short} hub clusters. | True | -| cluster-manager | Manages various cluster-related operations within the cluster environment. | True | -| cluster-proxy-addon | Automates the installation of apiserver-network-proxy on both hub and managed clusters using a reverse proxy server. | True | -| console-mce | Enables the {mce-short} console plug-in. | True | -| discovery | Discovers and identifies new clusters within the {ocm}. | True | -| hive | Provisions and performs initial configuration of {ocp-short} clusters. | True | -| hypershift | Hosts OpenShift control planes at scale with cost and time efficiency, and cross-cloud portability. | True | -| hypershift-local-hosting | Enables local hosting capabilities for within the local cluster environment. | True | -| local-cluster | Enables the import and self-management of the local hub cluster where the {mce-short} is deployed. | True | -| managedserviceaccount | Syncronizes service accounts to the managed clusters and collects tokens as secret resources back to the hub cluster.| True | -| server-foundation | Provides foundational services for server-side operations within the cluster environment. | True | \ No newline at end of file +| Name | Description | Enabled | +|------------------------------|----------------------------------------------------------------------------------------------------------------------|---------| +| assisted-service | Installs OpenShift with minimal infrastructure prerequisites and comprehensive pre-flight validations. | True | +| cluster-api-preview | Provides capabilities for declaratively handling the Cluster API lifecycle from within a managment cluster | False | +| cluster-lifecycle | Provides cluster management capabilities for {ocp-short} and {product-title-short} hub clusters. | True | +| cluster-manager | Manages various cluster-related operations within the cluster environment. | True | +| cluster-proxy-addon | Automates the installation of apiserver-network-proxy on both hub and managed clusters using a reverse proxy server. | True | +| console-mce | Enables the {mce-short} console plug-in. | True | +| discovery | Discovers and identifies new clusters within the {ocm}. | True | +| hive | Provisions and performs initial configuration of {ocp-short} clusters. | True | +| hypershift | Hosts OpenShift control planes at scale with cost and time efficiency, and cross-cloud portability. | True | +| hypershift-local-hosting | Enables local hosting capabilities for within the local cluster environment. | True | +| image-based-install-operator | Provide site configuration to Single Node OpenShift clusters to complete installation. | False | +| local-cluster | Enables the import and self-management of the local hub cluster where the {mce-short} is deployed. | True | +| managedserviceaccount | Syncronizes service accounts to the managed clusters and collects tokens as secret resources back to the hub cluster.| True | +| server-foundation | Provides foundational services for server-side operations within the cluster environment. | True | \ No newline at end of file diff --git a/pkg/toggle/toggle.go b/pkg/toggle/toggle.go index d71b6cbe7..dea739880 100644 --- a/pkg/toggle/toggle.go +++ b/pkg/toggle/toggle.go @@ -18,20 +18,21 @@ import ( ) const ( - ManagedServiceAccountChartDir = "pkg/templates/charts/toggle/managed-serviceaccount" + AssistedServiceChartDir = "pkg/templates/charts/toggle/assisted-service" + ClusterAPIDir = "pkg/templates/charts/toggle/cluster-api" + ClusterLifecycleChartDir = "pkg/templates/charts/toggle/cluster-lifecycle" + ClusterManagerChartDir = "pkg/templates/charts/toggle/cluster-manager" + ClusterProxyAddonDir = "pkg/templates/charts/toggle/cluster-proxy-addon" ConsoleMCEChartsDir = "pkg/templates/charts/toggle/console-mce" - ManagedServiceAccountCRDPath = "pkg/templates/managed-serviceaccount/crds" - ImageBasedInstallOperatorChartDir = "pkg/templates/charts/toggle/image-based-install-operator" DiscoveryChartDir = "pkg/templates/charts/toggle/discovery-operator" + HiveChartDir = "pkg/templates/charts/toggle/hive-operator" HostedImportChartDir = "pkg/templates/charts/hosted/server-foundation" HostingImportChartDir = "pkg/templates/charts/hosting/server-foundation" - HiveChartDir = "pkg/templates/charts/toggle/hive-operator" - AssistedServiceChartDir = "pkg/templates/charts/toggle/assisted-service" - ClusterLifecycleChartDir = "pkg/templates/charts/toggle/cluster-lifecycle" - ClusterManagerChartDir = "pkg/templates/charts/toggle/cluster-manager" - ServerFoundationChartDir = "pkg/templates/charts/toggle/server-foundation" HyperShiftChartDir = "pkg/templates/charts/toggle/hypershift" - ClusterProxyAddonDir = "pkg/templates/charts/toggle/cluster-proxy-addon" + ImageBasedInstallOperatorChartDir = "pkg/templates/charts/toggle/image-based-install-operator" + ManagedServiceAccountChartDir = "pkg/templates/charts/toggle/managed-serviceaccount" + ManagedServiceAccountCRDPath = "pkg/templates/managed-serviceaccount/crds" + ServerFoundationChartDir = "pkg/templates/charts/toggle/server-foundation" ) func EnabledStatus(namespacedName types.NamespacedName) status.StatusReporter { diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index afb3f171f..78ea619f5 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -7,12 +7,13 @@ import ( "context" "encoding/json" "fmt" + "path" + "path/filepath" + "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes" - "path" - "path/filepath" "os" @@ -60,16 +61,17 @@ var onComponents = []string{ } var offComponents = []string{ + backplanev1.ClusterAPIPreview, backplanev1.ImageBasedInstallOperator, } var nonOCPComponents = []string{ + backplanev1.ClusterLifecycle, backplanev1.ClusterManager, - backplanev1.ServerFoundation, backplanev1.HyperShift, backplanev1.HypershiftLocalHosting, backplanev1.LocalCluster, - backplanev1.ClusterLifecycle, + backplanev1.ServerFoundation, } var GlobalDeployOnOCP = true