Skip to content

Commit c4d6445

Browse files
authored
fix: redis cluster creates failed and always is deleting (#9422)
1 parent f92a6bd commit c4d6445

5 files changed

Lines changed: 23 additions & 5 deletions

File tree

controllers/apps/transformer_component_account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (t *componentAccountTransformer) Transform(ctx graph.TransformContext, dag
7777
existSecretCopy := existSecret.DeepCopy()
7878
ctrlutil.MergeMetadataMapInplace(secret.Labels, &existSecretCopy.Labels)
7979
ctrlutil.MergeMetadataMapInplace(secret.Annotations, &existSecretCopy.Annotations)
80-
if !reflect.DeepEqual(existSecret, existSecretCopy) {
80+
if !reflect.DeepEqual(existSecret, existSecretCopy) || !model.IsOwnerOf(transCtx.ComponentOrig, existSecret) {
8181
graphCli.Update(dag, existSecret, existSecretCopy, inUniversalContext4G())
8282
}
8383
}

controllers/apps/transformer_component_vars.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func createOrUpdateEnvConfigMap(ctx graph.TransformContext, dag *graph.DAG, data
182182
SetData(data).
183183
GetObject()
184184
graphCli.Create(dag, obj, inDataContext4G())
185-
} else if !reflect.DeepEqual(envObj.Data, data) {
185+
} else if !reflect.DeepEqual(envObj.Data, data) || !model.IsOwnerOf(transCtx.ComponentOrig, envObj) {
186186
envObjCopy := envObj.DeepCopy()
187187
envObjCopy.Data = data
188188
graphCli.Update(dag, envObj, envObjCopy, inDataContext4G())

pkg/controller/component/component_lifecycle_action_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func renderActionCmdJob(ctx context.Context, cli client.Reader, actionCtx *Actio
231231
},
232232
},
233233
}
234-
if err := BuildJobSchdulingPolicy(jobObj, actionCtx.component, actionCtx.cluster); err != nil {
234+
if err := BuildJobSchdulingPolicy(jobObj, actionCtx.component.DeepCopy(), actionCtx.cluster); err != nil {
235235
return nil, err
236236
}
237237
for i := range jobObj.Spec.Template.Spec.Containers {

pkg/controller/component/component_lifecycle_action_utils_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,30 @@ var _ = Describe("Component LifeCycle Action Utils Test", func() {
157157
}}
158158
Expect(k8sClient.Status().Update(ctx, &pod)).Should(Succeed())
159159
}
160+
comp.Spec.SchedulingPolicy = &appsv1alpha1.SchedulingPolicy{
161+
Affinity: &corev1.Affinity{
162+
PodAntiAffinity: &corev1.PodAntiAffinity{
163+
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{{
164+
Weight: 1,
165+
PodAffinityTerm: corev1.PodAffinityTerm{
166+
LabelSelector: &metav1.LabelSelector{
167+
MatchLabels: map[string]string{
168+
constant.AppInstanceLabelKey: clusterName,
169+
},
170+
},
171+
},
172+
}},
173+
},
174+
},
175+
}
160176
actionCtx, err = NewActionContext(cluster, comp, nil, synthesizeComp.LifecycleActions, synthesizeComp.ScriptTemplates, PreTerminateAction)
161177
Expect(err).Should(Succeed())
162178
renderJob, err := renderActionCmdJob(testCtx.Ctx, testCtx.Cli, actionCtx)
163179
Expect(err).Should(Succeed())
164180
Expect(renderJob).ShouldNot(BeNil())
165-
Expect(len(renderJob.Spec.Template.Spec.Containers[0].Env) == 11).Should(BeTrue())
181+
Expect(renderJob.Spec.Template.Spec.Containers[0].Env).ShouldNot(BeNil())
182+
Expect(renderJob.Spec.Template.Spec.Affinity.PodAntiAffinity).Should(BeNil())
183+
Expect(actionCtx.component.Spec.SchedulingPolicy.Affinity.PodAntiAffinity).ShouldNot(BeNil())
166184
compListExist := false
167185
deletingCompListExist := false
168186
undeletedCompListExist := false

pkg/controller/component/vars.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ func resolveServiceLoadBalancerRef(ctx context.Context, cli client.Reader, synth
713713
}
714714
return &corev1.EnvVar{Name: defineKey, Value: *points}, nil, nil
715715
}
716-
return resolveServiceVarRefLow(ctx, cli, synthesizedComp, selector, selector.Host, resolveLoadBalancer)
716+
return resolveServiceVarRefLow(ctx, cli, synthesizedComp, selector, selector.LoadBalancer, resolveLoadBalancer)
717717
}
718718

719719
func composeLoadBalancerValueFromServices(obj any) *string {

0 commit comments

Comments
 (0)