diff --git a/pkg/executables/clusterctl.go b/pkg/executables/clusterctl.go index de6808d5c7d3..33fff8bd9d78 100644 --- a/pkg/executables/clusterctl.go +++ b/pkg/executables/clusterctl.go @@ -234,7 +234,7 @@ func (c *Clusterctl) InitInfrastructure(ctx context.Context, managementComponent params = append(params, "--kubeconfig", cluster.KubeconfigFile) } - envMap, err := provider.EnvMap(clusterSpec) + envMap, err := provider.EnvMap(managementComponents, clusterSpec) if err != nil { return err } @@ -373,7 +373,7 @@ func (c *Clusterctl) Upgrade(ctx context.Context, managementCluster *types.Clust upgradeCommand = append(upgradeCommand, "--bootstrap", newBootstrapProvider) } - providerEnvMap, err := provider.EnvMap(newSpec) + providerEnvMap, err := provider.EnvMap(managementComponents, newSpec) if err != nil { return fmt.Errorf("failed generating provider env map for clusterctl upgrade: %v", err) } @@ -419,7 +419,7 @@ func (c *Clusterctl) InstallEtcdadmProviders(ctx context.Context, managementComp params = append(params, "--kubeconfig", cluster.KubeconfigFile) } - envMap, err := infraProvider.EnvMap(clusterSpec) + envMap, err := infraProvider.EnvMap(managementComponents, clusterSpec) if err != nil { return err } diff --git a/pkg/executables/clusterctl_test.go b/pkg/executables/clusterctl_test.go index 7f2fc252f8d0..ced3e4706e46 100644 --- a/pkg/executables/clusterctl_test.go +++ b/pkg/executables/clusterctl_test.go @@ -66,7 +66,7 @@ func (ct *clusterctlTest) expectBuildOverrideLayer() { } func (ct *clusterctlTest) expectGetProviderEnvMap() { - ct.provider.EXPECT().EnvMap(clusterSpec).Return(ct.providerEnvMap, nil) + ct.provider.EXPECT().EnvMap(ct.managementComponents, clusterSpec).Return(ct.providerEnvMap, nil) } func TestClusterctlInitInfrastructure(t *testing.T) { @@ -134,7 +134,7 @@ func TestClusterctlInitInfrastructure(t *testing.T) { tc.provider.EXPECT().Name().Return(tt.providerName) tc.provider.EXPECT().Version(tc.managementComponents).Return(tt.providerVersion) - tc.provider.EXPECT().EnvMap(clusterSpec).Return(tt.env, nil) + tc.provider.EXPECT().EnvMap(tc.managementComponents, clusterSpec).Return(tt.env, nil) tc.provider.EXPECT().GetInfrastructureBundle(tc.managementComponents).Return(&types.InfrastructureBundle{}) tc.e.EXPECT().ExecuteWithEnv(tc.ctx, tt.env, tt.wantExecArgs...).Return(bytes.Buffer{}, nil).Times(1).Do( @@ -182,7 +182,7 @@ func TestClusterctlInitInfrastructureEnvMapError(t *testing.T) { tt.provider.EXPECT().Name() tt.provider.EXPECT().Version(tt.managementComponents) - tt.provider.EXPECT().EnvMap(clusterSpec).Return(nil, errors.New("error with env map")) + tt.provider.EXPECT().EnvMap(tt.managementComponents, clusterSpec).Return(nil, errors.New("error with env map")) tt.provider.EXPECT().GetInfrastructureBundle(tt.managementComponents).Return(&types.InfrastructureBundle{}) if err := tt.clusterctl.InitInfrastructure(tt.ctx, tt.managementComponents, clusterSpec, cluster, tt.provider); err == nil { @@ -201,7 +201,7 @@ func TestClusterctlInitInfrastructureExecutableError(t *testing.T) { tt.provider.EXPECT().Name() tt.provider.EXPECT().Version(tt.managementComponents) - tt.provider.EXPECT().EnvMap(clusterSpec) + tt.provider.EXPECT().EnvMap(tt.managementComponents, clusterSpec) tt.provider.EXPECT().GetInfrastructureBundle(tt.managementComponents).Return(&types.InfrastructureBundle{}) tt.e.EXPECT().ExecuteWithEnv(tt.ctx, nil, gomock.Any()).Return(bytes.Buffer{}, errors.New("error from execute with env")) diff --git a/pkg/providers/cloudstack/cloudstack.go b/pkg/providers/cloudstack/cloudstack.go index ee93f3a35e0b..d90d9a21997a 100644 --- a/pkg/providers/cloudstack/cloudstack.go +++ b/pkg/providers/cloudstack/cloudstack.go @@ -815,7 +815,8 @@ func (p *cloudstackProvider) Version(componnets *cluster.ManagementComponents) s return componnets.CloudStack.Version } -func (p *cloudstackProvider) EnvMap(_ *cluster.Spec) (map[string]string, error) { +// EnvMap returns a map of environment variables required for the cloudstack provider. +func (p *cloudstackProvider) EnvMap(_ *cluster.ManagementComponents, _ *cluster.Spec) (map[string]string, error) { envMap := make(map[string]string) for _, key := range requiredEnvs { if env, ok := os.LookupEnv(key); ok && len(env) > 0 { diff --git a/pkg/providers/docker/docker.go b/pkg/providers/docker/docker.go index 4ff305622b0e..2999a5e5304a 100644 --- a/pkg/providers/docker/docker.go +++ b/pkg/providers/docker/docker.go @@ -632,7 +632,7 @@ func (p *Provider) Version(components *cluster.ManagementComponents) string { } // EnvMap returns a map of environment variables to be set when running the docker clusterctl command. -func (p *Provider) EnvMap(_ *cluster.Spec) (map[string]string, error) { +func (p *Provider) EnvMap(_ *cluster.ManagementComponents, _ *cluster.Spec) (map[string]string, error) { envMap := make(map[string]string) if env, ok := os.LookupEnv(githubTokenEnvVar); ok && len(env) > 0 { envMap[githubTokenEnvVar] = env diff --git a/pkg/providers/mocks/providers.go b/pkg/providers/mocks/providers.go index 8d7cef43df81..19d6425b2651 100644 --- a/pkg/providers/mocks/providers.go +++ b/pkg/providers/mocks/providers.go @@ -111,18 +111,18 @@ func (mr *MockProviderMockRecorder) DeleteResources(arg0, arg1 interface{}) *gom } // EnvMap mocks base method. -func (m *MockProvider) EnvMap(arg0 *cluster.Spec) (map[string]string, error) { +func (m *MockProvider) EnvMap(arg0 *cluster.ManagementComponents, arg1 *cluster.Spec) (map[string]string, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EnvMap", arg0) + ret := m.ctrl.Call(m, "EnvMap", arg0, arg1) ret0, _ := ret[0].(map[string]string) ret1, _ := ret[1].(error) return ret0, ret1 } // EnvMap indicates an expected call of EnvMap. -func (mr *MockProviderMockRecorder) EnvMap(arg0 interface{}) *gomock.Call { +func (mr *MockProviderMockRecorder) EnvMap(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnvMap", reflect.TypeOf((*MockProvider)(nil).EnvMap), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnvMap", reflect.TypeOf((*MockProvider)(nil).EnvMap), arg0, arg1) } // GenerateCAPISpecForCreate mocks base method. diff --git a/pkg/providers/nutanix/provider.go b/pkg/providers/nutanix/provider.go index 28775d127cbb..82ab5461796e 100644 --- a/pkg/providers/nutanix/provider.go +++ b/pkg/providers/nutanix/provider.go @@ -531,7 +531,8 @@ func (p *Provider) Version(components *cluster.ManagementComponents) string { return components.Nutanix.Version } -func (p *Provider) EnvMap(_ *cluster.Spec) (map[string]string, error) { +// EnvMap returns the environment variables for the provider. +func (p *Provider) EnvMap(_ *cluster.ManagementComponents, _ *cluster.Spec) (map[string]string, error) { // TODO(nutanix): determine if any env vars are needed and add them to requiredEnvs envMap := make(map[string]string) for _, key := range requiredEnvs { diff --git a/pkg/providers/nutanix/provider_test.go b/pkg/providers/nutanix/provider_test.go index 28cb00e5a461..81734bfba087 100644 --- a/pkg/providers/nutanix/provider_test.go +++ b/pkg/providers/nutanix/provider_test.go @@ -902,10 +902,11 @@ func TestNutanixProviderVersion(t *testing.T) { func TestNutanixProviderEnvMap(t *testing.T) { provider := testDefaultNutanixProvider(t) clusterSpec := test.NewFullClusterSpec(t, "testdata/eksa-cluster.yaml") + managementComponents := givenManagementComponents() t.Run("required envs not set", func(t *testing.T) { os.Clearenv() - envMap, err := provider.EnvMap(clusterSpec) + envMap, err := provider.EnvMap(managementComponents, clusterSpec) assert.Error(t, err) assert.Nil(t, envMap) }) @@ -916,7 +917,7 @@ func TestNutanixProviderEnvMap(t *testing.T) { t.Setenv(nutanixEndpointKey, "prism.nutanix.com") t.Setenv(expClusterResourceSetKey, "true") - envMap, err := provider.EnvMap(clusterSpec) + envMap, err := provider.EnvMap(managementComponents, clusterSpec) assert.NoError(t, err) assert.NotNil(t, envMap) }) diff --git a/pkg/providers/provider.go b/pkg/providers/provider.go index 3c96280fc0c2..b21ce72ea00b 100644 --- a/pkg/providers/provider.go +++ b/pkg/providers/provider.go @@ -27,7 +27,7 @@ type Provider interface { BootstrapClusterOpts(clusterSpec *cluster.Spec) ([]bootstrapper.BootstrapClusterOption, error) UpdateKubeConfig(content *[]byte, clusterName string) error Version(components *cluster.ManagementComponents) string - EnvMap(clusterSpec *cluster.Spec) (map[string]string, error) + EnvMap(managementComponents *cluster.ManagementComponents, clusterSpec *cluster.Spec) (map[string]string, error) GetDeployments() map[string][]string GetInfrastructureBundle(components *cluster.ManagementComponents) *types.InfrastructureBundle DatacenterConfig(clusterSpec *cluster.Spec) DatacenterConfig diff --git a/pkg/providers/snow/snow.go b/pkg/providers/snow/snow.go index 28b0b2616654..2a8770c1faa6 100644 --- a/pkg/providers/snow/snow.go +++ b/pkg/providers/snow/snow.go @@ -185,14 +185,13 @@ func (p *SnowProvider) Version(components *cluster.ManagementComponents) string return components.Snow.Version } -func (p *SnowProvider) EnvMap(clusterSpec *cluster.Spec) (map[string]string, error) { +// EnvMap returns the environment variables for the snow provider. +func (p *SnowProvider) EnvMap(managementComponents *cluster.ManagementComponents, clusterSpec *cluster.Spec) (map[string]string, error) { envMap := make(map[string]string) envMap[snowCredentialsKey] = string(clusterSpec.SnowCredentialsSecret.Data[v1alpha1.SnowCredentialsKey]) envMap[snowCertsKey] = string(clusterSpec.SnowCredentialsSecret.Data[v1alpha1.SnowCertificatesKey]) - versionsBundle := clusterSpec.RootVersionsBundle() - - envMap["SNOW_CONTROLLER_IMAGE"] = versionsBundle.Snow.Manager.VersionedImage() + envMap["SNOW_CONTROLLER_IMAGE"] = managementComponents.Snow.Manager.VersionedImage() return envMap, nil } diff --git a/pkg/providers/tinkerbell/tinkerbell.go b/pkg/providers/tinkerbell/tinkerbell.go index 7517ad1603d5..3ae0e4ea9e87 100644 --- a/pkg/providers/tinkerbell/tinkerbell.go +++ b/pkg/providers/tinkerbell/tinkerbell.go @@ -221,7 +221,8 @@ func (p *Provider) Version(components *cluster.ManagementComponents) string { return components.Tinkerbell.Version } -func (p *Provider) EnvMap(spec *cluster.Spec) (map[string]string, error) { +// EnvMap returns a map of environment variables for the tinkerbell provider. +func (p *Provider) EnvMap(_ *cluster.ManagementComponents, _ *cluster.Spec) (map[string]string, error) { return map[string]string{ // The TINKERBELL_IP is input for the CAPT deployment and used as part of default template // generation. However, we use custom templates and leverage the template override diff --git a/pkg/providers/vsphere/vsphere.go b/pkg/providers/vsphere/vsphere.go index d557d06512e5..7dac7db61a65 100644 --- a/pkg/providers/vsphere/vsphere.go +++ b/pkg/providers/vsphere/vsphere.go @@ -977,7 +977,8 @@ func (p *vsphereProvider) PostWorkloadInit(ctx context.Context, cluster *types.C return nil } -func (p *vsphereProvider) EnvMap(_ *cluster.Spec) (map[string]string, error) { +// EnvMap returns a map of environment variables required for the vsphere provider. +func (p *vsphereProvider) EnvMap(_ *cluster.ManagementComponents, _ *cluster.Spec) (map[string]string, error) { envMap := make(map[string]string) for _, key := range requiredEnvs { if env, ok := os.LookupEnv(key); ok && len(env) > 0 {