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

OIDC extender #360

Merged
merged 4 commits into from
Sep 6, 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
23 changes: 21 additions & 2 deletions internal/gardener/shoot/extender/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,32 @@ package extender
import (
gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"
imv1 "github.com/kyma-project/infrastructure-manager/api/v1"
"k8s.io/utils/ptr"
)

const (
OidcExtensionType = "shoot-oidc-service"
)

func ExtendWithOIDC(runtime imv1.Runtime, shoot *gardener.Shoot) error {
oidcConfig := runtime.Spec.Shoot.Kubernetes.KubeAPIServer.OidcConfig

setOIDCExtension(shoot)
setKubeAPIServerOIDCConfig(shoot, oidcConfig)

return nil
}

func setOIDCExtension(shoot *gardener.Shoot) {
oidcService := gardener.Extension{
Type: OidcExtensionType,
Disabled: ptr.To(false),
}

shoot.Spec.Extensions = append(shoot.Spec.Extensions, oidcService)
}

func setKubeAPIServerOIDCConfig(shoot *gardener.Shoot, oidcConfig gardener.OIDCConfig) {
shoot.Spec.Kubernetes.KubeAPIServer = &gardener.KubeAPIServerConfig{
OIDCConfig: &gardener.OIDCConfig{
CABundle: oidcConfig.CABundle,
Expand All @@ -21,6 +42,4 @@ func ExtendWithOIDC(runtime imv1.Runtime, shoot *gardener.Shoot) error {
UsernamePrefix: oidcConfig.UsernamePrefix,
},
}

return nil
}
3 changes: 3 additions & 0 deletions internal/gardener/shoot/extender/oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func TestOidcExtender(t *testing.T) {

// then
require.NoError(t, err)

assert.Equal(t, runtimeShoot.Spec.Shoot.Kubernetes.KubeAPIServer.OidcConfig, *shoot.Spec.Kubernetes.KubeAPIServer.OIDCConfig)
assert.Equal(t, false, *shoot.Spec.Extensions[0].Disabled)
assert.Equal(t, "shoot-oidc-service", shoot.Spec.Extensions[0].Type)
})
}
Loading