Skip to content

Commit b5d2af6

Browse files
authored
chore: propagate sharding labels to InstanceSet (#10435)
1 parent db9c15c commit b5d2af6

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

pkg/controller/factory/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func BuildInstanceSet(synthesizedComp *component.SynthesizedComponent, compDef *
5858
// priority: static < dynamic < built-in
5959
AddLabelsInMap(synthesizedComp.StaticLabels).
6060
AddLabelsInMap(synthesizedComp.DynamicLabels).
61-
AddLabelsInMap(constant.GetCompLabels(clusterName, compName)).
61+
AddLabelsInMap(constant.GetCompLabels(clusterName, compName, synthesizedComp.Labels)).
6262
AddAnnotations(constant.KubeBlocksGenerationKey, synthesizedComp.Generation).
6363
AddAnnotations(constant.CRDAPIVersionAnnotationKey, workloads.GroupVersion.String()).
6464
AddAnnotationsInMap(map[string]string{

pkg/controller/factory/builder_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,34 @@ var _ = Describe("builder", func() {
131131
Expect(*its.Spec.MemberUpdateStrategy).Should(BeEquivalentTo(workloads.BestEffortParallelUpdateStrategy))
132132
})
133133

134+
It("propagates sharding labels to InstanceSet metadata", func() {
135+
shardingName := "shard"
136+
compLabels := constant.GetClusterLabels(clusterName, map[string]string{
137+
constant.KBAppShardingNameLabelKey: shardingName,
138+
})
139+
synthesizedComp := &component.SynthesizedComponent{
140+
Namespace: testCtx.DefaultNamespace,
141+
ClusterName: clusterName,
142+
Name: "shard-a",
143+
CompDefName: "mongodb",
144+
Generation: "1",
145+
Labels: compLabels,
146+
DynamicLabels: map[string]string{"dynamic-label": "true"},
147+
Replicas: 1,
148+
PodSpec: &corev1.PodSpec{
149+
Containers: []corev1.Container{{Name: "mongodb"}},
150+
},
151+
}
152+
153+
its, err := BuildInstanceSet(synthesizedComp, nil)
154+
155+
Expect(err).Should(Succeed())
156+
Expect(its.Labels).Should(HaveKeyWithValue(constant.KBAppShardingNameLabelKey, shardingName))
157+
Expect(its.Labels).Should(HaveKeyWithValue("dynamic-label", "true"))
158+
Expect(its.Spec.Selector.MatchLabels).Should(HaveKeyWithValue(constant.KBAppShardingNameLabelKey, shardingName))
159+
Expect(its.Spec.Template.Labels).Should(HaveKeyWithValue(constant.KBAppShardingNameLabelKey, shardingName))
160+
})
161+
134162
It("builds ConfigMap with template correctly", func() {
135163
config := map[string]string{}
136164
_, cluster, synthesizedComponent := newClusterObjs(nil)

0 commit comments

Comments
 (0)