Skip to content

Commit 6edfe65

Browse files
authored
Add logic to warm template engine cache (#3135)
* Add logic to warm template engine cache Signed-off-by: Steven Crespo <[email protected]> * f Signed-off-by: Steven Crespo <[email protected]> * f Signed-off-by: Steven Crespo <[email protected]> --------- Signed-off-by: Steven Crespo <[email protected]>
1 parent b35ce5b commit 6edfe65

File tree

10 files changed

+96
-15
lines changed

10 files changed

+96
-15
lines changed

api/controllers/app/controller.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,17 @@ func NewAppController(opts ...AppControllerOption) (*AppController, error) {
210210
if err != nil {
211211
return nil, fmt.Errorf("patch app config values: %w", err)
212212
}
213+
// Warm the template engine cache with the existing values
214+
_, err = controller.appConfigManager.TemplateConfig(controller.configValues, false, false)
215+
if err != nil {
216+
return nil, fmt.Errorf("template config: %w", err)
217+
}
218+
} else {
219+
// Warm the template engine cache with empty values
220+
_, err := controller.appConfigManager.TemplateConfig(make(types.AppConfigValues), false, false)
221+
if err != nil {
222+
return nil, fmt.Errorf("template config: %w", err)
223+
}
213224
}
214225

215226
if controller.appPreflightManager == nil {

api/controllers/app/tests/test_suite.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,14 @@ func (s *AppControllerTestSuite) TestPatchAppConfigValues() {
149149
for _, tt := range tests {
150150
t.Run(tt.name, func(t *testing.T) {
151151

152-
appConfigManager := &appconfig.MockAppConfigManager{}
153152
appPreflightManager := &apppreflightmanager.MockAppPreflightManager{}
154153
appReleaseManager := &appreleasemanager.MockAppReleaseManager{}
155154
appInstallManager := &appinstallmanager.MockAppInstallManager{}
156155
sm := scenario.createSM(tt.currentState)
157156

157+
appConfigManager := &appconfig.MockAppConfigManager{}
158+
appConfigManager.On("TemplateConfig", types.AppConfigValues{}, false, false).Return(types.AppConfig{}, nil)
159+
158160
controller, err := appcontroller.NewAppController(
159161
appcontroller.WithStateMachine(sm),
160162
appcontroller.WithAppConfigManager(appConfigManager),
@@ -426,10 +428,13 @@ func (s *AppControllerTestSuite) TestRunAppPreflights() {
426428
for _, tt := range tests {
427429
s.T().Run(tt.name, func(t *testing.T) {
428430

429-
appConfigManager := &appconfig.MockAppConfigManager{}
430431
appPreflightManager := &apppreflightmanager.MockAppPreflightManager{}
431432
appReleaseManager := &appreleasemanager.MockAppReleaseManager{}
432433
sm := s.CreateInstallStateMachine(tt.currentState)
434+
435+
appConfigManager := &appconfig.MockAppConfigManager{}
436+
appConfigManager.On("TemplateConfig", types.AppConfigValues{}, false, false).Return(types.AppConfig{}, nil)
437+
433438
controller, err := appcontroller.NewAppController(
434439
appcontroller.WithStateMachine(sm),
435440
appcontroller.WithAppConfigManager(appConfigManager),
@@ -499,12 +504,14 @@ func (s *AppControllerTestSuite) TestGetAppInstallStatus() {
499504

500505
for _, tt := range tests {
501506
s.T().Run(tt.name, func(t *testing.T) {
502-
appConfigManager := &appconfig.MockAppConfigManager{}
503507
appPreflightManager := &apppreflightmanager.MockAppPreflightManager{}
504508
appReleaseManager := &appreleasemanager.MockAppReleaseManager{}
505509
appInstallManager := &appinstallmanager.MockAppInstallManager{}
506510
sm := s.CreateInstallStateMachine(states.StateNew)
507511

512+
appConfigManager := &appconfig.MockAppConfigManager{}
513+
appConfigManager.On("TemplateConfig", types.AppConfigValues{}, false, false).Return(types.AppConfig{}, nil)
514+
508515
controller, err := appcontroller.NewAppController(
509516
appcontroller.WithStateMachine(sm),
510517
appcontroller.WithAppConfigManager(appConfigManager),
@@ -527,6 +534,7 @@ func (s *AppControllerTestSuite) TestGetAppInstallStatus() {
527534
assert.Equal(t, expectedAppInstall, result)
528535
}
529536

537+
appConfigManager.AssertExpectations(s.T())
530538
appInstallManager.AssertExpectations(s.T())
531539
})
532540
}
@@ -681,12 +689,14 @@ func (s *AppControllerTestSuite) TestInstallApp() {
681689

682690
for _, tt := range tests {
683691
s.T().Run(tt.name, func(t *testing.T) {
684-
appConfigManager := &appconfig.MockAppConfigManager{}
685692
appPreflightManager := &apppreflightmanager.MockAppPreflightManager{}
686693
appReleaseManager := &appreleasemanager.MockAppReleaseManager{}
687694
appInstallManager := &appinstallmanager.MockAppInstallManager{}
688695
sm := s.CreateInstallStateMachine(tt.currentState)
689696

697+
appConfigManager := &appconfig.MockAppConfigManager{}
698+
appConfigManager.On("TemplateConfig", types.AppConfigValues{}, false, false).Return(types.AppConfig{}, nil)
699+
690700
controller, err := appcontroller.NewAppController(
691701
appcontroller.WithStateMachine(sm),
692702
appcontroller.WithAppConfigManager(appConfigManager),
@@ -820,13 +830,15 @@ func (s *AppControllerTestSuite) TestUpgradeApp() {
820830

821831
for _, tt := range tests {
822832
s.T().Run(tt.name, func(t *testing.T) {
823-
appConfigManager := &appconfig.MockAppConfigManager{}
824833
appPreflightManager := &apppreflightmanager.MockAppPreflightManager{}
825834
appReleaseManager := &appreleasemanager.MockAppReleaseManager{}
826835
appInstallManager := &appinstallmanager.MockAppInstallManager{}
827836
appUpgradeManager := &appupgrademanager.MockAppUpgradeManager{}
828837
sm := s.CreateUpgradeStateMachine(tt.currentState)
829838

839+
appConfigManager := &appconfig.MockAppConfigManager{}
840+
appConfigManager.On("TemplateConfig", types.AppConfigValues{}, false, false).Return(types.AppConfig{}, nil)
841+
830842
controller, err := appcontroller.NewAppController(
831843
appcontroller.WithStateMachine(sm),
832844
appcontroller.WithAppConfigManager(appConfigManager),
@@ -896,13 +908,15 @@ func (s *AppControllerTestSuite) TestGetAppUpgradeStatus() {
896908

897909
for _, tt := range tests {
898910
s.T().Run(tt.name, func(t *testing.T) {
899-
appConfigManager := &appconfig.MockAppConfigManager{}
900911
appPreflightManager := &apppreflightmanager.MockAppPreflightManager{}
901912
appReleaseManager := &appreleasemanager.MockAppReleaseManager{}
902913
appInstallManager := &appinstallmanager.MockAppInstallManager{}
903914
appUpgradeManager := &appupgrademanager.MockAppUpgradeManager{}
904915
sm := s.CreateUpgradeStateMachine(states.StateNew)
905916

917+
appConfigManager := &appconfig.MockAppConfigManager{}
918+
appConfigManager.On("TemplateConfig", types.AppConfigValues{}, false, false).Return(types.AppConfig{}, nil)
919+
906920
controller, err := appcontroller.NewAppController(
907921
appcontroller.WithStateMachine(sm),
908922
appcontroller.WithAppConfigManager(appConfigManager),

api/controllers/kubernetes/install/controller_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ func TestConfigureInstallation(t *testing.T) {
219219

220220
mockManager := &installation.MockInstallationManager{}
221221
mockMetricsReporter := &metrics.MockReporter{}
222+
222223
mockStore := &store.MockStore{}
224+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
223225

224226
tt.setupMock(mockManager, mockInstallation, tt.config, mockStore, mockMetricsReporter)
225227

@@ -421,7 +423,10 @@ func TestSetupInfra(t *testing.T) {
421423
mockInfraManager := &infra.MockInfraManager{}
422424
mockMetricsReporter := &metrics.MockReporter{}
423425
mockStore := &store.MockStore{}
426+
424427
mockAppConfigManager := &appconfig.MockAppConfigManager{}
428+
mockAppConfigManager.On("TemplateConfig", types.AppConfigValues{}, false, false).Return(types.AppConfig{}, nil)
429+
425430
tt.setupMocks(ki, mockInstallationManager, mockInfraManager, mockMetricsReporter, mockStore, mockAppConfigManager)
426431

427432
appController, err := appcontroller.NewAppController(

api/controllers/linux/install/controller_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ func TestConfigureInstallation(t *testing.T) {
399399

400400
mockManager := &installation.MockInstallationManager{}
401401
mockMetricsReporter := &metrics.MockReporter{}
402+
402403
mockStore := &store.MockStore{}
404+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
403405

404406
tt.setupMock(mockManager, rc, tt.config, mockStore, mockMetricsReporter)
405407

@@ -732,6 +734,9 @@ func TestRunHostPreflights(t *testing.T) {
732734

733735
tt.setupMocks(mockPreflightManager, rc, mockMetricsReporter, mockStore)
734736

737+
// Mock GetConfigValues call that happens during controller initialization
738+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
739+
735740
controller, err := NewInstallController(
736741
WithRuntimeConfig(rc),
737742
WithStateMachine(sm),
@@ -1152,10 +1157,12 @@ func TestSetupInfra(t *testing.T) {
11521157
mockInfraManager := &infra.MockInfraManager{}
11531158
mockMetricsReporter := &metrics.MockReporter{}
11541159
mockStore := &store.MockStore{}
1155-
mockAppConfigManager := &appconfig.MockAppConfigManager{}
11561160
mockAppPreflightManager := &apppreflightmanager.MockAppPreflightManager{}
11571161
mockAppReleaseManager := &appreleasemanager.MockAppReleaseManager{}
11581162

1163+
mockAppConfigManager := &appconfig.MockAppConfigManager{}
1164+
mockAppConfigManager.On("TemplateConfig", types.AppConfigValues{}, false, false).Return(types.AppConfig{}, nil)
1165+
11591166
tt.setupMocks(rc, mockPreflightManager, mockInstallationManager, mockInfraManager, mockAppConfigManager, mockMetricsReporter, mockStore)
11601167

11611168
appController, err := appcontroller.NewAppController(
@@ -1397,6 +1404,9 @@ func TestProcessAirgap(t *testing.T) {
13971404

13981405
tt.setupMocks(mockAirgapManager, mockInstallationManager, expectedRegistrySettings, rc)
13991406

1407+
// Mock GetConfigValues call that happens during controller initialization
1408+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
1409+
14001410
controller, err := NewInstallController(
14011411
WithRuntimeConfig(rc),
14021412
WithStateMachine(sm),

api/controllers/linux/upgrade/controller_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ func TestUpgradeInfra(t *testing.T) {
8181
rc.SetManagerPort(9001)
8282

8383
mockInfraManager := &infra.MockInfraManager{}
84-
mockStore := &store.MockStore{}
8584
mockInstallationManager := &installation.MockInstallationManager{}
8685

86+
mockStore := &store.MockStore{}
87+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
88+
8789
tt.setupMocks(rc, mockInfraManager, mockInstallationManager)
8890

8991
sm := NewStateMachine(
@@ -187,7 +189,9 @@ func TestGetInfra(t *testing.T) {
187189
for _, tt := range tests {
188190
t.Run(tt.name, func(t *testing.T) {
189191
mockInfraManager := &infra.MockInfraManager{}
192+
190193
mockStore := &store.MockStore{}
194+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
191195

192196
tt.setupMock(mockInfraManager)
193197

@@ -321,9 +325,11 @@ func TestReportingHandlers(t *testing.T) {
321325
for _, tt := range tests {
322326
t.Run(tt.name, func(t *testing.T) {
323327
mockMetricsReporter := &metrics.MockReporter{}
324-
mockStore := &store.MockStore{}
325328
mockInfraManager := &infra.MockInfraManager{}
326329

330+
mockStore := &store.MockStore{}
331+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
332+
327333
tt.setupMocks(mockMetricsReporter, mockStore)
328334

329335
// Mock RequiresUpgrade which is called during controller initialization
@@ -452,6 +458,8 @@ func TestProcessAirgap(t *testing.T) {
452458

453459
tt.setupMocks(mockAirgapManager, mockInstallationManager, expectedRegistrySettings, rc)
454460

461+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
462+
455463
controller, err := NewUpgradeController(
456464
WithRuntimeConfig(rc),
457465
WithStateMachine(sm),

api/integration/app/upgrade/apppreflight_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,14 @@ func (s *AppPreflightTestSuite) TestPostRunAppPreflights() {
342342
// Create state machine with wrong state
343343
stateMachine := s.createStateMachine(states.StateNew)
344344

345+
// Create mock store with GetConfigValues expectation
346+
mockStore := &store.MockStore{}
347+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
348+
345349
// Create simple app controller
346350
appController, err := appcontroller.NewAppController(
347351
appcontroller.WithStateMachine(stateMachine),
348-
appcontroller.WithStore(&store.MockStore{}),
352+
appcontroller.WithStore(mockStore),
349353
appcontroller.WithReleaseData(integration.DefaultReleaseData()),
350354
appcontroller.WithHelmClient(&helm.MockClient{}),
351355
)
@@ -380,10 +384,14 @@ func (s *AppPreflightTestSuite) TestPostRunAppPreflights() {
380384
// Create state machine
381385
stateMachine := s.createStateMachine(states.StateApplicationConfigured)
382386

387+
// Create mock store with GetConfigValues expectation
388+
mockStore := &store.MockStore{}
389+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
390+
383391
// Create simple app controller
384392
appController, err := appcontroller.NewAppController(
385393
appcontroller.WithStateMachine(stateMachine),
386-
appcontroller.WithStore(&store.MockStore{}),
394+
appcontroller.WithStore(mockStore),
387395
appcontroller.WithReleaseData(integration.DefaultReleaseData()),
388396
appcontroller.WithHelmClient(&helm.MockClient{}),
389397
)

api/integration/app/upgrade/upgrade_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func (s *AppUpgradeTestSuite) TestPostUpgradeApp() {
6161

6262
// Create mock store that will be shared between AppController and UpgradeController
6363
mockStore := &store.MockStore{}
64+
mockAppConfigManager.On("TemplateConfig", types.AppConfigValues{}, false, false).Return(types.AppConfig{}, nil)
6465

6566
// Create state machine that will be shared between AppController and UpgradeController
6667
stateMachine := s.createStateMachine(states.StateAppPreflightsSucceeded)
@@ -124,10 +125,14 @@ func (s *AppUpgradeTestSuite) TestPostUpgradeApp() {
124125
// Create state machine
125126
stateMachine := s.createStateMachine(states.StateAppPreflightsSucceeded)
126127

128+
// Create mock store
129+
mockStore := &store.MockStore{}
130+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
131+
127132
// Create simple app controller for auth test
128133
appController, err := appcontroller.NewAppController(
129134
appcontroller.WithStateMachine(stateMachine),
130-
appcontroller.WithStore(&store.MockStore{}),
135+
appcontroller.WithStore(mockStore),
131136
appcontroller.WithReleaseData(integration.DefaultReleaseData()),
132137
appcontroller.WithHelmClient(&helm.MockClient{}),
133138
)
@@ -171,6 +176,7 @@ func (s *AppUpgradeTestSuite) TestPostUpgradeApp() {
171176
// Create mock app config manager
172177
mockAppConfigManager := &appconfig.MockAppConfigManager{}
173178
mockAppConfigManager.On("GetKotsadmConfigValues").Return(kotsv1beta1.ConfigValues{}, nil)
179+
mockAppConfigManager.On("TemplateConfig", types.AppConfigValues{}, false, false).Return(types.AppConfig{}, nil)
174180

175181
// Create mock app upgrade manager that fails
176182
mockAppUpgradeManager := &appupgrademanager.MockAppUpgradeManager{}
@@ -265,11 +271,15 @@ func (s *AppUpgradeTestSuite) TestGetAppUpgradeStatus() {
265271

266272
stateMachine := s.createStateMachine(states.StateAppPreflightsSucceeded)
267273

274+
// Create mock store
275+
mockStore := &store.MockStore{}
276+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
277+
268278
// Create app controller with real upgrade manager
269279
appController, err := appcontroller.NewAppController(
270280
appcontroller.WithAppUpgradeManager(appUpgradeManager),
271281
appcontroller.WithStateMachine(stateMachine),
272-
appcontroller.WithStore(&store.MockStore{}),
282+
appcontroller.WithStore(mockStore),
273283
appcontroller.WithReleaseData(integration.DefaultReleaseData()),
274284
appcontroller.WithHelmClient(&helm.MockClient{}),
275285
)
@@ -309,9 +319,14 @@ func (s *AppUpgradeTestSuite) TestGetAppUpgradeStatus() {
309319
stateMachine := s.createStateMachine(states.StateAppPreflightsSucceeded)
310320

311321
// Create simple app controller for auth test
322+
323+
// Create mock store
324+
mockStore := &store.MockStore{}
325+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
326+
312327
appController, err := appcontroller.NewAppController(
313328
appcontroller.WithStateMachine(stateMachine),
314-
appcontroller.WithStore(&store.MockStore{}),
329+
appcontroller.WithStore(mockStore),
315330
appcontroller.WithReleaseData(integration.DefaultReleaseData()),
316331
appcontroller.WithHelmClient(&helm.MockClient{}),
317332
)

api/integration/kubernetes/install/appinstall_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func TestGetAppInstallStatus(t *testing.T) {
5353

5454
// Create mock store
5555
mockStore := &store.MockStore{}
56+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
5657

5758
// Create real app install controller
5859
appController, err := appcontroller.NewAppController(
@@ -269,6 +270,8 @@ func TestPostInstallApp(t *testing.T) {
269270

270271
// Create simple app install controller
271272
mockStore := &store.MockStore{}
273+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
274+
272275
appController, err := appcontroller.NewAppController(
273276
appcontroller.WithStateMachine(stateMachine),
274277
appcontroller.WithStore(mockStore),
@@ -506,6 +509,7 @@ func TestPostInstallApp(t *testing.T) {
506509
t.Run("App preflight bypass denied with failed preflights", func(t *testing.T) {
507510
// Create mock store
508511
mockStore := &store.MockStore{}
512+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
509513

510514
// Create mock app preflight manager that returns non-strict failures (method should be called but bypass denied)
511515
mockAppPreflightManager := &apppreflightmanager.MockAppPreflightManager{}
@@ -586,6 +590,7 @@ func TestPostInstallApp(t *testing.T) {
586590
t.Run("Strict app preflight bypass blocked", func(t *testing.T) {
587591
// Create mock store
588592
mockStore := &store.MockStore{}
593+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
589594

590595
// Create mock app preflight manager that returns strict failures (cannot be bypassed)
591596
mockAppPreflightManager := &apppreflightmanager.MockAppPreflightManager{}

api/integration/linux/install/appinstall_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestGetAppInstallStatus(t *testing.T) {
5555

5656
// Create mock store
5757
mockStore := &store.MockStore{}
58+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
5859

5960
// Create real app install controller
6061
appController, err := appcontroller.NewAppController(
@@ -286,6 +287,8 @@ func TestPostInstallApp(t *testing.T) {
286287

287288
// Create simple app install controller
288289
mockStore := &store.MockStore{}
290+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
291+
289292
appController, err := appcontroller.NewAppController(
290293
appcontroller.WithStateMachine(stateMachine),
291294
appcontroller.WithStore(mockStore),
@@ -546,6 +549,7 @@ func TestPostInstallApp(t *testing.T) {
546549
t.Run("App preflight bypass denied with failed preflights", func(t *testing.T) {
547550
// Create mock store
548551
mockStore := &store.MockStore{}
552+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
549553

550554
// Create mock app preflight manager that returns non-strict failures (method should be called but bypass denied)
551555
mockAppPreflightManager := &apppreflightmanager.MockAppPreflightManager{}
@@ -626,6 +630,7 @@ func TestPostInstallApp(t *testing.T) {
626630
t.Run("Strict app preflight bypass blocked", func(t *testing.T) {
627631
// Create mock store
628632
mockStore := &store.MockStore{}
633+
mockStore.AppConfigMockStore.On("GetConfigValues").Return(types.AppConfigValues{}, nil)
629634

630635
// Create mock app preflight manager that returns strict failures (cannot be bypassed)
631636
mockAppPreflightManager := &apppreflightmanager.MockAppPreflightManager{}

0 commit comments

Comments
 (0)