Skip to content

Commit 4aebbc4

Browse files
committed
init
1 parent 65dfc72 commit 4aebbc4

File tree

15 files changed

+150
-143
lines changed

15 files changed

+150
-143
lines changed

apis/apps/v1/deprecated.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,9 @@ func (r *Cluster) IsStatusUpdating() bool {
4040
return !r.IsDeleting() && !r.IsUpdating()
4141
}
4242

43-
func (r *Cluster) GetComponentByName(componentName string) *ClusterComponentSpec {
44-
for _, v := range r.Spec.ComponentSpecs {
45-
if v.Name == componentName {
46-
return &v
47-
}
48-
}
49-
return nil
50-
}
51-
52-
func (r *ClusterSpec) GetComponentByName(componentName string) *ClusterComponentSpec {
43+
func (r *ClusterSpec) GetComponentByName(compName string) *ClusterComponentSpec {
5344
for i, v := range r.ComponentSpecs {
54-
if v.Name == componentName {
45+
if v.Name == compName {
5546
return &r.ComponentSpecs[i]
5647
}
5748
}

apis/workloads/v1/instanceset_types.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -534,15 +534,15 @@ type ConfigTemplate struct {
534534
// The name of the config.
535535
Name string `json:"name"`
536536

537-
// The generation of the config content.
537+
// Represents a checksum or hash of the config content.
538538
//
539539
// +optional
540-
Generation int64 `json:"generation,omitempty"`
540+
ConfigHash *string `json:"configHash,omitempty"`
541541

542-
// Represents a checksum or hash of the config content.
542+
// Specifies whether to restart instances.
543543
//
544544
// +optional
545-
ConfigHash *string `json:"configHash,omitempty"`
545+
Restart *bool `json:"restart,omitempty"`
546546

547547
// The custom reconfigure action.
548548
//
@@ -591,11 +591,6 @@ type InstanceConfigStatus struct {
591591
// +kubebuilder:validation:Required
592592
Name string `json:"name"`
593593

594-
// The generation of the config.
595-
//
596-
// +optional
597-
Generation int64 `json:"generation,omitempty"`
598-
599594
// Represents a checksum or hash of the config content.
600595
//
601596
// +optional

apis/workloads/v1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/workloads.kubeblocks.io_instancesets.yaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ spec:
7272
configHash:
7373
description: Represents a checksum or hash of the config content.
7474
type: string
75-
generation:
76-
description: The generation of the config content.
77-
format: int64
78-
type: integer
7975
name:
8076
description: The name of the config.
8177
type: string
@@ -525,6 +521,9 @@ spec:
525521

526522
An empty name indicates that the reconfigure action is the default one defined by lifecycle actions.
527523
type: string
524+
restart:
525+
description: Specifies whether to restart instances.
526+
type: boolean
528527
required:
529528
- name
530529
type: object
@@ -11783,10 +11782,6 @@ spec:
1178311782
description: Represents a checksum or hash of the config
1178411783
content.
1178511784
type: string
11786-
generation:
11787-
description: The generation of the config.
11788-
format: int64
11789-
type: integer
1179011785
name:
1179111786
description: The name of the config.
1179211787
type: string

controllers/apps/component/component_controller_test.go

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,7 @@ var _ = Describe("Component Controller", func() {
15221522
Variables: map[string]string{
15231523
"LOG_LEVEL": "debug",
15241524
},
1525+
ConfigHash: ptr.To("123456"),
15251526
},
15261527
}
15271528
})()).Should(Succeed())
@@ -1536,7 +1537,8 @@ var _ = Describe("Component Controller", func() {
15361537
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
15371538
g.Expect(its.Spec.Configs).Should(HaveLen(1))
15381539
g.Expect(its.Spec.Configs[0].Name).Should(Equal(fileTemplate))
1539-
g.Expect(its.Spec.Configs[0].Generation).Should(Equal(its.Generation))
1540+
g.Expect(its.Spec.Configs[0].ConfigHash).ShouldNot(BeNil())
1541+
g.Expect(*its.Spec.Configs[0].ConfigHash).Should(Equal("123456"))
15401542
g.Expect(its.Spec.Configs[0].Reconfigure).ShouldNot(BeNil())
15411543
g.Expect(its.Spec.Configs[0].ReconfigureActionName).Should(BeEmpty())
15421544
g.Expect(its.Spec.Configs[0].Parameters).Should(HaveKey("KB_CONFIG_FILES_UPDATED"))
@@ -1571,6 +1573,7 @@ var _ = Describe("Component Controller", func() {
15711573
comp.Spec.Configs[0].Variables = map[string]string{
15721574
"LOG_LEVEL": "warn",
15731575
}
1576+
comp.Spec.Configs[0].ConfigHash = ptr.To("123456")
15741577
})()).Should(Succeed())
15751578

15761579
By("check the file template object again")
@@ -1583,7 +1586,8 @@ var _ = Describe("Component Controller", func() {
15831586
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
15841587
g.Expect(its.Spec.Configs).Should(HaveLen(1))
15851588
g.Expect(its.Spec.Configs[0].Name).Should(Equal(fileTemplate))
1586-
g.Expect(its.Spec.Configs[0].Generation).Should(Equal(its.Generation))
1589+
g.Expect(its.Spec.Configs[0].ConfigHash).ShouldNot(BeNil())
1590+
g.Expect(*its.Spec.Configs[0].ConfigHash).Should(Equal("123456"))
15871591
g.Expect(its.Spec.Configs[0].Reconfigure).ShouldNot(BeNil())
15881592
g.Expect(its.Spec.Configs[0].ReconfigureActionName).Should(Equal(fmt.Sprintf("reconfigure-%s", fileTemplate)))
15891593
g.Expect(its.Spec.Configs[0].Parameters).Should(HaveKey("KB_CONFIG_FILES_UPDATED"))
@@ -1672,6 +1676,54 @@ var _ = Describe("Component Controller", func() {
16721676
})).Should(Succeed())
16731677
}
16741678

1679+
testReconfigureConfigHash := func(compName, compDefName, fileTemplate string) {
1680+
var (
1681+
initConfigHash, newConfigHash string
1682+
)
1683+
1684+
createCompObj(compName, compDefName, nil)
1685+
1686+
By("check the file template object")
1687+
fileTemplateCMKey := types.NamespacedName{
1688+
Namespace: testCtx.DefaultNamespace,
1689+
Name: fileTemplateObjectName(&component.SynthesizedComponent{FullCompName: compKey.Name}, fileTemplate),
1690+
}
1691+
Eventually(testapps.CheckObj(&testCtx, fileTemplateCMKey, func(g Gomega, cm *corev1.ConfigMap) {
1692+
g.Expect(cm.Data).Should(HaveKeyWithValue("level", "info"))
1693+
initConfigHash = cm.Annotations[constant.CMInsConfigurationHashLabelKey]
1694+
g.Expect(initConfigHash).NotTo(BeEmpty())
1695+
})).Should(Succeed())
1696+
1697+
By("update the config template variables")
1698+
Expect(testapps.GetAndChangeObj(&testCtx, compKey, func(comp *kbappsv1.Component) {
1699+
comp.Spec.Configs = []kbappsv1.ClusterComponentConfig{
1700+
{
1701+
Name: ptr.To(fileTemplate),
1702+
Variables: map[string]string{
1703+
"LOG_LEVEL": "debug",
1704+
},
1705+
},
1706+
}
1707+
})()).Should(Succeed())
1708+
1709+
By("check the file template object again")
1710+
Eventually(testapps.CheckObj(&testCtx, fileTemplateCMKey, func(g Gomega, cm *corev1.ConfigMap) {
1711+
g.Expect(cm.Data).Should(HaveKeyWithValue("level", "debug"))
1712+
newConfigHash = cm.Annotations[constant.CMInsConfigurationHashLabelKey]
1713+
g.Expect(newConfigHash).NotTo(BeEmpty())
1714+
g.Expect(newConfigHash).NotTo(Equal(initConfigHash))
1715+
})).Should(Succeed())
1716+
1717+
By("check the workload updated")
1718+
itsKey := compKey
1719+
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
1720+
g.Expect(its.Spec.Configs).Should(HaveLen(1))
1721+
g.Expect(its.Spec.Configs[0].Name).Should(Equal(fileTemplate))
1722+
g.Expect(its.Spec.Configs[0].ConfigHash).ShouldNot(BeNil())
1723+
g.Expect(*its.Spec.Configs[0].ConfigHash).Should(Equal(newConfigHash))
1724+
})).Should(Succeed())
1725+
}
1726+
16751727
Context("provisioning", func() {
16761728
BeforeEach(func() {
16771729
createDefinitionObjects()
@@ -2245,5 +2297,9 @@ var _ = Describe("Component Controller", func() {
22452297
It("reconfigure - restart", func() {
22462298
testReconfigureRestart(defaultCompName, compDefObj.Name, fileTemplate)
22472299
})
2300+
2301+
It("reconfigure - config hash", func() {
2302+
testReconfigureConfigHash(defaultCompName, compDefObj.Name, fileTemplate)
2303+
})
22482304
})
22492305
})

controllers/apps/component/transformer_component_workload_ops.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"crypto/sha256"
2424
"errors"
2525
"fmt"
26+
"maps"
2627
"path/filepath"
2728
"reflect"
2829
"slices"
@@ -452,7 +453,7 @@ func (r *componentWorkloadOps) handleReconfigure(transCtx *componentTransformCon
452453
action *appsv1.Action
453454
actionName string
454455
)
455-
if tpl.ExternalManaged != nil && *tpl.ExternalManaged {
456+
if ptr.Deref(tpl.ExternalManaged, false) {
456457
if tpl.Reconfigure == nil {
457458
return // disabled by the external system
458459
}
@@ -467,12 +468,15 @@ func (r *componentWorkloadOps) handleReconfigure(transCtx *componentTransformCon
467468
return // has no reconfigure action defined
468469
}
469470

471+
parameters := lifecycle.FileTemplateChanges(changes.Created, changes.Removed, changes.Updated)
472+
maps.Copy(parameters, tpl.Variables)
470473
config := workloads.ConfigTemplate{
471474
Name: tpl.Name,
472-
Generation: r.component.Generation,
475+
ConfigHash: tpl.ConfigHash,
476+
Restart: tpl.RestartOnFileChange,
473477
Reconfigure: action,
474478
ReconfigureActionName: actionName,
475-
Parameters: lifecycle.FileTemplateChanges(changes.Created, changes.Removed, changes.Updated),
479+
Parameters: parameters,
476480
}
477481
if r.protoITS.Spec.Configs == nil {
478482
r.protoITS.Spec.Configs = make([]workloads.ConfigTemplate, 0)

controllers/workloads/instanceset_controller_test.go

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ var _ = Describe("InstanceSet Controller", func() {
424424
createITSObj(itsName, func(f *testapps.MockInstanceSetFactory) {
425425
f.AddConfigs(workloads.ConfigTemplate{
426426
Name: "server",
427-
Generation: int64(1),
427+
ConfigHash: ptr.To("123456"),
428428
})
429429
})
430430

@@ -436,7 +436,7 @@ var _ = Describe("InstanceSet Controller", func() {
436436
Configs: []workloads.InstanceConfigStatus{
437437
{
438438
Name: "server",
439-
Generation: int64(1),
439+
ConfigHash: ptr.To("123456"),
440440
},
441441
},
442442
}))
@@ -465,39 +465,16 @@ var _ = Describe("InstanceSet Controller", func() {
465465
}).AddConfigs([]workloads.ConfigTemplate{
466466
{
467467
Name: "server",
468-
Generation: int64(1),
468+
ConfigHash: ptr.To("123456"),
469469
},
470470
{
471471
Name: "logging",
472-
Generation: int64(2),
472+
ConfigHash: ptr.To("123456"),
473473
},
474474
}...)
475475
})
476476

477-
By("mock pods running and available")
478-
podKey := types.NamespacedName{
479-
Namespace: itsObj.Namespace,
480-
Name: fmt.Sprintf("%s-0", itsObj.Name),
481-
}
482-
Expect(testapps.GetAndChangeObjStatus(&testCtx, podKey, func(pod *corev1.Pod) {
483-
pod.Status.Phase = corev1.PodRunning
484-
pod.Status.Conditions = []corev1.PodCondition{
485-
{
486-
Type: corev1.PodReady,
487-
Status: corev1.ConditionTrue,
488-
LastTransitionTime: metav1.Now(),
489-
},
490-
}
491-
pod.Status.ContainerStatuses = []corev1.ContainerStatus{
492-
{
493-
Name: pod.Spec.Containers[0].Name,
494-
State: corev1.ContainerState{
495-
Running: &corev1.ContainerStateRunning{},
496-
},
497-
Image: pod.Spec.Containers[0].Image,
498-
},
499-
}
500-
})()).ShouldNot(HaveOccurred())
477+
mockPodReady(fmt.Sprintf("%s-0", itsObj.Name))
501478

502479
By("check the init instance status")
503480
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
@@ -507,25 +484,25 @@ var _ = Describe("InstanceSet Controller", func() {
507484
Configs: []workloads.InstanceConfigStatus{
508485
{
509486
Name: "server",
510-
Generation: int64(1),
487+
ConfigHash: ptr.To("123456"),
511488
},
512489
{
513490
Name: "logging",
514-
Generation: int64(2),
491+
ConfigHash: ptr.To("123456"),
515492
},
516493
},
517494
}))
518495
})).Should(Succeed())
519496

520-
By("check the reconfigure action not called")
497+
By("check the reconfigure action NOT called")
521498
Eventually(func(g Gomega) {
522499
g.Expect(reconfigure).Should(BeEmpty())
523500
g.Expect(parameters).Should(BeNil())
524501
}).Should(Succeed())
525502

526-
By("update configs")
503+
By("update configs to reconfigure")
527504
Expect(testapps.GetAndChangeObj(&testCtx, itsKey, func(its *workloads.InstanceSet) {
528-
its.Spec.Configs[1].Generation = 128
505+
its.Spec.Configs[1].ConfigHash = ptr.To("abcdef")
529506
its.Spec.Configs[1].Reconfigure = testapps.NewLifecycleAction("reconfigure")
530507
its.Spec.Configs[1].ReconfigureActionName = ""
531508
its.Spec.Configs[1].Parameters = map[string]string{"foo": "bar"}
@@ -539,11 +516,11 @@ var _ = Describe("InstanceSet Controller", func() {
539516
Configs: []workloads.InstanceConfigStatus{
540517
{
541518
Name: "server",
542-
Generation: int64(1),
519+
ConfigHash: ptr.To("123456"),
543520
},
544521
{
545522
Name: "logging",
546-
Generation: int64(128),
523+
ConfigHash: ptr.To("abcdef"),
547524
},
548525
},
549526
}))
@@ -579,11 +556,11 @@ var _ = Describe("InstanceSet Controller", func() {
579556
}).AddConfigs([]workloads.ConfigTemplate{
580557
{
581558
Name: "server",
582-
Generation: int64(1),
559+
ConfigHash: ptr.To("123456"),
583560
},
584561
{
585562
Name: "logging",
586-
Generation: int64(2),
563+
ConfigHash: ptr.To("123456"),
587564
},
588565
}...)
589566
})
@@ -598,25 +575,25 @@ var _ = Describe("InstanceSet Controller", func() {
598575
Configs: []workloads.InstanceConfigStatus{
599576
{
600577
Name: "server",
601-
Generation: int64(1),
578+
ConfigHash: ptr.To("123456"),
602579
},
603580
{
604581
Name: "logging",
605-
Generation: int64(2),
582+
ConfigHash: ptr.To("123456"),
606583
},
607584
},
608585
}))
609586
})).Should(Succeed())
610587

611-
By("check the reconfigure action not called")
588+
By("check the reconfigure action NOT called")
612589
Eventually(func(g Gomega) {
613590
g.Expect(reconfigure).Should(BeEmpty())
614591
g.Expect(parameters).Should(BeNil())
615592
}).Should(Succeed())
616593

617-
By("update configs")
594+
By("update configs to reconfigure")
618595
Expect(testapps.GetAndChangeObj(&testCtx, itsKey, func(its *workloads.InstanceSet) {
619-
its.Spec.Configs[1].Generation = 128
596+
its.Spec.Configs[1].ConfigHash = ptr.To("abcdef")
620597
its.Spec.Configs[1].Reconfigure = testapps.NewLifecycleAction("reconfigure")
621598
its.Spec.Configs[1].ReconfigureActionName = "reconfigure-server"
622599
its.Spec.Configs[1].Parameters = map[string]string{"foo": "bar"}
@@ -630,11 +607,11 @@ var _ = Describe("InstanceSet Controller", func() {
630607
Configs: []workloads.InstanceConfigStatus{
631608
{
632609
Name: "server",
633-
Generation: int64(1),
610+
ConfigHash: ptr.To("123456"),
634611
},
635612
{
636613
Name: "logging",
637-
Generation: int64(128),
614+
ConfigHash: ptr.To("abcdef"),
638615
},
639616
},
640617
}))

0 commit comments

Comments
 (0)