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

Add default machine image name #382

Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion internal/gardener/shoot/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type GardenerConfig struct {
}

type MachineImageConfig struct {
DefaultName string `json:"defaultName" validate:"required"`
DefaultVersion string `json:"defaultVersion" validate:"required"`
}

Expand All @@ -75,7 +76,7 @@ func NewConverter(config ConverterConfig) Converter {
extender.ExtendWithAnnotations,
extender.ExtendWithLabels,
extender.NewKubernetesVersionExtender(config.Kubernetes.DefaultVersion),
extender.NewProviderExtender(config.Provider.AWS.EnableIMDSv2, config.MachineImage.DefaultVersion),
extender.NewProviderExtender(config.Provider.AWS.EnableIMDSv2, config.MachineImage.DefaultName, config.MachineImage.DefaultVersion),
extender.NewDNSExtender(config.DNS.SecretName, config.DNS.DomainPrefix, config.DNS.ProviderType),
extender.ExtendWithOIDC,
extender.ExtendWithCloudProfile,
Expand Down
2 changes: 2 additions & 0 deletions internal/gardener/shoot/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ var testReader io.Reader = strings.NewReader(`{
}
},
"machineImage": {
"defaultName": "test-image-name",
"defaultVersion": "0.1.2.3.4"
},
"gardener": {
Expand Down Expand Up @@ -188,6 +189,7 @@ func Test_ConverterConfig_Load_OK(t *testing.T) {
},
},
MachineImage: MachineImageConfig{
DefaultName: "test-image-name",
DefaultVersion: "0.1.2.3.4",
},
Gardener: GardenerConfig{
Expand Down
11 changes: 8 additions & 3 deletions internal/gardener/shoot/extender/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)

func NewProviderExtender(enableIMDSv2 bool, defaultMachineImageVersion string) func(runtime imv1.Runtime, shoot *gardener.Shoot) error {
func NewProviderExtender(enableIMDSv2 bool, defaultMachineImageName, defaultMachineImageVersion string) func(runtime imv1.Runtime, shoot *gardener.Shoot) error {
return func(runtime imv1.Runtime, shoot *gardener.Shoot) error {
provider := &shoot.Spec.Provider
provider.Type = runtime.Spec.Shoot.Provider.Type
Expand All @@ -26,7 +26,7 @@ func NewProviderExtender(enableIMDSv2 bool, defaultMachineImageVersion string) f
return err
}

setDefaultMachineImageVersion(provider, defaultMachineImageVersion)
setDefaultMachineImage(provider, defaultMachineImageName, defaultMachineImageVersion)
err = setWorkerConfig(provider, provider.Type, enableIMDSv2)
setWorkerSettings(provider)

Expand Down Expand Up @@ -122,12 +122,13 @@ func setWorkerSettings(provider *gardener.Provider) {
}
}

func setDefaultMachineImageVersion(provider *gardener.Provider, defaultMachineImageVersion string) {
func setDefaultMachineImage(provider *gardener.Provider, defaultMachineImageName, defaultMachineImageVersion string) {
for i := 0; i < len(provider.Workers); i++ {
worker := &provider.Workers[i]

if worker.Machine.Image == nil {
worker.Machine.Image = &gardener.ShootMachineImage{
Name: defaultMachineImageName,
Version: &defaultMachineImageVersion,
}

Expand All @@ -138,6 +139,10 @@ func setDefaultMachineImageVersion(provider *gardener.Provider, defaultMachineIm
machineImageVersion = &defaultMachineImageVersion
}

if worker.Machine.Image.Name == "" {
worker.Machine.Image.Name = defaultMachineImageName
}

worker.Machine.Image.Version = machineImageVersion
}
}
11 changes: 7 additions & 4 deletions internal/gardener/shoot/extender/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func TestProviderExtender(t *testing.T) {
EnableIMDSv2 bool
DefaultMachineImageVersion string
ExpectedMachineImageVersion string
DefaultMachineImageName string
ExpectedMachineImageName string
ExpectedZonesCount int
}{
"Create provider specific config for AWS without worker config": {
Expand Down Expand Up @@ -65,13 +67,13 @@ func TestProviderExtender(t *testing.T) {
shoot := fixEmptyGardenerShoot("cluster", "kcp-system")

// when
extender := NewProviderExtender(testCase.EnableIMDSv2, testCase.DefaultMachineImageVersion)
extender := NewProviderExtender(testCase.EnableIMDSv2, testCase.DefaultMachineImageName, testCase.DefaultMachineImageVersion)
err := extender(testCase.Runtime, &shoot)

// then
require.NoError(t, err)

assertProvider(t, testCase.Runtime.Spec.Shoot, shoot, testCase.EnableIMDSv2, testCase.ExpectedMachineImageVersion)
assertProvider(t, testCase.Runtime.Spec.Shoot, shoot, testCase.EnableIMDSv2, testCase.ExpectedMachineImageName, testCase.ExpectedMachineImageVersion)
assertProviderSpecificConfig(t, shoot, testCase.ExpectedZonesCount)
})
}
Expand All @@ -90,7 +92,7 @@ func TestProviderExtender(t *testing.T) {
}

// when
extender := NewProviderExtender(false, "")
extender := NewProviderExtender(false, "", "")
err := extender(runtime, &shoot)

// then
Expand Down Expand Up @@ -175,7 +177,7 @@ func fixAWSProviderWithMultipleWorkers() imv1.Provider {
}
}

func assertProvider(t *testing.T, runtimeShoot imv1.RuntimeShoot, shoot gardener.Shoot, expectWorkerConfig bool, expectedMachineImageVersion string) {
func assertProvider(t *testing.T, runtimeShoot imv1.RuntimeShoot, shoot gardener.Shoot, expectWorkerConfig bool, expectedMachineImageName, expectedMachineImageVersion string) {
assert.Equal(t, runtimeShoot.Provider.Type, shoot.Spec.Provider.Type)
assert.Equal(t, runtimeShoot.Provider.Workers, shoot.Spec.Provider.Workers)
assert.Equal(t, false, shoot.Spec.Provider.WorkersSettings.SSHAccess.Enabled)
Expand All @@ -192,6 +194,7 @@ func assertProvider(t *testing.T, runtimeShoot imv1.RuntimeShoot, shoot gardener
assert.Empty(t, worker.ProviderConfig)
}
assert.Equal(t, expectedMachineImageVersion, *worker.Machine.Image.Version)
assert.Equal(t, expectedMachineImageName, worker.Machine.Image.Name)
}
}

Expand Down
Loading