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

Changing way extensions are handled in KIM and matchers #535

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
07e7e0e
Added extender taking DNS config from the shoot
akgalwas Nov 27, 2024
86436ce
fix shoot extensions matching
m00g3n Nov 28, 2024
a03a67a
Added OIDC extender for update scenario
akgalwas Nov 28, 2024
9f6daa6
Fixes for oidc
akgalwas Nov 28, 2024
0f2e2fa
Added unit tests for new extenders
akgalwas Nov 28, 2024
d1dfc09
Minor refactor
akgalwas Nov 28, 2024
a86f8c3
Linter
akgalwas Nov 28, 2024
b87ae3c
Linter
akgalwas Nov 28, 2024
cff6295
Merge branch 'main' into fix-oidc-extension-for-updated-clusters
akgalwas Nov 28, 2024
7d3e7ef
Linter
akgalwas Nov 28, 2024
0762970
Liiiinteeeeeer
akgalwas Nov 28, 2024
b5334f1
Added missing arguments to the patch converter
akgalwas Nov 28, 2024
b7b3aa2
Removed setting secret reference in DNS extender
akgalwas Nov 29, 2024
9d58146
Added comparing resources in the matchers
akgalwas Nov 29, 2024
ff6905a
Updated role.yaml and corrected a message in Migrator
akgalwas Nov 29, 2024
90f1516
Reverted useless change in oidc state
akgalwas Nov 29, 2024
f96e502
fix converter test
m00g3n Nov 28, 2024
8278a4d
Started working on separate extender for extensions
akgalwas Nov 29, 2024
fdf9ef3
Add audit log matching
akgalwas Dec 2, 2024
b77e324
Implementation of separate extension extender
akgalwas Dec 2, 2024
faf1881
Implementation of separate extension extender
akgalwas Dec 2, 2024
a2379bd
Linter
akgalwas Dec 2, 2024
2ec3890
Merge branch 'main' into fix-oidc-extension-for-updated-clusters
akgalwas Dec 2, 2024
8601202
Linter
akgalwas Dec 2, 2024
c63e7e5
Linter
akgalwas Dec 2, 2024
7ca488c
Implemented logic for OIDC
akgalwas Dec 2, 2024
363c612
Fixes in the new extender
akgalwas Dec 2, 2024
c77e1d4
Linter
akgalwas Dec 2, 2024
89d109a
Code integrated
akgalwas Dec 2, 2024
f6c6383
Code integrated
akgalwas Dec 2, 2024
08dbb11
Linter
akgalwas Dec 2, 2024
ea30bb7
Linter
akgalwas Dec 2, 2024
ed1cb3a
Linter
akgalwas Dec 2, 2024
546ae88
Linter
akgalwas Dec 2, 2024
a3f99c1
Unit tests
akgalwas Dec 2, 2024
dbf4a29
Unit tests
akgalwas Dec 2, 2024
367e5c9
Fix for create scenario
akgalwas Dec 2, 2024
237a8b8
Fix for index out of bound problem
akgalwas Dec 2, 2024
cf4a5f7
Escaping the rabbit hole
akgalwas Dec 2, 2024
672faa0
Transferring to parallel universe
akgalwas Dec 2, 2024
707739b
Coming back to the future
akgalwas Dec 3, 2024
95ed3f1
Satisfying the linter
akgalwas Dec 3, 2024
79715a8
Merge branch 'main' into fix-oidc-extension-for-updated-clusters
akgalwas Dec 3, 2024
2a345b8
Add network filter extension extender to include for patch operation
koala7659 Dec 3, 2024
a1b29a1
Adding unit tests for new extension extender
koala7659 Dec 3, 2024
90926fe
Removing unused code, and references to it
koala7659 Dec 3, 2024
81c272e
Merge branch 'main' into fix-oidc-extension-for-updated-clusters
Disper Dec 4, 2024
165eb39
Fix for the overwriting tolerations problem
akgalwas Dec 4, 2024
9ff933b
Linter, please go away.
akgalwas Dec 4, 2024
db657a4
Fix the fix
akgalwas Dec 4, 2024
1b72715
Revert "Fix the fix"
akgalwas Dec 4, 2024
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
1 change: 1 addition & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ rules:
- infrastructuremanager.kyma-project.io
resources:
- gardenerclusters
- runtimes
verbs:
- create
- delete
Expand Down
3 changes: 1 addition & 2 deletions hack/runtime-migrator/cmd/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/kyma-project/infrastructure-manager/pkg/config"
"github.com/kyma-project/infrastructure-manager/pkg/gardener/kubeconfig"
"github.com/kyma-project/infrastructure-manager/pkg/gardener/shoot/extender/auditlogs"
"github.com/pkg/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -139,7 +138,7 @@ func (m Migration) Do(ctx context.Context, runtimeIDs []string) error {
return
}

reportSuccess(runtimeID, shoot.Name, "Runtime have been applied")
reportSuccess(runtimeID, shoot.Name, "Runtime has been applied")
}
}

Expand Down
29 changes: 26 additions & 3 deletions hack/runtime-migrator/internal/runtime/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,36 @@ func (v Verifier) newConverter(shootToMatch v1beta1.Shoot) (gardener_shoot.Conve
return gardener_shoot.Converter{}, err
}

imgName, imgVersion := getImageNameAndVersion(shootToMatch.Spec.Provider.Workers)

return gardener_shoot.NewConverterPatch(gardener_shoot.PatchOpts{
ConverterConfig: v.converterConfig,
AuditLogData: auditLogData,
Zones: getZones(shootToMatch.Spec.Provider.Workers),
ConverterConfig: v.converterConfig,
AuditLogData: auditLogData,
Zones: getZones(shootToMatch.Spec.Provider.Workers),
ShootK8SVersion: shootToMatch.Spec.Kubernetes.Version,
ShootImageName: imgName,
ShootImageVersion: imgVersion,
Extensions: shootToMatch.Spec.Extensions,
Resources: shootToMatch.Spec.Resources,
}), nil
}

func getImageNameAndVersion(workers []v1beta1.Worker) (string, string) {
var imageName, imageVersion string

for _, worker := range workers {
if worker.Machine.Image != nil {
imageName = worker.Machine.Image.Name
if worker.Machine.Image.Version != nil {
imageVersion = *worker.Machine.Image.Version
}
break
}
}

return imageName, imageVersion
}

func getZones(workers []v1beta1.Worker) []string {
var zones []string

Expand Down
35 changes: 33 additions & 2 deletions hack/shoot-comparator/pkg/shoot/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"reflect"
"strings"

"github.com/kyma-project/infrastructure-manager/hack/shoot-comparator/pkg/runtime"

"github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/kyma-project/infrastructure-manager/hack/shoot-comparator/pkg/errors"
"github.com/onsi/gomega"
Expand Down Expand Up @@ -164,6 +166,15 @@ func (m *Matcher) Match(actual interface{}) (success bool, err error) {
actual: shootToMatch.Labels,
path: "metadata/labels",
},
{
GomegaMatcher: gstruct.MatchElements(
idResource,
gstruct.IgnoreMissing,
resources(shootToMatch.Spec.Resources),
),
actual: shootActual.Spec.Resources,
path: "spec/resources",
},
}

for _, matcher := range matchers {
Expand Down Expand Up @@ -230,6 +241,14 @@ func idToleration(v interface{}) string {
return fmt.Sprintf("%s:%s", toleration.Key, val(toleration.Value))
}

func idResource(v interface{}) string {
res, ok := v.(v1beta1.NamedResourceReference)
if !ok {
panic("invalid type")
}
return fmt.Sprintf("%s", res.Name)
}

func tolerations(ts []v1beta1.Toleration) gstruct.Elements {
out := map[string]types.GomegaMatcher{}
for _, t := range ts {
Expand All @@ -242,6 +261,18 @@ func tolerations(ts []v1beta1.Toleration) gstruct.Elements {
return out
}

func resources(ts []v1beta1.NamedResourceReference) gstruct.Elements {
out := map[string]types.GomegaMatcher{}
for _, t := range ts {
ID := idResource(t)
out[ID] = gstruct.MatchAllFields(gstruct.Fields{
"Name": gomega.BeComparableTo(t.Name),
"ResourceRef": gomega.BeComparableTo(t.ResourceRef),
})
}
return out
}

func idProvider(v interface{}) string {
provider, ok := v.(v1beta1.DNSProvider)
if !ok {
Expand Down Expand Up @@ -339,7 +370,7 @@ func newKubeAPIServerMatcher(k v1beta1.Kubernetes) types.GomegaMatcher {
"KubernetesConfig": gstruct.Ignore(),
"AdmissionPlugins": gstruct.Ignore(),
"APIAudiences": gstruct.Ignore(),
"AuditConfig": gstruct.Ignore(),
"AuditConfig": gomega.BeComparableTo(k.KubeAPIServer.AuditConfig),
"RuntimeConfig": gstruct.Ignore(),
"ServiceAccountConfig": gstruct.Ignore(),
"WatchCacheSizes": gstruct.Ignore(),
Expand Down Expand Up @@ -393,7 +424,7 @@ func extensions(es []v1beta1.Extension) gstruct.Elements {
ID := idExtension(e)
out[ID] = gstruct.MatchAllFields(gstruct.Fields{
"Type": gomega.BeComparableTo(e.Type),
"ProviderConfig": newProviderCfgMatcher(e.Type, e.ProviderConfig),
"ProviderConfig": runtime.NewRawExtensionMatcher(e.ProviderConfig),
"Disabled": gomega.BeComparableTo(e.Disabled),
})
}
Expand Down
26 changes: 0 additions & 26 deletions hack/shoot-comparator/pkg/shoot/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,32 +934,6 @@ var _ = Describe(":: shoot matcher :: ", func() {
})),
true,
),
Entry(
"should find no differences in spec/extensions #2",
deepCp(empty, withShootSpec(v1beta1.ShootSpec{
Extensions: []v1beta1.Extension{
{
Type: "shoot-dns-service",
Disabled: ptr.To[bool](true),
ProviderConfig: &runtime.RawExtension{
Raw: []byte("{\"apiVersion\":\"service.dns.extensions.gardener.cloud/v1alpha1\",\"kind\":\"DNSConfig\",\"dnsProviderReplication\":{\"enabled\":true},\"providers\":[{\"domains\":{\"include\":[\"a50de45.dev.kyma.ondemand.com\"]},\"secretName\":\"route53-secret-dev\",\"type\":\"aws-route53\"}],\"syncProvidersFromShootSpecDNS\":true}"),
},
},
},
})),
deepCp(empty, withShootSpec(v1beta1.ShootSpec{
Extensions: []v1beta1.Extension{
{
Type: "shoot-dns-service",
Disabled: ptr.To[bool](true),
ProviderConfig: &runtime.RawExtension{
Raw: []byte("{\"apiVersion\":\"service.dns.extensions.gardener.cloud/v1alpha1\",\"kind\":\"DNSConfig\",\"dnsProviderReplication\":{\"enabled\":true},\"providers\":[{\"domains\":{\"include\":[\"a50de45.dev.kyma.ondemand.com\"]},\"secretName\":\"xxx-route53-secret-dev\",\"type\":\"aws-route53\"}],\"syncProvidersFromShootSpecDNS\":true}"),
},
},
},
})),
true,
),
Entry(
"should find no differences in spec/extensions #3",
deepCp(empty, withShootSpec(v1beta1.ShootSpec{
Expand Down
20 changes: 18 additions & 2 deletions internal/controller/runtime/fsm/runtime_fsm_configure_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ func sFnConfigureOidc(ctx context.Context, m *fsm, s *systemState) (stateFn, *ct
"True",
"OIDC extension disabled",
)

return switchState(sFnApplyClusterRoleBindings)
}

if !multiOidcSupported(s.instance) {
// New OIDC functionality is supported only for new clusters
m.log.Info("Multi OIDC is not supported for migrated runtimes")
s.instance.UpdateStatePending(
imv1.ConditionTypeOidcConfigured,
imv1.ConditionReasonOidcConfigured,
"True",
"Multi OIDC not supported for migrated runtimes",
)
return switchState(sFnApplyClusterRoleBindings)
}

Expand All @@ -37,15 +50,14 @@ func sFnConfigureOidc(ctx context.Context, m *fsm, s *systemState) (stateFn, *ct
return updateStatusAndStopWithError(err)
}

m.log.Info("OIDC has been configured", "Name", s.shoot.Name)
s.instance.UpdateStatePending(
imv1.ConditionTypeOidcConfigured,
imv1.ConditionReasonOidcConfigured,
"True",
"OIDC configuration completed",
)

m.log.Info("OIDC has been configured", "Name", s.shoot.Name)

return switchState(sFnApplyClusterRoleBindings)
}

Expand Down Expand Up @@ -108,6 +120,10 @@ func isOidcExtensionEnabled(shoot gardener.Shoot) bool {
return false
}

func multiOidcSupported(runtime imv1.Runtime) bool {
return runtime.Labels["operator.kyma-project.io/created-by-migrator"] != "true" //nolint:all
}

func createOpenIDConnectResource(additionalOidcConfig gardener.OIDCConfig, oidcID int) *authenticationv1alpha1.OpenIDConnect {
toSupportedSigningAlgs := func(signingAlgs []string) []authenticationv1alpha1.SigningAlgorithm {
var supportedSigningAlgs []authenticationv1alpha1.SigningAlgorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,45 @@ func TestOidcState(t *testing.T) {
assertEqualConditions(t, expectedRuntimeConditions, systemState.instance.Status.Conditions)
})

t.Run("Should switch state to ApplyClusterRoleBindings when multi OIDC support is disabled", func(t *testing.T) {
// given
ctx := context.Background()
fsm := &fsm{}

runtimeStub := runtimeForTest()
runtimeStub.ObjectMeta.Labels = map[string]string{
"operator.kyma-project.io/created-by-migrator": "true",
}

shootStub := shootForTest()
oidcService := gardener.Extension{
Type: "shoot-oidc-service",
Disabled: ptr.To(false),
}
shootStub.Spec.Extensions = append(shootStub.Spec.Extensions, oidcService)

systemState := &systemState{
instance: runtimeStub,
shoot: shootStub,
}

expectedRuntimeConditions := []metav1.Condition{
{
Type: string(imv1.ConditionTypeOidcConfigured),
Reason: string(imv1.ConditionReasonOidcConfigured),
Status: "True",
Message: "Multi OIDC not supported for migrated runtimes",
},
}

// when
stateFn, _, _ := sFnConfigureOidc(ctx, fsm, systemState)

// then
require.Contains(t, stateFn.name(), "sFnApplyClusterRoleBindings")
assertEqualConditions(t, expectedRuntimeConditions, systemState.instance.Status.Conditions)
})

t.Run("Should configure OIDC using defaults", func(t *testing.T) {
// given
ctx := context.Background()
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func sFnPatchExistingShoot(ctx context.Context, m *fsm, s *systemState) (stateFn
ShootK8SVersion: s.shoot.Spec.Kubernetes.Version,
ShootImageName: imgName,
ShootImageVersion: imgVersion,
Extensions: s.shoot.Spec.Extensions,
Resources: s.shoot.Spec.Resources,
})

if err != nil {
Expand Down
15 changes: 10 additions & 5 deletions internal/controller/runtime/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package runtime
import (
"context"
"encoding/json"
"github.com/kyma-project/infrastructure-manager/pkg/gardener/shoot/extender/extensions"
v12 "k8s.io/api/core/v1"
"path/filepath"
"testing"
"time"
Expand All @@ -36,7 +38,6 @@ import (
"github.com/pkg/errors"
"github.com/stretchr/testify/mock"
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 Expand Up @@ -346,9 +347,13 @@ func fixConverterConfigForTests() config.Config {
}

func addAuditLogConfigToShoot(shoot *gardener_api.Shoot) {
shoot.Spec.Kubernetes.KubeAPIServer.AuditConfig = &gardener_api.AuditConfig{
AuditPolicy: &gardener_api.AuditPolicy{
ConfigMapRef: &v12.ObjectReference{Name: "policy-config-map"},
shoot.Spec.Kubernetes = gardener_api.Kubernetes{
KubeAPIServer: &gardener_api.KubeAPIServerConfig{
AuditConfig: &gardener_api.AuditConfig{
AuditPolicy: &gardener_api.AuditPolicy{
ConfigMapRef: &v12.ObjectReference{Name: "policy-config-map"},
},
},
},
}

Expand All @@ -373,7 +378,7 @@ func addAuditLogConfigToShoot(shoot *gardener_api.Shoot) {

ext := &shoot.Spec.Extensions[len(shoot.Spec.Extensions)-1]

cfg := auditlogs.AuditlogExtensionConfig{
cfg := extensions.AuditlogExtensionConfig{
TypeMeta: metav1.TypeMeta{
Kind: extensionKind,
APIVersion: extensionVersion,
Expand Down
Loading
Loading