Skip to content

Commit

Permalink
Add default machine image name (#382)
Browse files Browse the repository at this point in the history
* Add default image name

* Run gci

---------

Co-authored-by: Arkadiusz Galwas <arkadiusz.galwas@sap.com>
  • Loading branch information
VOID404 and akgalwas authored Sep 19, 2024
1 parent aff1b4f commit 26f8316
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 32 deletions.
5 changes: 3 additions & 2 deletions hack/shoot-comparator/cmd/comparator/directories.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package comparator

import (
"fmt"
"github.com/kyma-project/infrastructure-manager/tools/shoot-comparator/internal/directories"
"github.com/spf13/cobra"
"log/slog"
"time"

"github.com/kyma-project/infrastructure-manager/tools/shoot-comparator/internal/directories"
"github.com/spf13/cobra"
)

func init() {
Expand Down
1 change: 1 addition & 0 deletions hack/shoot-comparator/cmd/comparator/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package comparator

import (
"fmt"

"github.com/kyma-project/infrastructure-manager/tools/shoot-comparator/internal/files"
"github.com/spf13/cobra"
)
Expand Down
3 changes: 2 additions & 1 deletion hack/shoot-comparator/internal/directories/comparator.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package directories

import (
"github.com/kyma-project/infrastructure-manager/tools/shoot-comparator/internal/files"
"os"
"path"
"slices"
"time"

"github.com/kyma-project/infrastructure-manager/tools/shoot-comparator/internal/files"
)

type Result struct {
Expand Down
6 changes: 3 additions & 3 deletions hack/shoot-comparator/internal/directories/comparator_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package directories

import (
"github.com/gardener/gardener/pkg/apis/core/v1beta1"
"gopkg.in/yaml.v3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"os"
"path"
"testing"
"time"

"github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const onlyLeftFilename = "onlyLeftFile.yaml"
Expand Down
3 changes: 2 additions & 1 deletion hack/shoot-comparator/internal/files/comparator.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package files

import (
"os"

"github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/kyma-project/infrastructure-manager/tools/shoot-comparator/pkg/shoot"
"os"
"sigs.k8s.io/yaml"
)

Expand Down
7 changes: 4 additions & 3 deletions hack/shoot-comparator/pkg/shoot/extensionmatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package shoot

import (
"fmt"
"github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/onsi/gomega"
"github.com/onsi/gomega/types"
"reflect"
"sort"
"strings"

"github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/onsi/gomega"
"github.com/onsi/gomega/types"
)

type ExtensionMatcher struct {
Expand Down
1 change: 1 addition & 0 deletions hack/shoot-comparator/pkg/shoot/extensionmatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package shoot

import (
"fmt"

"github.com/gardener/gardener/pkg/apis/core/v1beta1"
. "github.com/onsi/ginkgo/v2" //nolint:revive
. "github.com/onsi/gomega" //nolint:revive
Expand Down
5 changes: 1 addition & 4 deletions internal/auditlogging/mocks/AuditLogConfigurator.go

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

6 changes: 3 additions & 3 deletions internal/controller/runtime/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ package runtime
import (
"context"
"encoding/json"
"github.com/kyma-project/infrastructure-manager/internal/auditlogging"
v1 "k8s.io/api/autoscaling/v1"
v12 "k8s.io/api/core/v1"
"path/filepath"
"testing"
"time"

gardener_api "github.com/gardener/gardener/pkg/apis/core/v1beta1"
infrastructuremanagerv1 "github.com/kyma-project/infrastructure-manager/api/v1"
"github.com/kyma-project/infrastructure-manager/internal/auditlogging"
"github.com/kyma-project/infrastructure-manager/internal/controller/runtime/fsm"
gardener_shoot "github.com/kyma-project/infrastructure-manager/internal/gardener/shoot"
. "github.com/onsi/ginkgo/v2" //nolint:revive
. "github.com/onsi/gomega" //nolint:revive
v1 "k8s.io/api/autoscaling/v1"
v12 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
//nolint:revive
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/runtime/test_client_obj_tracker_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package runtime

import (
"testing"

gardener_api "github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"testing"
)

func TestCustomTracker_Get(t *testing.T) {
Expand Down
7 changes: 2 additions & 5 deletions internal/gardener/mocks/ShootClient.go

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

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.NewKubernetesExtender(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
2 changes: 1 addition & 1 deletion internal/gardener/shoot/extender/oidc_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package extender

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"testing"

gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"
imv1 "github.com/kyma-project/infrastructure-manager/api/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestOidcExtender(t *testing.T) {
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

0 comments on commit 26f8316

Please sign in to comment.