Skip to content

Commit

Permalink
chore: don't set placement annotation if no multi-cluster configured (#…
Browse files Browse the repository at this point in the history
…7677)

(cherry picked from commit d7fbbd8)
  • Loading branch information
leon-inf committed Jul 2, 2024
1 parent 5a14a34 commit f2c59dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 6 additions & 3 deletions controllers/apps/transformer_component_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,10 +909,13 @@ func getRunningVolumes(ctx context.Context, cli client.Client, synthesizedComp *
}

func buildInstanceSetPlacementAnnotation(comp *appsv1alpha1.Component, its *workloads.InstanceSet) {
if its.Annotations == nil {
its.Annotations = make(map[string]string)
p := placement(comp)
if len(p) > 0 {
if its.Annotations == nil {
its.Annotations = make(map[string]string)
}
its.Annotations[constant.KBAppMultiClusterPlacementKey] = p
}
its.Annotations[constant.KBAppMultiClusterPlacementKey] = placement(comp)
}

func newComponentWorkloadOps(reqCtx intctrlutil.RequestCtx,
Expand Down
7 changes: 6 additions & 1 deletion pkg/controller/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func BuildComponent(cluster *appsv1alpha1.Cluster, compSpec *appsv1alpha1.Cluste
}()
compBuilder := builder.NewComponentBuilder(cluster.Namespace, compName, compDefName).
AddAnnotations(constant.KubeBlocksGenerationKey, strconv.FormatInt(cluster.Generation, 10)).
AddAnnotations(constant.KBAppMultiClusterPlacementKey, cluster.Annotations[constant.KBAppMultiClusterPlacementKey]).
AddLabelsInMap(constant.GetComponentWellKnownLabels(cluster.Name, compSpec.Name)).
AddLabels(constant.KBAppClusterUIDLabelKey, string(cluster.UID)).
SetServiceVersion(compSpec.ServiceVersion).
Expand Down Expand Up @@ -110,6 +109,12 @@ func BuildComponent(cluster *appsv1alpha1.Cluster, compSpec *appsv1alpha1.Cluste
if annotations != nil {
compBuilder.AddAnnotationsInMap(annotations)
}
if cluster.Annotations != nil {
p, ok := cluster.Annotations[constant.KBAppMultiClusterPlacementKey]
if ok {
compBuilder.AddAnnotations(constant.KBAppMultiClusterPlacementKey, p)
}
}
if !IsGenerated(compBuilder.GetObject()) {
compBuilder.SetServices(compSpec.Services)
}
Expand Down

0 comments on commit f2c59dd

Please sign in to comment.