Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate snow provider environment variable map using management components #7568

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
params = append(params, "--kubeconfig", cluster.KubeconfigFile)
}

envMap, err := infraProvider.EnvMap(clusterSpec)
envMap, err := infraProvider.EnvMap(managementComponents, clusterSpec)

Check warning on line 422 in pkg/executables/clusterctl.go

View check run for this annotation

Codecov / codecov/patch

pkg/executables/clusterctl.go#L422

Added line #L422 was not covered by tests
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 @@
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) {

Check warning on line 819 in pkg/providers/cloudstack/cloudstack.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/cloudstack/cloudstack.go#L819

Added line #L819 was not covered by tests
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 @@
}

// 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) {

Check warning on line 635 in pkg/providers/docker/docker.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/docker/docker.go#L635

Added line #L635 was not covered by tests
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 @@ -530,7 +530,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 @@
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) {

Check warning on line 189 in pkg/providers/snow/snow.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/snow/snow.go#L189

Added line #L189 was not covered by tests
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()

Check warning on line 194 in pkg/providers/snow/snow.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/snow/snow.go#L194

Added line #L194 was not covered by tests

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

Check warning on line 225 in pkg/providers/tinkerbell/tinkerbell.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/tinkerbell/tinkerbell.go#L225

Added line #L225 was not covered by tests
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 @@
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) {

Check warning on line 981 in pkg/providers/vsphere/vsphere.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/vsphere/vsphere.go#L981

Added line #L981 was not covered by tests
envMap := make(map[string]string)
for _, key := range requiredEnvs {
if env, ok := os.LookupEnv(key); ok && len(env) > 0 {
Expand Down
Loading