@@ -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