diff --git a/controllers/apps/transformer_component_workload.go b/controllers/apps/transformer_component_workload.go index 799099bebad..ae5eba1e03f 100644 --- a/controllers/apps/transformer_component_workload.go +++ b/controllers/apps/transformer_component_workload.go @@ -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, diff --git a/pkg/controller/component/component.go b/pkg/controller/component/component.go index b90ccb4a472..39edebedd15 100644 --- a/pkg/controller/component/component.go +++ b/pkg/controller/component/component.go @@ -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). @@ -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) }