Skip to content

Commit

Permalink
Merge pull request #360 from Disper/oidc-extender
Browse files Browse the repository at this point in the history
OIDC extender
  • Loading branch information
kyma-bot authored Sep 6, 2024
2 parents cc4da41 + 46d46b8 commit c9900b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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)
})
}

0 comments on commit c9900b4

Please sign in to comment.