Skip to content

Commit 69b8c50

Browse files
authored
chore: perform config reconfigure and restart in ITS (#10068)
1 parent a7ee586 commit 69b8c50

38 files changed

Lines changed: 940 additions & 566 deletions

apis/apps/v1/componentdefinition_types.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,6 @@ type ComponentFileTemplate struct {
11161116
// If specified, this action overrides the global reconfigure action defined in lifecycle actions
11171117
// for this specific file template.
11181118
//
1119-
// When @restartOnFileChange is set to true, this action will be ignored.
1120-
//
11211119
// The container executing this action has access to following variables:
11221120
//
11231121
// - KB_CONFIG_FILES_CREATED: file1,file2...

apis/apps/v1/types.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,10 @@ type ClusterComponentConfig struct {
550550
// Specifies whether to restart the component to reload the updated configuration.
551551
//
552552
// +optional
553-
RestartOnConfigChange *bool `json:"restartOnConfigChange,omitempty"`
553+
Restart *bool `json:"restart,omitempty"`
554554

555555
// The custom reconfigure action to reload the updated configuration.
556556
//
557-
// When @restartOnConfigChange is set to true, this action will be ignored.
558-
//
559557
// The container executing this action has access to following variables:
560558
//
561559
// - KB_CONFIG_FILES_CREATED: file1,file2...

apis/apps/v1/zz_generated.deepcopy.go

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

config/crd/bases/apps.kubeblocks.io_clusters.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,6 @@ spec:
306306
The custom reconfigure action to reload the updated configuration.
307307

308308

309-
When @restartOnConfigChange is set to true, this action will be ignored.
310-
311-
312309
The container executing this action has access to following variables:
313310

314311

@@ -751,7 +748,7 @@ spec:
751748
format: int32
752749
type: integer
753750
type: object
754-
restartOnConfigChange:
751+
restart:
755752
description: Specifies whether to restart the component
756753
to reload the updated configuration.
757754
type: boolean
@@ -11658,9 +11655,6 @@ spec:
1165811655
The custom reconfigure action to reload the updated configuration.
1165911656

1166011657

11661-
When @restartOnConfigChange is set to true, this action will be ignored.
11662-
11663-
1166411658
The container executing this action has access to following variables:
1166511659

1166611660

@@ -12107,7 +12101,7 @@ spec:
1210712101
format: int32
1210812102
type: integer
1210912103
type: object
12110-
restartOnConfigChange:
12104+
restart:
1211112105
description: Specifies whether to restart the component
1211212106
to reload the updated configuration.
1211312107
type: boolean

config/crd/bases/apps.kubeblocks.io_componentdefinitions.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4283,9 +4283,6 @@ spec:
42834283
for this specific file template.
42844284

42854285

4286-
When @restartOnFileChange is set to true, this action will be ignored.
4287-
4288-
42894286
The container executing this action has access to following variables:
42904287

42914288

@@ -18560,9 +18557,6 @@ spec:
1856018557
for this specific file template.
1856118558

1856218559

18563-
When @restartOnFileChange is set to true, this action will be ignored.
18564-
18565-
1856618560
The container executing this action has access to following variables:
1856718561

1856818562

config/crd/bases/apps.kubeblocks.io_components.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,6 @@ spec:
181181
The custom reconfigure action to reload the updated configuration.
182182

183183

184-
When @restartOnConfigChange is set to true, this action will be ignored.
185-
186-
187184
The container executing this action has access to following variables:
188185

189186

@@ -622,7 +619,7 @@ spec:
622619
format: int32
623620
type: integer
624621
type: object
625-
restartOnConfigChange:
622+
restart:
626623
description: Specifies whether to restart the component to reload
627624
the updated configuration.
628625
type: boolean

config/crd/bases/apps.kubeblocks.io_sidecardefinitions.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ spec:
114114
for this specific file template.
115115
116116
117-
When @restartOnFileChange is set to true, this action will be ignored.
118-
119-
120117
The container executing this action has access to following variables:
121118
122119
@@ -1989,9 +1986,6 @@ spec:
19891986
for this specific file template.
19901987
19911988
1992-
When @restartOnFileChange is set to true, this action will be ignored.
1993-
1994-
19951989
The container executing this action has access to following variables:
19961990
19971991

config/crd/bases/parameters.kubeblocks.io_componentparameters.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ spec:
176176
for this specific file template.
177177
178178
179-
When @restartOnFileChange is set to true, this action will be ignored.
180-
181-
182179
The container executing this action has access to following variables:
183180
184181

controllers/apps/component/component_controller_test.go

Lines changed: 112 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,95 @@ var _ = Describe("Component Controller", func() {
15021502
Eventually(testapps.CheckObjExists(&testCtx, client.ObjectKeyFromObject(cm), &corev1.ConfigMap{}, false)).Should(Succeed())
15031503
}
15041504

1505+
testFileTemplateProvision := func(compName, compDefName, fileTemplate string) {
1506+
var (
1507+
serverConfigName = "server-conf"
1508+
serverConfigHash = "abcdefg"
1509+
serverConfigAction = testapps.NewLifecycleAction(serverConfigName)
1510+
)
1511+
1512+
By("mock the cmpd to add a new config template")
1513+
compDefKey := types.NamespacedName{Name: compDefName}
1514+
Expect(testapps.GetAndChangeObj(&testCtx, compDefKey, func(cmpd *kbappsv1.ComponentDefinition) {
1515+
cmpd.Spec.Configs = append(cmpd.Spec.Configs, kbappsv1.ComponentFileTemplate{
1516+
Name: serverConfigName,
1517+
VolumeName: "server-conf",
1518+
ExternalManaged: ptr.To(true),
1519+
})
1520+
for i := range cmpd.Spec.Runtime.Containers {
1521+
cmpd.Spec.Runtime.Containers[i].VolumeMounts =
1522+
append(cmpd.Spec.Runtime.Containers[i].VolumeMounts, corev1.VolumeMount{
1523+
Name: "server-conf",
1524+
MountPath: "/var/run/app/conf/server",
1525+
})
1526+
}
1527+
compDefObj = cmpd.DeepCopy()
1528+
})()).ShouldNot(HaveOccurred())
1529+
1530+
createCompObj(compName, compDefName, func(f *testapps.MockComponentFactory) {
1531+
f.SetConfigs([]kbappsv1.ClusterComponentConfig{
1532+
{
1533+
Name: ptr.To(serverConfigName),
1534+
ClusterComponentConfigSource: kbappsv1.ClusterComponentConfigSource{
1535+
ConfigMap: &corev1.ConfigMapVolumeSource{
1536+
LocalObjectReference: corev1.LocalObjectReference{
1537+
Name: compDefObj.Spec.Configs[0].Template, // reuse log-conf template
1538+
},
1539+
},
1540+
},
1541+
ConfigHash: ptr.To(serverConfigHash),
1542+
Restart: ptr.To(true),
1543+
Reconfigure: serverConfigAction,
1544+
},
1545+
})
1546+
})
1547+
1548+
By("check the file template objects")
1549+
var defaultInitConfigHash string
1550+
for _, tplName := range []string{fileTemplate, serverConfigName} {
1551+
cmKey := types.NamespacedName{
1552+
Namespace: testCtx.DefaultNamespace,
1553+
Name: fileTemplateObjectName(&component.SynthesizedComponent{FullCompName: compKey.Name}, tplName),
1554+
}
1555+
if tplName == fileTemplate {
1556+
Eventually(testapps.CheckObj(&testCtx, cmKey, func(g Gomega, cm *corev1.ConfigMap) {
1557+
g.Expect(cm.Data).Should(HaveKeyWithValue("level", "info"))
1558+
defaultInitConfigHash = cm.Annotations[constant.CMInsConfigurationHashLabelKey]
1559+
g.Expect(defaultInitConfigHash).NotTo(BeEmpty())
1560+
})).Should(Succeed())
1561+
} else {
1562+
// doesn't provision it
1563+
Consistently(testapps.CheckObjExists(&testCtx, cmKey, &corev1.ConfigMap{}, false)).Should(Succeed())
1564+
}
1565+
}
1566+
1567+
By("check the workload")
1568+
itsKey := compKey
1569+
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
1570+
g.Expect(its.Spec.Configs).Should(HaveLen(2))
1571+
g.Expect(its.Spec.Configs[0].Name).Should(Equal(fileTemplate))
1572+
g.Expect(its.Spec.Configs[0].ConfigHash).ShouldNot(BeNil())
1573+
g.Expect(*its.Spec.Configs[0].ConfigHash).Should(Equal(defaultInitConfigHash))
1574+
g.Expect(its.Spec.Configs[0].Restart).Should(BeNil())
1575+
g.Expect(its.Spec.Configs[0].Reconfigure).ShouldNot(BeNil())
1576+
g.Expect(*its.Spec.Configs[0].Reconfigure).Should(Equal(*compDefObj.Spec.LifecycleActions.Reconfigure))
1577+
g.Expect(its.Spec.Configs[0].ReconfigureActionName).Should(BeEmpty()) // default reconfigure action
1578+
g.Expect(its.Spec.Configs[1].Name).Should(Equal(serverConfigName))
1579+
g.Expect(its.Spec.Configs[1].ConfigHash).ShouldNot(BeNil())
1580+
g.Expect(*its.Spec.Configs[1].ConfigHash).Should(Equal(serverConfigHash))
1581+
g.Expect(its.Spec.Configs[1].Restart).ShouldNot(BeNil())
1582+
g.Expect(*its.Spec.Configs[1].Restart).Should(BeTrue())
1583+
g.Expect(its.Spec.Configs[1].Reconfigure).ShouldNot(BeNil())
1584+
g.Expect(*its.Spec.Configs[1].Reconfigure).Should(Equal(*serverConfigAction))
1585+
g.Expect(its.Spec.Configs[1].ReconfigureActionName).Should(Equal(
1586+
component.UDFReconfigureActionName(component.SynthesizedFileTemplate{
1587+
ComponentFileTemplate: kbappsv1.ComponentFileTemplate{
1588+
Name: serverConfigName,
1589+
},
1590+
})))
1591+
})).Should(Succeed())
1592+
}
1593+
15051594
testReconfigureAction := func(compName, compDefName, fileTemplate string) {
15061595
createCompObj(compName, compDefName, nil)
15071596

@@ -1540,7 +1629,7 @@ var _ = Describe("Component Controller", func() {
15401629
g.Expect(its.Spec.Configs[0].ConfigHash).ShouldNot(BeNil())
15411630
g.Expect(*its.Spec.Configs[0].ConfigHash).Should(Equal("123456"))
15421631
g.Expect(its.Spec.Configs[0].Reconfigure).ShouldNot(BeNil())
1543-
g.Expect(its.Spec.Configs[0].ReconfigureActionName).Should(BeEmpty())
1632+
g.Expect(its.Spec.Configs[0].ReconfigureActionName).Should(BeEmpty()) // default reconfigure action
15441633
g.Expect(its.Spec.Configs[0].Parameters).Should(HaveKey("KB_CONFIG_FILES_UPDATED"))
15451634
g.Expect(its.Spec.Configs[0].Parameters["KB_CONFIG_FILES_UPDATED"]).Should(ContainSubstring("level"))
15461635
})).Should(Succeed())
@@ -1554,7 +1643,7 @@ var _ = Describe("Component Controller", func() {
15541643
Variables: map[string]string{
15551644
"LOG_LEVEL": "debug",
15561645
},
1557-
Reconfigure: testapps.NewLifecycleAction("reconfigure"),
1646+
Reconfigure: testapps.NewLifecycleAction(fileTemplate),
15581647
},
15591648
})
15601649
})
@@ -1626,7 +1715,9 @@ var _ = Describe("Component Controller", func() {
16261715
By("check the workload updated")
16271716
itsKey := compKey
16281717
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
1629-
g.Expect(its.Spec.Configs).Should(BeNil())
1718+
g.Expect(its.Spec.Configs).Should(HaveLen(2))
1719+
g.Expect(its.Spec.Configs[0].Name).Should(Equal(fileTemplate))
1720+
g.Expect(its.Spec.Configs[1].Name).Should(Equal("server-conf"))
16301721
})).Should(Succeed())
16311722
}
16321723

@@ -1670,9 +1761,10 @@ var _ = Describe("Component Controller", func() {
16701761
By("check the workload updated")
16711762
itsKey := compKey
16721763
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
1673-
g.Expect(its.Spec.Configs).Should(BeNil())
1674-
g.Expect(its.Spec.Template.Annotations).ShouldNot(BeNil())
1675-
g.Expect(its.Spec.Template.Annotations).Should(HaveKey(constant.RestartAnnotationKey))
1764+
g.Expect(its.Spec.Configs).Should(HaveLen(1))
1765+
g.Expect(its.Spec.Configs[0].Name).Should(Equal(fileTemplate))
1766+
g.Expect(its.Spec.Configs[0].Restart).ShouldNot(BeNil())
1767+
g.Expect(*its.Spec.Configs[0].Restart).Should(BeTrue())
16761768
})).Should(Succeed())
16771769
}
16781770

@@ -1694,6 +1786,15 @@ var _ = Describe("Component Controller", func() {
16941786
g.Expect(initConfigHash).NotTo(BeEmpty())
16951787
})).Should(Succeed())
16961788

1789+
By("check the init workload")
1790+
itsKey := compKey
1791+
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
1792+
g.Expect(its.Spec.Configs).Should(HaveLen(1))
1793+
g.Expect(its.Spec.Configs[0].Name).Should(Equal(fileTemplate))
1794+
g.Expect(its.Spec.Configs[0].ConfigHash).ShouldNot(BeNil())
1795+
g.Expect(*its.Spec.Configs[0].ConfigHash).Should(Equal(initConfigHash))
1796+
})).Should(Succeed())
1797+
16971798
By("update the config template variables")
16981799
Expect(testapps.GetAndChangeObj(&testCtx, compKey, func(comp *kbappsv1.Component) {
16991800
comp.Spec.Configs = []kbappsv1.ClusterComponentConfig{
@@ -1715,7 +1816,6 @@ var _ = Describe("Component Controller", func() {
17151816
})).Should(Succeed())
17161817

17171818
By("check the workload updated")
1718-
itsKey := compKey
17191819
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
17201820
g.Expect(its.Spec.Configs).Should(HaveLen(1))
17211821
g.Expect(its.Spec.Configs[0].Name).Should(Equal(fileTemplate))
@@ -2282,6 +2382,10 @@ var _ = Describe("Component Controller", func() {
22822382
testFileTemplateVolumes(defaultCompName, compDefObj.Name, fileTemplate)
22832383
})
22842384

2385+
It("config template provision", func() {
2386+
testFileTemplateProvision(defaultCompName, compDefObj.Name, fileTemplate)
2387+
})
2388+
22852389
It("reconfigure - action", func() {
22862390
testReconfigureAction(defaultCompName, compDefObj.Name, fileTemplate)
22872391
})
@@ -2298,7 +2402,7 @@ var _ = Describe("Component Controller", func() {
22982402
testReconfigureRestart(defaultCompName, compDefObj.Name, fileTemplate)
22992403
})
23002404

2301-
PIt("reconfigure - config hash", func() {
2405+
It("reconfigure - config hash", func() {
23022406
testReconfigureConfigHash(defaultCompName, compDefObj.Name, fileTemplate)
23032407
})
23042408
})

0 commit comments

Comments
 (0)