Skip to content

Commit

Permalink
Merge branch 'main' into fix-dump-shoot-name
Browse files Browse the repository at this point in the history
  • Loading branch information
m00g3n authored Sep 19, 2024
2 parents 4879f84 + fe5a19a commit 8b906cf
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 77 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.

104 changes: 59 additions & 45 deletions internal/controller/runtime/fsm/runtime_fsm_configure_auditlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
func sFnConfigureAuditLog(ctx context.Context, m *fsm, s *systemState) (stateFn, *ctrl.Result, error) {
m.log.Info("Configure Audit Log state")

wasAuditLogEnabled, err := m.AuditLogging.Enable(ctx, s.shoot)
shootNeedsToBeReconciled, err := m.AuditLogging.Enable(ctx, s.shoot)

if wasAuditLogEnabled && err == nil {
if shootNeedsToBeReconciled && err == nil {
m.log.Info("Audit Log configured for shoot: " + s.shoot.Name)
s.instance.UpdateStatePending(
imv1.ConditionTypeAuditLogConfigured,
Expand All @@ -28,59 +28,73 @@ func sFnConfigureAuditLog(ctx context.Context, m *fsm, s *systemState) (stateFn,
return updateStatusAndRequeueAfter(gardenerRequeueDuration)
}

auditLogMandatoryString := strconv.FormatBool(m.RCCfg.AuditLogMandatory)
if err == nil {
s.instance.UpdateStateReady(
imv1.ConditionTypeAuditLogConfigured,
imv1.ConditionReasonAuditLogConfigured,
"Audit Log state completed successfully",
)

return updateStatusAndStop()
}

if err != nil { //nolint:nestif
if k8serrors.IsConflict(err) {
m.log.Error(err, "Conflict while updating Shoot object after applying Audit Log configuration, retrying")
return handleError(err, m, s)
}

func handleError(err error, m *fsm, s *systemState) (stateFn, *ctrl.Result, error) {
setStateForAuditLogError := func(reason imv1.RuntimeConditionReason, pendingMsg string, readyMsg string) {
if m.RCCfg.AuditLogMandatory {
s.instance.UpdateStatePending(
imv1.ConditionTypeAuditLogConfigured,
imv1.ConditionReasonAuditLogError,
"True",
err.Error(),
reason,
"False",
pendingMsg,
)
return updateStatusAndRequeue()
} else {
s.instance.UpdateStateReady(
imv1.ConditionTypeAuditLogConfigured,
reason,
readyMsg)
}
errorMessage := err.Error()
if errors.Is(err, auditlogging.ErrMissingMapping) {
if m.RCCfg.AuditLogMandatory {
m.log.Error(err, "AuditLogMandatory", auditLogMandatoryString, "providerType", s.shoot.Spec.Provider.Type, "region", s.shoot.Spec.Region)
s.instance.UpdateStatePending(
imv1.ConditionTypeAuditLogConfigured,
imv1.ConditionReasonAuditLogMissingRegionMapping,
"False",
errorMessage,
)
} else {
m.log.Info(errorMessage, "AuditLogMandatory", auditLogMandatoryString, "providerType", s.shoot.Spec.Provider.Type, "region", s.shoot.Spec.Region)
s.instance.UpdateStateReady(
imv1.ConditionTypeAuditLogConfigured,
imv1.ConditionReasonAuditLogMissingRegionMapping,
"Missing region mapping for this shoot. Audit Log is not mandatory. Skipping configuration")
}
}

logError := func(err error, keysAndValues ...any) {
if m.RCCfg.AuditLogMandatory {
m.log.Error(nil, err.Error(), keysAndValues...)
} else {
if m.RCCfg.AuditLogMandatory {
m.log.Error(err, "AuditLogMandatory", auditLogMandatoryString)
s.instance.UpdateStatePending(
imv1.ConditionTypeAuditLogConfigured,
imv1.ConditionReasonAuditLogError,
"False",
errorMessage)
} else {
m.log.Info(errorMessage, "AuditLogMandatory", auditLogMandatoryString)
s.instance.UpdateStateReady(
imv1.ConditionTypeAuditLogConfigured,
imv1.ConditionReasonAuditLogError,
"Configuration of Audit Log is not mandatory, error for context: "+errorMessage)
}
m.log.Info(err.Error(), keysAndValues...)
}
} else {
s.instance.UpdateStateReady(
}

if k8serrors.IsConflict(err) {
m.log.Error(err, "Conflict while updating Shoot object after applying Audit Log configuration, retrying")
s.instance.UpdateStatePending(
imv1.ConditionTypeAuditLogConfigured,
imv1.ConditionReasonAuditLogConfigured,
"Audit Log state completed successfully",
imv1.ConditionReasonAuditLogError,
"True",
err.Error(),
)

return updateStatusAndRequeue()
}

auditLogMandatoryString := strconv.FormatBool(m.RCCfg.AuditLogMandatory)

if errors.Is(err, auditlogging.ErrMissingMapping) {
pendingStatusMsg := err.Error()
readyStatusMsg := "Missing region mapping for this shoot. Audit Log is not mandatory. Skipping configuration"
setStateForAuditLogError(imv1.ConditionReasonAuditLogMissingRegionMapping, pendingStatusMsg, readyStatusMsg)

logError(err, "AuditLogMandatory", auditLogMandatoryString, "providerType", s.shoot.Spec.Provider.Type, "region", s.shoot.Spec.Region)

return updateStatusAndStop()
}

pendingStatusMsg := err.Error()
readyStatusMsg := "Configuration of Audit Log is not mandatory, error for context: " + err.Error()
setStateForAuditLogError(imv1.ConditionReasonAuditLogError, pendingStatusMsg, readyStatusMsg)

logError(err, "AuditLogMandatory", auditLogMandatoryString)

return updateStatusAndStop()
}
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
}
}
Loading

0 comments on commit 8b906cf

Please sign in to comment.