Skip to content

Commit

Permalink
feat: support FeatureGateComponentReplicasAnnotation feature gate (#7902
Browse files Browse the repository at this point in the history
)

(cherry picked from commit 5c4f341)
  • Loading branch information
free6om committed Aug 5, 2024
1 parent 621d117 commit 237167b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions deploy/helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 2 additions & 0 deletions deploy/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,8 @@ featureGates:
enabled: false
ignorePodVerticalScaling:
enabled: false
componentReplicasAnnotation:
enabled: true

vmagent:

Expand Down
3 changes: 3 additions & 0 deletions pkg/constant/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
7 changes: 5 additions & 2 deletions pkg/controller/factory/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,19 @@ func BuildInstanceSet(synthesizedComp *component.SynthesizedComponent, component
synthesizedComp.Annotations,
)

replicasStr := strconv.Itoa(int(synthesizedComp.Replicas))
podBuilder := builder.NewPodBuilder("", "").
AddLabelsInMap(synthesizedComp.Labels).
AddLabelsInMap(labels).
AddLabelsInMap(compDefLabel).
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(),
Expand Down

0 comments on commit 237167b

Please sign in to comment.