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

Handing missing Disabled field in OIDC extension data to avoid crash #551

Merged
merged 1 commit into from
Dec 5, 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
3 changes: 3 additions & 0 deletions hack/runtime-migrator/internal/runtime/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ func getControlPlane(shoot v1beta1.Shoot) *v1beta1.ControlPlane {
func checkIfShootNetworkFilteringEnabled(shoot v1beta1.Shoot) bool {
for _, extension := range shoot.Spec.Extensions {
if extension.Type == ShootNetworkingFilterExtensionType {
if extension.Disabled == nil {
return true
}
return !(*extension.Disabled)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func deleteExistingKymaOpenIDConnectResources(ctx context.Context, client k8s_cl
func isOidcExtensionEnabled(shoot gardener.Shoot) bool {
for _, extension := range shoot.Spec.Extensions {
if extension.Type == extender.OidcExtensionType {
if extension.Disabled == nil {
return true
}
return !(*extension.Disabled)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,74 @@ func TestOidcState(t *testing.T) {
assertEqualConditions(t, expectedRuntimeConditions, systemState.instance.Status.Conditions)
})

t.Run("Should not crash and configure OIDC using defaults when Disabled field is missing in extension data", func(t *testing.T) {
// given
ctx := context.Background()

// start of fake client setup
scheme, err := newOIDCTestScheme()
require.NoError(t, err)
var fakeClient = fake.NewClientBuilder().
WithScheme(scheme).
Build()
testFsm := &fsm{K8s: K8s{
ShootClient: fakeClient,
Client: fakeClient,
},
RCCfg: RCCfg{
Config: config.Config{
ClusterConfig: config.ClusterConfig{
DefaultSharedIASTenant: createConverterOidcConfig("defaut-client-id"),
},
},
},
}
GetShootClient = func(
_ context.Context,
_ client.Client,
_ imv1.Runtime) (client.Client, error) {
return fakeClient, nil
}
// end of fake client setup

runtimeStub := runtimeForTest()
shootStub := shootForTest()
oidcService := gardener.Extension{
Type: "shoot-oidc-service",
Disabled: nil,
}
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: "OIDC configuration completed",
},
}

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

// then
require.Contains(t, stateFn.name(), "sFnApplyClusterRoleBindings")

var openIdConnects authenticationv1alpha1.OpenIDConnectList

err = fakeClient.List(ctx, &openIdConnects)
require.NoError(t, err)
assert.Len(t, openIdConnects.Items, 1)

assertOIDCCRD(t, "kyma-oidc-0", "defaut-client-id", openIdConnects.Items[0])
assertEqualConditions(t, expectedRuntimeConditions, systemState.instance.Status.Conditions)
})

t.Run("Should configure OIDC based on Runtime CR configuration", func(t *testing.T) {
// given
ctx := context.Background()
Expand Down
Loading