Skip to content

Commit 40ad303

Browse files
committed
tidyup
1 parent 3f5fadb commit 40ad303

File tree

6 files changed

+15
-199
lines changed

6 files changed

+15
-199
lines changed

controllers/apps/component/component_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,7 @@ var _ = Describe("Component Controller", func() {
22982298
testReconfigureRestart(defaultCompName, compDefObj.Name, fileTemplate)
22992299
})
23002300

2301-
It("reconfigure - config hash", func() {
2301+
PIt("reconfigure - config hash", func() {
23022302
testReconfigureConfigHash(defaultCompName, compDefObj.Name, fileTemplate)
23032303
})
23042304
})

controllers/apps/component/transformer_component_template.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,16 @@ func getFileTemplateObjects(transCtx *componentTransformContext) (map[string]*co
188188

189189
func buildFileTemplateObjects(transCtx *componentTransformContext) (map[string]*corev1.ConfigMap, error) {
190190
objs := make(map[string]*corev1.ConfigMap)
191-
for i, tpl := range transCtx.SynthesizeComponent.FileTemplates {
191+
for _, tpl := range transCtx.SynthesizeComponent.FileTemplates {
192192
// If the file template is managed by external, the cm object has been rendered by the external manager.
193193
if isExternalManaged(tpl) {
194194
continue
195195
}
196-
197196
obj, err := buildFileTemplateObject(transCtx, tpl)
198197
if err != nil {
199198
return nil, err
200199
}
201200
objs[obj.Name] = obj
202-
203-
configHash := obj.Annotations[constant.CMInsConfigurationHashLabelKey]
204-
transCtx.SynthesizeComponent.FileTemplates[i].ConfigHash = &configHash
205201
}
206202
return objs, nil
207203
}

controllers/apps/component/transformer_component_workload_ops.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ func (r *componentWorkloadOps) handleReconfigure(transCtx *componentTransformCon
424424

425425
if len(toCreate) > 0 || len(toDelete) > 0 {
426426
// since pod volumes changed, the workload will be restarted
427-
// TODO: sync reconfigure and then restart
428427
r.protoITS.Spec.Configs = nil
429428
return nil
430429
}
@@ -439,7 +438,6 @@ func (r *componentWorkloadOps) handleReconfigure(transCtx *componentTransformCon
439438
if tpl.Name == tplName {
440439
if ptr.Deref(tpl.RestartOnFileChange, false) {
441440
// restart
442-
// TODO: restart on config
443441
if r.protoITS.Spec.Template.Annotations == nil {
444442
r.protoITS.Spec.Template.Annotations = map[string]string{}
445443
}

controllers/workloads/instanceset_controller_test.go

Lines changed: 1 addition & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ var _ = Describe("InstanceSet Controller", func() {
107107
).Should(Succeed())
108108
}
109109

110-
mockPodReady := func(podNames ...string) []*corev1.Pod {
110+
mockPodReady := func(podNames ...string) {
111111
By("mock pods ready")
112-
pods := make([]*corev1.Pod, 0)
113112
for _, podName := range podNames {
114113
podKey := types.NamespacedName{
115114
Namespace: itsObj.Namespace,
@@ -133,10 +132,8 @@ var _ = Describe("InstanceSet Controller", func() {
133132
Image: pod.Spec.Containers[0].Image,
134133
},
135134
}
136-
pods = append(pods, pod)
137135
})()).Should(Succeed())
138136
}
139-
return pods
140137
}
141138

142139
Context("reconciliation", func() {
@@ -627,173 +624,6 @@ var _ = Describe("InstanceSet Controller", func() {
627624
g.Expect(parameters).Should(HaveKeyWithValue("foo", "bar"))
628625
}).Should(Succeed())
629626
})
630-
631-
It("restart", func() {
632-
createITSObj(itsName, func(f *testapps.MockInstanceSetFactory) {
633-
f.SetInstanceUpdateStrategy(&workloads.InstanceUpdateStrategy{
634-
Type: kbappsv1.RollingUpdateStrategyType,
635-
}).AddConfigs([]workloads.ConfigTemplate{
636-
{
637-
Name: "server",
638-
ConfigHash: ptr.To("123456"),
639-
},
640-
{
641-
Name: "logging",
642-
ConfigHash: ptr.To("654321"),
643-
},
644-
}...)
645-
})
646-
647-
pods := mockPodReady(fmt.Sprintf("%s-0", itsObj.Name))
648-
Expect(pods).Should(HaveLen(1))
649-
650-
By("check the init instance status")
651-
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
652-
g.Expect(its.Status.InstanceStatus).Should(HaveLen(1))
653-
g.Expect(its.Status.InstanceStatus[0]).Should(Equal(workloads.InstanceStatus{
654-
PodName: fmt.Sprintf("%s-0", itsObj.Name),
655-
Configs: []workloads.InstanceConfigStatus{
656-
{
657-
Name: "server",
658-
ConfigHash: ptr.To("123456"),
659-
},
660-
{
661-
Name: "logging",
662-
ConfigHash: ptr.To("654321"),
663-
},
664-
},
665-
}))
666-
})).Should(Succeed())
667-
668-
By("update configs to restart")
669-
Expect(testapps.GetAndChangeObj(&testCtx, itsKey, func(its *workloads.InstanceSet) {
670-
its.Spec.Configs[1].ConfigHash = ptr.To("abcdef")
671-
its.Spec.Configs[1].Restart = ptr.To(true)
672-
})()).ShouldNot(HaveOccurred())
673-
674-
By("check the instance status updated")
675-
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
676-
g.Expect(its.Status.InstanceStatus).Should(HaveLen(1))
677-
g.Expect(its.Status.InstanceStatus[0]).Should(Equal(workloads.InstanceStatus{
678-
PodName: fmt.Sprintf("%s-0", itsObj.Name),
679-
Configs: []workloads.InstanceConfigStatus{
680-
{
681-
Name: "server",
682-
ConfigHash: ptr.To("123456"),
683-
},
684-
{
685-
Name: "logging",
686-
ConfigHash: ptr.To("abcdef"),
687-
},
688-
},
689-
}))
690-
})).Should(Succeed())
691-
692-
By("check the instance restarted")
693-
podKey := client.ObjectKeyFromObject(pods[0])
694-
Eventually(testapps.CheckObj(&testCtx, podKey, func(g Gomega, pod *corev1.Pod) {
695-
// g.Expect(pod.UID).ShouldNot(Equal(pods[0].UID)) TODO: impl
696-
})).Should(Succeed())
697-
})
698-
699-
It("reconfigure and restart", func() {
700-
By("mock reconfigure action calls")
701-
var (
702-
reconfigure string
703-
parameters map[string]string
704-
)
705-
testapps.MockKBAgentClient(func(recorder *kbacli.MockClientMockRecorder) {
706-
recorder.Action(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, req kbaproto.ActionRequest) (kbaproto.ActionResponse, error) {
707-
if req.Action == "reconfigure" || strings.HasPrefix(req.Action, "udf-reconfigure") {
708-
reconfigure = req.Action
709-
parameters = req.Parameters
710-
}
711-
return kbaproto.ActionResponse{}, nil
712-
}).AnyTimes()
713-
})
714-
715-
createITSObj(itsName, func(f *testapps.MockInstanceSetFactory) {
716-
f.SetInstanceUpdateStrategy(&workloads.InstanceUpdateStrategy{
717-
Type: kbappsv1.RollingUpdateStrategyType,
718-
}).AddConfigs([]workloads.ConfigTemplate{
719-
{
720-
Name: "server",
721-
ConfigHash: ptr.To("123456"),
722-
},
723-
{
724-
Name: "logging",
725-
ConfigHash: ptr.To("654321"),
726-
},
727-
}...)
728-
})
729-
730-
pods := mockPodReady(fmt.Sprintf("%s-0", itsObj.Name))
731-
Expect(pods).Should(HaveLen(1))
732-
733-
By("check the init instance status")
734-
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
735-
g.Expect(its.Status.InstanceStatus).Should(HaveLen(1))
736-
g.Expect(its.Status.InstanceStatus[0]).Should(Equal(workloads.InstanceStatus{
737-
PodName: fmt.Sprintf("%s-0", itsObj.Name),
738-
Configs: []workloads.InstanceConfigStatus{
739-
{
740-
Name: "server",
741-
ConfigHash: ptr.To("123456"),
742-
},
743-
{
744-
Name: "logging",
745-
ConfigHash: ptr.To("654321"),
746-
},
747-
},
748-
}))
749-
})).Should(Succeed())
750-
751-
By("check the reconfigure action NOT called")
752-
Eventually(func(g Gomega) {
753-
g.Expect(reconfigure).Should(BeEmpty())
754-
g.Expect(parameters).Should(BeNil())
755-
}).Should(Succeed())
756-
757-
By("update configs to reconfigure and restart")
758-
Expect(testapps.GetAndChangeObj(&testCtx, itsKey, func(its *workloads.InstanceSet) {
759-
its.Spec.Configs[1].ConfigHash = ptr.To("abcdef")
760-
its.Spec.Configs[1].Restart = ptr.To(true)
761-
its.Spec.Configs[1].Reconfigure = testapps.NewLifecycleAction("reconfigure")
762-
its.Spec.Configs[1].ReconfigureActionName = ""
763-
its.Spec.Configs[1].Parameters = map[string]string{"foo": "bar"}
764-
})()).ShouldNot(HaveOccurred())
765-
766-
By("check the instance status updated")
767-
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
768-
g.Expect(its.Status.InstanceStatus).Should(HaveLen(1))
769-
g.Expect(its.Status.InstanceStatus[0]).Should(Equal(workloads.InstanceStatus{
770-
PodName: fmt.Sprintf("%s-0", itsObj.Name),
771-
Configs: []workloads.InstanceConfigStatus{
772-
{
773-
Name: "server",
774-
ConfigHash: ptr.To("123456"),
775-
},
776-
{
777-
Name: "logging",
778-
ConfigHash: ptr.To("abcdef"),
779-
},
780-
},
781-
}))
782-
})).Should(Succeed())
783-
784-
By("check the reconfigure action call")
785-
Eventually(func(g Gomega) {
786-
g.Expect(reconfigure).Should(Equal("reconfigure"))
787-
g.Expect(parameters).ShouldNot(BeNil())
788-
g.Expect(parameters).Should(HaveKeyWithValue("foo", "bar"))
789-
}).Should(Succeed())
790-
791-
By("check the instance restarted")
792-
podKey := client.ObjectKeyFromObject(pods[0])
793-
Eventually(testapps.CheckObj(&testCtx, podKey, func(g Gomega, pod *corev1.Pod) {
794-
// g.Expect(pod.UID).ShouldNot(Equal(pods[0].UID)) TODO: impl
795-
})).Should(Succeed())
796-
})
797627
})
798628

799629
Context("pod naming rule", func() {

pkg/controller/component/synthesize_component_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ var _ = Describe("synthesized component", func() {
176176
Template: comp.Spec.Configs[0].ConfigMap.Name,
177177
Namespace: comp.Namespace,
178178
VolumeName: compDef.Spec.Configs[1].VolumeName,
179-
Reconfigure: comp.Spec.Configs[0].Reconfigure,
180179
ExternalManaged: comp.Spec.Configs[0].ExternalManaged,
180+
Reconfigure: comp.Spec.Configs[0].Reconfigure,
181181
},
182182
Config: true,
183183
}))

pkg/controller/instanceset/reconciler_update.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (r *updateReconciler) memberUpdateQuota(its *workloads.InstanceSet, podList
245245
// if it's a roleful InstanceSet, we use updateCount to represent Pods can be updated according to the spec.memberUpdateStrategy.
246246
updateCount := len(podList)
247247
if len(its.Spec.Roles) > 0 {
248-
plan := NewUpdatePlan(*its, podList, r.isInstUpdated)
248+
plan := NewUpdatePlan(*its, podList, r.isPodOrConfigUpdated)
249249
podsToBeUpdated, err := plan.Execute()
250250
if err != nil {
251251
return -1, err
@@ -300,17 +300,17 @@ func (r *updateReconciler) reconfigure(tree *kubebuilderx.ObjectTree, its *workl
300300
for _, config := range its.Spec.Configs {
301301
if !r.isConfigUpdated(its, pod, config) {
302302
allUpdated = false
303-
if err := r.reconfigureInst(tree, its, pod, config); err != nil {
303+
if err := r.reconfigureConfig(tree, its, pod, config); err != nil {
304304
return false, err
305305
}
306306
}
307307
// TODO: compose the status from pods but not the its spec and status
308-
r.setInstConfigStatus(its, pod, config)
308+
r.setInstanceConfigStatus(its, pod, config)
309309
}
310310
return allUpdated, nil
311311
}
312312

313-
func (r *updateReconciler) reconfigureInst(tree *kubebuilderx.ObjectTree, its *workloads.InstanceSet, pod *corev1.Pod, config workloads.ConfigTemplate) error {
313+
func (r *updateReconciler) reconfigureConfig(tree *kubebuilderx.ObjectTree, its *workloads.InstanceSet, pod *corev1.Pod, config workloads.ConfigTemplate) error {
314314
if config.Reconfigure == nil {
315315
return nil // skip
316316
}
@@ -344,7 +344,7 @@ func (r *updateReconciler) reconfigureInst(tree *kubebuilderx.ObjectTree, its *w
344344
return nil
345345
}
346346

347-
func (r *updateReconciler) setInstConfigStatus(its *workloads.InstanceSet, pod *corev1.Pod, config workloads.ConfigTemplate) {
347+
func (r *updateReconciler) setInstanceConfigStatus(its *workloads.InstanceSet, pod *corev1.Pod, config workloads.ConfigTemplate) {
348348
if its.Status.InstanceStatus == nil {
349349
its.Status.InstanceStatus = make([]workloads.InstanceStatus, 0)
350350
}
@@ -372,27 +372,19 @@ func (r *updateReconciler) setInstConfigStatus(its *workloads.InstanceSet, pod *
372372
its.Status.InstanceStatus[idx].Configs = append(its.Status.InstanceStatus[idx].Configs, status)
373373
}
374374

375-
func (r *updateReconciler) isInstUpdated(its *workloads.InstanceSet, pod *corev1.Pod) (bool, error) {
376-
updated, err := r.isPodUpdated(its, pod)
377-
if err != nil || !updated {
378-
return updated, err
379-
}
380-
for _, config := range its.Spec.Configs {
381-
if !r.isConfigUpdated(its, pod, config) {
382-
return false, nil
383-
}
384-
}
385-
return true, nil
386-
}
387-
388-
func (r *updateReconciler) isPodUpdated(its *workloads.InstanceSet, pod *corev1.Pod) (bool, error) {
375+
func (r *updateReconciler) isPodOrConfigUpdated(its *workloads.InstanceSet, pod *corev1.Pod) (bool, error) {
389376
policy, _, err := getPodUpdatePolicy(its, pod)
390377
if err != nil {
391378
return false, err
392379
}
393380
if policy != noOpsPolicy {
394381
return false, nil
395382
}
383+
for _, config := range its.Spec.Configs {
384+
if !r.isConfigUpdated(its, pod, config) {
385+
return false, nil
386+
}
387+
}
396388
return true, nil
397389
}
398390

0 commit comments

Comments
 (0)