@@ -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+ PIt ("reconfigure - config hash" , func () {
2302+ testReconfigureConfigHash (defaultCompName , compDefObj .Name , fileTemplate )
2303+ })
22482304 })
22492305})
0 commit comments