From 4edb21782f8b93edc2b7a6bb8faa84bd68abb8dd Mon Sep 17 00:00:00 2001 From: Somefive Date: Mon, 13 Mar 2023 11:17:15 +0800 Subject: [PATCH] Feat: add feature gate to allow disbale cluster watch at the start of vela-core (#5632) Signed-off-by: Somefive --- charts/vela-core/README.md | 1 + .../templates/kubevela-controller.yaml | 1 + charts/vela-core/values.yaml | 2 ++ pkg/features/controller_features.go | 4 +++ pkg/multicluster/virtual_cluster.go | 25 ++++++++++--------- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/charts/vela-core/README.md b/charts/vela-core/README.md index b8e4fcf06..5492e4683 100644 --- a/charts/vela-core/README.md +++ b/charts/vela-core/README.md @@ -100,6 +100,7 @@ helm install --create-namespace -n vela-system kubevela kubevela/vela-core --wai | `featureGates.preDispatchDryRun` | enable dryrun before dispatching resources. Enable this flag can help prevent unsuccessful dispatch resources entering resourcetracker and improve the user experiences of gc but at the cost of increasing network requests. | `true` | | `featureGates.validateComponentWhenSharding` | enable component validation in webhook when sharding mode enabled | `false` | | `featureGates.disableWebhookAutoSchedule` | disable auto schedule for application mutating webhook when sharding enabled | `false` | +| `featureGates.disableBootstrapClusterInfo` | disable the cluster info bootstrap at the starting of the controller | `false` | ### MultiCluster parameters diff --git a/charts/vela-core/templates/kubevela-controller.yaml b/charts/vela-core/templates/kubevela-controller.yaml index 35e34a77b..ec58b02be 100644 --- a/charts/vela-core/templates/kubevela-controller.yaml +++ b/charts/vela-core/templates/kubevela-controller.yaml @@ -302,6 +302,7 @@ spec: - "--feature-gates=GzipApplicationRevision={{- .Values.featureGates.gzipApplicationRevision | toString -}}" - "--feature-gates=ZstdApplicationRevision={{- .Values.featureGates.zstdApplicationRevision | toString -}}" - "--feature-gates=PreDispatchDryRun={{- .Values.featureGates.preDispatchDryRun | toString -}}" + - "--feature-gates=DisableBootstrapClusterInfo={{- .Values.featureGates.disableBootstrapClusterInfo | toString -}}" {{ if .Values.authentication.enabled }} {{ if .Values.authentication.withUser }} - "--authentication-with-user" diff --git a/charts/vela-core/values.yaml b/charts/vela-core/values.yaml index 6502223dd..59978ac47 100644 --- a/charts/vela-core/values.yaml +++ b/charts/vela-core/values.yaml @@ -112,6 +112,7 @@ optimize: ##@param featureGates.preDispatchDryRun enable dryrun before dispatching resources. Enable this flag can help prevent unsuccessful dispatch resources entering resourcetracker and improve the user experiences of gc but at the cost of increasing network requests. ##@param featureGates.validateComponentWhenSharding enable component validation in webhook when sharding mode enabled ##@param featureGates.disableWebhookAutoSchedule disable auto schedule for application mutating webhook when sharding enabled +##@param featureGates.disableBootstrapClusterInfo disable the cluster info bootstrap at the starting of the controller ##@param featureGates: enableLegacyComponentRevision: false @@ -124,6 +125,7 @@ featureGates: preDispatchDryRun: true validateComponentWhenSharding: false disableWebhookAutoSchedule: false + disableBootstrapClusterInfo: false ## @section MultiCluster parameters diff --git a/pkg/features/controller_features.go b/pkg/features/controller_features.go index fb8720061..5213f51d5 100644 --- a/pkg/features/controller_features.go +++ b/pkg/features/controller_features.go @@ -100,6 +100,9 @@ const ( // If set to true, the webhook will not make auto schedule for applications and users can make customized // scheduler for assigning shards to applications DisableWebhookAutoSchedule = "DisableWebhookAutoSchedule" + + // DisableBootstrapClusterInfo disable the cluster info bootstrap at the starting of the controller + DisableBootstrapClusterInfo = "DisableBootstrapClusterInfo" ) var defaultFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{ @@ -121,6 +124,7 @@ var defaultFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{ PreDispatchDryRun: {Default: true, PreRelease: featuregate.Alpha}, ValidateComponentWhenSharding: {Default: false, PreRelease: featuregate.Alpha}, DisableWebhookAutoSchedule: {Default: false, PreRelease: featuregate.Alpha}, + DisableBootstrapClusterInfo: {Default: false, PreRelease: featuregate.Alpha}, } func init() { diff --git a/pkg/multicluster/virtual_cluster.go b/pkg/multicluster/virtual_cluster.go index e43039810..68bda0c8f 100644 --- a/pkg/multicluster/virtual_cluster.go +++ b/pkg/multicluster/virtual_cluster.go @@ -22,6 +22,7 @@ import ( "fmt" "strings" + "github.com/kubevela/pkg/util/singleton" "github.com/oam-dev/cluster-gateway/pkg/generated/clientset/versioned" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" @@ -32,6 +33,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/selection" apitypes "k8s.io/apimachinery/pkg/types" + utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/client-go/rest" "k8s.io/klog/v2" "k8s.io/kubectl/pkg/scheme" @@ -43,6 +45,7 @@ import ( clustercommon "github.com/oam-dev/cluster-gateway/pkg/common" "github.com/oam-dev/kubevela/apis/types" + "github.com/oam-dev/kubevela/pkg/features" "github.com/oam-dev/kubevela/pkg/utils/common" velaerrors "github.com/oam-dev/kubevela/pkg/utils/errors" ) @@ -55,18 +58,16 @@ func InitClusterInfo(cfg *rest.Config) error { if err != nil { return err } - client, err := client.New(cfg, client.Options{Scheme: common.Scheme}) - if err != nil { - return err - } - clusters, err := prismclusterv1alpha1.NewClusterClient(client).List(ctx) - if err != nil { - return errors.Wrap(err, "fail to get registered clusters") - } - for _, cluster := range clusters.Items { - if err = SetClusterVersionInfo(ctx, cfg, cluster.Name); err != nil { - klog.Warningf("set cluster version for %s: %v, skip it...", cluster.Name, err) - continue + if !utilfeature.DefaultMutableFeatureGate.Enabled(features.DisableBootstrapClusterInfo) { + clusters, err := prismclusterv1alpha1.NewClusterClient(singleton.KubeClient.Get()).List(ctx) + if err != nil { + return errors.Wrap(err, "fail to get registered clusters") + } + for _, cluster := range clusters.Items { + if err = SetClusterVersionInfo(ctx, cfg, cluster.Name); err != nil { + klog.Warningf("set cluster version for %s: %v, skip it...", cluster.Name, err) + continue + } } } return nil