@@ -13,6 +13,7 @@ import (
1313 states "github.com/replicatedhq/embedded-cluster/api/internal/states/install"
1414 "github.com/replicatedhq/embedded-cluster/api/internal/store"
1515 "github.com/replicatedhq/embedded-cluster/api/types"
16+ ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
1617 "github.com/replicatedhq/embedded-cluster/pkg/release"
1718 kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
1819 troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
@@ -503,16 +504,18 @@ func (s *AppInstallControllerTestSuite) TestInstallApp() {
503504 tests := []struct {
504505 name string
505506 ignoreAppPreflights bool
507+ proxySpec * ecv1beta1.ProxySpec
508+ registrySettings * types.RegistrySettings
506509 currentState statemachine.State
507510 expectedState statemachine.State
508- setupMocks func (* appconfig.MockAppConfigManager , * appinstallmanager.MockAppInstallManager )
511+ setupMocks func (* appconfig.MockAppConfigManager , * appreleasemanager. MockAppReleaseManager , * appinstallmanager.MockAppInstallManager )
509512 expectedErr bool
510513 }{
511514 {
512515 name : "invalid state transition from succeeded state" ,
513516 currentState : states .StateSucceeded ,
514517 expectedState : states .StateSucceeded ,
515- setupMocks : func (acm * appconfig.MockAppConfigManager , aim * appinstallmanager.MockAppInstallManager ) {
518+ setupMocks : func (acm * appconfig.MockAppConfigManager , arm * appreleasemanager. MockAppReleaseManager , aim * appinstallmanager.MockAppInstallManager ) {
516519 // No mocks needed for invalid state transition
517520 },
518521 expectedErr : true ,
@@ -521,27 +524,37 @@ func (s *AppInstallControllerTestSuite) TestInstallApp() {
521524 name : "invalid state transition from infrastructure installing state" ,
522525 currentState : states .StateInfrastructureInstalling ,
523526 expectedState : states .StateInfrastructureInstalling ,
524- setupMocks : func (acm * appconfig.MockAppConfigManager , aim * appinstallmanager.MockAppInstallManager ) {
527+ setupMocks : func (acm * appconfig.MockAppConfigManager , arm * appreleasemanager. MockAppReleaseManager , aim * appinstallmanager.MockAppInstallManager ) {
525528 // No mocks needed for invalid state transition
526529 },
527530 expectedErr : true ,
528531 },
529532 {
530- name : "successful app installation from app preflights succeeded state" ,
533+ name : "successful app installation from app preflights succeeded state with helm charts " ,
531534 currentState : states .StateAppPreflightsSucceeded ,
532535 expectedState : states .StateSucceeded ,
533- setupMocks : func (acm * appconfig.MockAppConfigManager , aim * appinstallmanager.MockAppInstallManager ) {
534- mock .InOrder (
535- acm .On ("GetKotsadmConfigValues" ).Return (kotsv1beta1.ConfigValues {
536- Spec : kotsv1beta1.ConfigValuesSpec {
537- Values : map [string ]kotsv1beta1.ConfigValue {
538- "test-key" : {Value : "test-value" },
539- },
536+ setupMocks : func (acm * appconfig.MockAppConfigManager , arm * appreleasemanager.MockAppReleaseManager , aim * appinstallmanager.MockAppInstallManager ) {
537+ configValues := kotsv1beta1.ConfigValues {
538+ Spec : kotsv1beta1.ConfigValuesSpec {
539+ Values : map [string ]kotsv1beta1.ConfigValue {
540+ "test-key" : {Value : "test-value" },
540541 },
541- }, nil ),
542- aim .On ("Install" , mock .Anything , mock .MatchedBy (func (cv kotsv1beta1.ConfigValues ) bool {
543- return cv .Spec .Values ["test-key" ].Value == "test-value"
544- })).Return (nil ),
542+ },
543+ }
544+ expectedCharts := []types.InstallableHelmChart {
545+ {
546+ Archive : []byte ("chart-archive-data" ),
547+ Values : map [string ]any {"key" : "value" },
548+ },
549+ }
550+ appConfigValues := types.AppConfigValues {
551+ "test-key" : types.AppConfigValue {Value : "test-value" },
552+ }
553+ mock .InOrder (
554+ acm .On ("GetConfigValues" ).Return (appConfigValues , nil ),
555+ acm .On ("GetKotsadmConfigValues" ).Return (configValues , nil ),
556+ arm .On ("ExtractInstallableHelmCharts" , mock .Anything , appConfigValues , mock .AnythingOfType ("*v1beta1.ProxySpec" ), mock .AnythingOfType ("*types.RegistrySettings" )).Return (expectedCharts , nil ),
557+ aim .On ("Install" , mock .Anything , expectedCharts , configValues ).Return (nil ),
545558 )
546559 },
547560 expectedErr : false ,
@@ -550,18 +563,22 @@ func (s *AppInstallControllerTestSuite) TestInstallApp() {
550563 name : "successful app installation from app preflights failed bypassed state" ,
551564 currentState : states .StateAppPreflightsFailedBypassed ,
552565 expectedState : states .StateSucceeded ,
553- setupMocks : func (acm * appconfig.MockAppConfigManager , aim * appinstallmanager.MockAppInstallManager ) {
554- mock .InOrder (
555- acm .On ("GetKotsadmConfigValues" ).Return (kotsv1beta1.ConfigValues {
556- Spec : kotsv1beta1.ConfigValuesSpec {
557- Values : map [string ]kotsv1beta1.ConfigValue {
558- "test-key" : {Value : "test-value" },
559- },
566+ setupMocks : func (acm * appconfig.MockAppConfigManager , arm * appreleasemanager.MockAppReleaseManager , aim * appinstallmanager.MockAppInstallManager ) {
567+ configValues := kotsv1beta1.ConfigValues {
568+ Spec : kotsv1beta1.ConfigValuesSpec {
569+ Values : map [string ]kotsv1beta1.ConfigValue {
570+ "test-key" : {Value : "test-value" },
560571 },
561- }, nil ),
562- aim .On ("Install" , mock .Anything , mock .MatchedBy (func (cv kotsv1beta1.ConfigValues ) bool {
563- return cv .Spec .Values ["test-key" ].Value == "test-value"
564- })).Return (nil ),
572+ },
573+ }
574+ appConfigValues := types.AppConfigValues {
575+ "test-key" : types.AppConfigValue {Value : "test-value" },
576+ }
577+ mock .InOrder (
578+ acm .On ("GetConfigValues" ).Return (appConfigValues , nil ),
579+ acm .On ("GetKotsadmConfigValues" ).Return (configValues , nil ),
580+ arm .On ("ExtractInstallableHelmCharts" , mock .Anything , appConfigValues , mock .AnythingOfType ("*v1beta1.ProxySpec" ), mock .AnythingOfType ("*types.RegistrySettings" )).Return ([]types.InstallableHelmChart {}, nil ),
581+ aim .On ("Install" , mock .Anything , []types.InstallableHelmChart {}, configValues ).Return (nil ),
565582 )
566583 },
567584 expectedErr : false ,
@@ -570,7 +587,11 @@ func (s *AppInstallControllerTestSuite) TestInstallApp() {
570587 name : "get config values error" ,
571588 currentState : states .StateAppPreflightsSucceeded ,
572589 expectedState : states .StateAppPreflightsSucceeded ,
573- setupMocks : func (acm * appconfig.MockAppConfigManager , aim * appinstallmanager.MockAppInstallManager ) {
590+ setupMocks : func (acm * appconfig.MockAppConfigManager , arm * appreleasemanager.MockAppReleaseManager , aim * appinstallmanager.MockAppInstallManager ) {
591+ appConfigValues := types.AppConfigValues {
592+ "test-key" : types.AppConfigValue {Value : "test-value" },
593+ }
594+ acm .On ("GetConfigValues" ).Return (appConfigValues , nil )
574595 acm .On ("GetKotsadmConfigValues" ).Return (kotsv1beta1.ConfigValues {}, errors .New ("config values error" ))
575596 },
576597 expectedErr : true ,
@@ -580,18 +601,22 @@ func (s *AppInstallControllerTestSuite) TestInstallApp() {
580601 ignoreAppPreflights : true ,
581602 currentState : states .StateAppPreflightsFailed ,
582603 expectedState : states .StateSucceeded ,
583- setupMocks : func (acm * appconfig.MockAppConfigManager , aim * appinstallmanager.MockAppInstallManager ) {
584- mock .InOrder (
585- acm .On ("GetKotsadmConfigValues" ).Return (kotsv1beta1.ConfigValues {
586- Spec : kotsv1beta1.ConfigValuesSpec {
587- Values : map [string ]kotsv1beta1.ConfigValue {
588- "test-key" : {Value : "test-value" },
589- },
604+ setupMocks : func (acm * appconfig.MockAppConfigManager , arm * appreleasemanager.MockAppReleaseManager , aim * appinstallmanager.MockAppInstallManager ) {
605+ configValues := kotsv1beta1.ConfigValues {
606+ Spec : kotsv1beta1.ConfigValuesSpec {
607+ Values : map [string ]kotsv1beta1.ConfigValue {
608+ "test-key" : {Value : "test-value" },
590609 },
591- }, nil ),
592- aim .On ("Install" , mock .Anything , mock .MatchedBy (func (cv kotsv1beta1.ConfigValues ) bool {
593- return cv .Spec .Values ["test-key" ].Value == "test-value"
594- })).Return (nil ),
610+ },
611+ }
612+ appConfigValues := types.AppConfigValues {
613+ "test-key" : types.AppConfigValue {Value : "test-value" },
614+ }
615+ mock .InOrder (
616+ acm .On ("GetConfigValues" ).Return (appConfigValues , nil ),
617+ acm .On ("GetKotsadmConfigValues" ).Return (configValues , nil ),
618+ arm .On ("ExtractInstallableHelmCharts" , mock .Anything , appConfigValues , mock .AnythingOfType ("*v1beta1.ProxySpec" ), mock .AnythingOfType ("*types.RegistrySettings" )).Return ([]types.InstallableHelmChart {}, nil ),
619+ aim .On ("Install" , mock .Anything , []types.InstallableHelmChart {}, configValues ).Return (nil ),
595620 )
596621 },
597622 expectedErr : false ,
@@ -601,11 +626,54 @@ func (s *AppInstallControllerTestSuite) TestInstallApp() {
601626 ignoreAppPreflights : false ,
602627 currentState : states .StateAppPreflightsFailed ,
603628 expectedState : states .StateAppPreflightsFailed ,
604- setupMocks : func (acm * appconfig.MockAppConfigManager , aim * appinstallmanager.MockAppInstallManager ) {
629+ setupMocks : func (acm * appconfig.MockAppConfigManager , arm * appreleasemanager. MockAppReleaseManager , aim * appinstallmanager.MockAppInstallManager ) {
605630 // No mocks needed as method should return early with error
606631 },
607632 expectedErr : true ,
608633 },
634+ {
635+ name : "successful app installation with proxy spec passed to helm chart extraction" ,
636+ currentState : states .StateAppPreflightsSucceeded ,
637+ expectedState : states .StateSucceeded ,
638+ proxySpec : & ecv1beta1.ProxySpec {
639+ HTTPProxy : "http://proxy.example.com:8080" ,
640+ HTTPSProxy : "https://proxy.example.com:8080" ,
641+ NoProxy : "localhost,127.0.0.1" ,
642+ },
643+ registrySettings : & types.RegistrySettings {
644+ HasLocalRegistry : true ,
645+ Host : "10.128.0.11:5000" ,
646+ },
647+ setupMocks : func (acm * appconfig.MockAppConfigManager , arm * appreleasemanager.MockAppReleaseManager , aim * appinstallmanager.MockAppInstallManager ) {
648+ configValues := kotsv1beta1.ConfigValues {
649+ Spec : kotsv1beta1.ConfigValuesSpec {
650+ Values : map [string ]kotsv1beta1.ConfigValue {
651+ "test-key" : {Value : "test-value" },
652+ },
653+ },
654+ }
655+ appConfigValues := types.AppConfigValues {
656+ "test-key" : types.AppConfigValue {Value : "test-value" },
657+ }
658+ expectedCharts := []types.InstallableHelmChart {
659+ {
660+ Archive : []byte ("chart-with-proxy-template" ),
661+ Values : map [string ]any {"proxy_url" : "http://proxy.example.com:8080" },
662+ },
663+ }
664+ mock .InOrder (
665+ acm .On ("GetConfigValues" ).Return (appConfigValues , nil ),
666+ acm .On ("GetKotsadmConfigValues" ).Return (configValues , nil ),
667+ arm .On ("ExtractInstallableHelmCharts" , mock .Anything , appConfigValues , mock .MatchedBy (func (proxySpec * ecv1beta1.ProxySpec ) bool {
668+ return proxySpec != nil
669+ }), mock .MatchedBy (func (registrySettings * types.RegistrySettings ) bool {
670+ return registrySettings != nil
671+ })).Return (expectedCharts , nil ),
672+ aim .On ("Install" , mock .Anything , expectedCharts , configValues ).Return (nil ),
673+ )
674+ },
675+ expectedErr : false ,
676+ },
609677 }
610678
611679 for _ , tt := range tests {
@@ -627,8 +695,12 @@ func (s *AppInstallControllerTestSuite) TestInstallApp() {
627695 )
628696 require .NoError (t , err , "failed to create install controller" )
629697
630- tt .setupMocks (appConfigManager , appInstallManager )
631- err = controller .InstallApp (t .Context (), tt .ignoreAppPreflights )
698+ tt .setupMocks (appConfigManager , appReleaseManager , appInstallManager )
699+ err = controller .InstallApp (t .Context (), InstallAppOptions {
700+ IgnoreAppPreflights : tt .ignoreAppPreflights ,
701+ ProxySpec : tt .proxySpec ,
702+ RegistrySettings : tt .registrySettings ,
703+ })
632704
633705 if tt .expectedErr {
634706 assert .Error (t , err )
@@ -643,6 +715,7 @@ func (s *AppInstallControllerTestSuite) TestInstallApp() {
643715 assert .False (t , sm .IsLockAcquired (), "state machine should not be locked after app installation" )
644716
645717 appConfigManager .AssertExpectations (s .T ())
718+ appReleaseManager .AssertExpectations (s .T ())
646719 appInstallManager .AssertExpectations (s .T ())
647720 })
648721 }
0 commit comments