Skip to content

Commit

Permalink
generate snow provider environment variable map using management comp…
Browse files Browse the repository at this point in the history
…onents (#7568)
  • Loading branch information
cxbrowne1207 authored Feb 13, 2024
1 parent 91339ef commit c9fa512
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 23 deletions.
6 changes: 3 additions & 3 deletions pkg/executables/clusterctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/executables/clusterctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand All @@ -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"))
Expand Down
3 changes: 2 additions & 1 deletion pkg/providers/cloudstack/cloudstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/providers/mocks/providers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/providers/nutanix/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions pkg/providers/nutanix/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions pkg/providers/snow/snow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/providers/tinkerbell/tinkerbell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/providers/vsphere/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c9fa512

Please sign in to comment.