Fix ManifestWorkReplicaset featureGate (#340)

Signed-off-by: melserngawy <melserng@redhat.com>
This commit is contained in:
Mohamed ElSerngawy
2023-04-05 22:09:18 -04:00
committed by GitHub
parent bceed21bb7
commit c2cedbe2ff
7 changed files with 71 additions and 15 deletions

View File

@@ -3,7 +3,6 @@ package clustermanagercontroller
import (
"context"
"encoding/base64"
ocmfeature "open-cluster-management.io/api/feature"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
@@ -30,6 +29,7 @@ import (
operatorv1client "open-cluster-management.io/api/client/operator/clientset/versioned/typed/operator/v1"
operatorinformer "open-cluster-management.io/api/client/operator/informers/externalversions/operator/v1"
operatorlister "open-cluster-management.io/api/client/operator/listers/operator/v1"
ocmfeature "open-cluster-management.io/api/feature"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
"open-cluster-management.io/registration-operator/manifests"
"open-cluster-management.io/registration-operator/pkg/helpers"
@@ -165,6 +165,7 @@ func (n *clusterManagerController) sync(ctx context.Context, controllerContext f
workFeatureGates = clusterManager.Spec.WorkConfiguration.FeatureGates
}
config.WorkFeatureGates, workFeatureMsgs = helpers.ConvertToFeatureGateFlags("Work", workFeatureGates, ocmfeature.DefaultHubWorkFeatureGates)
config.MWReplicaSetEnabled = helpers.FeatureGateEnabled(workFeatureGates, ocmfeature.DefaultHubWorkFeatureGates, ocmfeature.ManifestWorkReplicaSet)
addonFeatureGates := []operatorapiv1.FeatureGate{}
if clusterManager.Spec.AddOnManagerConfiguration != nil {

View File

@@ -46,6 +46,11 @@ type testController struct {
}
func newClusterManager(name string) *operatorapiv1.ClusterManager {
featureGate := operatorapiv1.FeatureGate{
Feature: "ManifestWorkReplicaSet",
Mode: operatorapiv1.FeatureGateModeTypeEnable,
}
return &operatorapiv1.ClusterManager{
ObjectMeta: metav1.ObjectMeta{
Name: name,
@@ -61,6 +66,9 @@ func newClusterManager(name string) *operatorapiv1.ClusterManager {
{Feature: "AddonManagement", Mode: operatorapiv1.FeatureGateModeTypeEnable},
},
},
WorkConfiguration: &operatorapiv1.WorkConfiguration{
FeatureGates: []operatorapiv1.FeatureGate{featureGate},
},
},
}
}

View File

@@ -41,6 +41,9 @@ var (
"cluster-manager/hub/cluster-manager-placement-clusterrole.yaml",
"cluster-manager/hub/cluster-manager-placement-clusterrolebinding.yaml",
"cluster-manager/hub/cluster-manager-placement-serviceaccount.yaml",
}
mwReplicaSetResourceFiles = []string{
// manifestworkreplicaset
"cluster-manager/hub/cluster-manager-manifestworkreplicaset-clusterrole.yaml",
"cluster-manager/hub/cluster-manager-manifestworkreplicaset-clusterrolebinding.yaml",
@@ -84,6 +87,14 @@ func (c *hubReoncile) reconcile(ctx context.Context, cm *operatorapiv1.ClusterMa
}
}
// Remove ManifestWokReplicaSet deployment if feature not enabled
if !config.MWReplicaSetEnabled {
_, _, err := cleanResources(ctx, c.hubKubeClient, cm, config, mwReplicaSetResourceFiles...)
if err != nil {
return cm, reconcileStop, err
}
}
hubResources := getHubResources(cm.Spec.DeployOption.Mode, config)
var appliedErrs []error
@@ -134,6 +145,10 @@ func getHubResources(mode operatorapiv1.InstallMode, config manifests.HubConfig)
if config.AddOnManagerEnabled {
hubResources = append(hubResources, hubAddOnManagerRbacResourceFiles...)
}
if config.MWReplicaSetEnabled {
hubResources = append(hubResources, mwReplicaSetResourceFiles...)
}
// the hubHostedWebhookServiceFiles are only used in hosted mode
if mode == operatorapiv1.InstallModeHosted {
hubResources = append(hubResources, hubHostedWebhookServiceFiles...)

View File

@@ -29,12 +29,15 @@ var (
"cluster-manager/management/cluster-manager-registration-webhook-deployment.yaml",
"cluster-manager/management/cluster-manager-work-webhook-deployment.yaml",
"cluster-manager/management/cluster-manager-placement-deployment.yaml",
"cluster-manager/management/cluster-manager-manifestworkreplicaset-deployment.yaml",
}
addOnManagerDeploymentFiles = []string{
"cluster-manager/management/cluster-manager-addon-manager-deployment.yaml",
}
mwReplicaSetDeploymentFiles = []string{
"cluster-manager/management/cluster-manager-manifestworkreplicaset-deployment.yaml",
}
)
type runtimeReconcile struct {
@@ -57,6 +60,14 @@ func (c *runtimeReconcile) reconcile(ctx context.Context, cm *operatorapiv1.Clus
}
}
// Remove ManifestWokReplicaSet deployment if feature not enabled
if !config.MWReplicaSetEnabled {
_, _, err := cleanResources(ctx, c.kubeClient, cm, config, mwReplicaSetDeploymentFiles...)
if err != nil {
return cm, reconcileStop, err
}
}
// In the Hosted mode, ensure the rbac kubeconfig secrets is existed for deployments to mount.
// In this step, we get serviceaccount token from the hub cluster to form a kubeconfig and set it as a secret on the management cluster.
// Before this step, the serviceaccounts in the hub cluster and the namespace in the management cluster should be applied first.
@@ -107,6 +118,9 @@ func (c *runtimeReconcile) reconcile(ctx context.Context, cm *operatorapiv1.Clus
if config.AddOnManagerEnabled {
deployResources = append(deployResources, addOnManagerDeploymentFiles...)
}
if config.MWReplicaSetEnabled {
deployResources = append(deployResources, mwReplicaSetDeploymentFiles...)
}
for _, file := range deployResources {
updatedDeployment, currentGeneration, err := helpers.ApplyDeployment(
ctx,