diff --git a/cmd/manager/main.go b/cmd/manager/main.go index c53463e5d00..7f28c5d9bdb 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -145,6 +145,7 @@ func init() { viper.SetDefault(intctrlutil.FeatureGateEnableRuntimeMetrics, false) viper.SetDefault(constant.CfgKBReconcileWorkers, 8) viper.SetDefault(constant.FeatureGateIgnoreConfigTemplateDefaultMode, false) + viper.SetDefault(constant.FeatureGateComponentReplicasAnnotation, true) } type flagName string diff --git a/deploy/helm/templates/deployment.yaml b/deploy/helm/templates/deployment.yaml index 5d5e7d74156..f603fc178ba 100644 --- a/deploy/helm/templates/deployment.yaml +++ b/deploy/helm/templates/deployment.yaml @@ -181,6 +181,8 @@ spec: - name: IGNORE_POD_VERTICAL_SCALING value: "true" {{- end }} + - name: COMPONENT_REPLICAS_ANNOTATION + value: {{ .Values.featureGates.componentReplicasAnnotation.enabled | quote }} {{- with .Values.securityContext }} securityContext: {{- toYaml . | nindent 12 }} diff --git a/deploy/helm/values.yaml b/deploy/helm/values.yaml index ecaebb91e8c..f915a9eb105 100644 --- a/deploy/helm/values.yaml +++ b/deploy/helm/values.yaml @@ -1923,6 +1923,8 @@ featureGates: enabled: false ignorePodVerticalScaling: enabled: false + componentReplicasAnnotation: + enabled: true vmagent: diff --git a/pkg/constant/flag.go b/pkg/constant/flag.go index bc5ad76592b..d8859b525c8 100644 --- a/pkg/constant/flag.go +++ b/pkg/constant/flag.go @@ -33,4 +33,7 @@ const ( // HostNetworkAnnotationKey defines the feature gate to enable the host-network for specified components or shardings. HostNetworkAnnotationKey = "kubeblocks.io/host-network" + + // FeatureGateComponentReplicasAnnotation tells whether to add and update the annotation "component-replicas" to all pods of a Component + FeatureGateComponentReplicasAnnotation = "COMPONENT_REPLICAS_ANNOTATION" ) diff --git a/pkg/controller/factory/builder.go b/pkg/controller/factory/builder.go index cca06192a2e..0aa5c50e06e 100644 --- a/pkg/controller/factory/builder.go +++ b/pkg/controller/factory/builder.go @@ -80,7 +80,6 @@ func BuildInstanceSet(synthesizedComp *component.SynthesizedComponent, component synthesizedComp.Annotations, ) - replicasStr := strconv.Itoa(int(synthesizedComp.Replicas)) podBuilder := builder.NewPodBuilder("", ""). AddLabelsInMap(synthesizedComp.Labels). AddLabelsInMap(labels). @@ -88,8 +87,12 @@ func BuildInstanceSet(synthesizedComp *component.SynthesizedComponent, component AddLabelsInMap(constant.GetAppVersionLabel(compDefName)). AddLabelsInMap(synthesizedComp.UserDefinedLabels). AddLabelsInMap(constant.GetClusterWellKnownLabels(clusterName)). - AddAnnotations(constant.ComponentReplicasAnnotationKey, replicasStr). AddAnnotationsInMap(synthesizedComp.UserDefinedAnnotations) + if viper.GetBool(constant.FeatureGateComponentReplicasAnnotation) { + replicasStr := strconv.Itoa(int(synthesizedComp.Replicas)) + podBuilder.AddAnnotations(constant.ComponentReplicasAnnotationKey, replicasStr) + + } template := corev1.PodTemplateSpec{ ObjectMeta: podBuilder.GetObject().ObjectMeta, Spec: *synthesizedComp.PodSpec.DeepCopy(),