Skip to content

Commit

Permalink
added capi toggle to MCE operator
Browse files Browse the repository at this point in the history
Signed-off-by: dislbenn <[email protected]>
  • Loading branch information
dislbenn committed Dec 16, 2024
1 parent cb3beec commit 068f6bb
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 31 deletions.
5 changes: 5 additions & 0 deletions api/v1/multiclusterengine_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -43,6 +45,8 @@ const (

var allComponents = []string{
AssistedService,
ClusterAPI,
ClusterAPIPreview,
ClusterLifecycle,
ClusterManager,
ClusterProxyAddon,
Expand All @@ -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,
Expand Down
33 changes: 30 additions & 3 deletions controllers/backplaneconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{}) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
76 changes: 75 additions & 1 deletion controllers/toggle_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {

Expand Down
30 changes: 16 additions & 14 deletions docs/available-components.md
Original file line number Diff line number Diff line change
@@ -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 |
| 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 |
19 changes: 10 additions & 9 deletions pkg/toggle/toggle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 068f6bb

Please sign in to comment.