Skip to content

Commit

Permalink
Merge branch 'main' into shoot-comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
m00g3n authored May 21, 2024
2 parents 0373788 + ca34464 commit cdbbdaf
Show file tree
Hide file tree
Showing 20 changed files with 620 additions and 96 deletions.
27 changes: 13 additions & 14 deletions api/v1/runtime_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package v1
import (
gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

//+kubebuilder:object:root=true
Expand Down Expand Up @@ -64,15 +63,17 @@ type RuntimeStatus struct {
}

type RuntimeShoot struct {
Name string `json:"name"`
Purpose gardener.ShootPurpose `json:"purpose"`
Region string `json:"region"`
LicenceType *string `json:"licenceType,omitempty"`
SecretBindingName string `json:"secretBindingName"`
Kubernetes Kubernetes `json:"kubernetes"`
Provider Provider `json:"provider"`
Networking Networking `json:"networking"`
ControlPlane gardener.ControlPlane `json:"controlPlane"`
Name string `json:"name"`
Purpose gardener.ShootPurpose `json:"purpose"`
PlatformRegion string `json:"platformRegion"`
Region string `json:"region"`
LicenceType *string `json:"licenceType,omitempty"`
SecretBindingName string `json:"secretBindingName"`
EnforceSeedLocation *bool `json:"enforceSeedLocation,omitempty"`
Kubernetes Kubernetes `json:"kubernetes"`
Provider Provider `json:"provider"`
Networking Networking `json:"networking"`
ControlPlane gardener.ControlPlane `json:"controlPlane"`
}

type Kubernetes struct {
Expand All @@ -86,10 +87,8 @@ type APIServer struct {
}

type Provider struct {
Type string `json:"type"`
ControlPlaneConfig runtime.RawExtension `json:"controlPlaneConfig"`
InfrastructureConfig runtime.RawExtension `json:"infrastructureConfig"`
Workers []gardener.Worker `json:"workers"`
Type string `json:"type"`
Workers []gardener.Worker `json:"workers"`
}

type Networking struct {
Expand Down
9 changes: 6 additions & 3 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ spec:
- failureTolerance
type: object
type: object
enforceSeedLocation:
type: boolean
kubernetes:
properties:
kubeAPIServer:
Expand Down Expand Up @@ -295,14 +297,10 @@ spec:
- pods
- services
type: object
platformRegion:
type: string
provider:
properties:
controlPlaneConfig:
type: object
x-kubernetes-preserve-unknown-fields: true
infrastructureConfig:
type: object
x-kubernetes-preserve-unknown-fields: true
type:
type: string
workers:
Expand Down Expand Up @@ -1001,8 +999,6 @@ spec:
type: object
type: array
required:
- controlPlaneConfig
- infrastructureConfig
- type
- workers
type: object
Expand All @@ -1018,6 +1014,7 @@ spec:
- kubernetes
- name
- networking
- platformRegion
- provider
- purpose
- region
Expand Down
5 changes: 1 addition & 4 deletions internal/controller/runtime_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
. "github.com/onsi/gomega" //nolint:revive
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apimachneryruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
Expand Down Expand Up @@ -55,9 +54,7 @@ var _ = Describe("Runtime Controller", func() {
Shoot: imv1.RuntimeShoot{
Networking: imv1.Networking{},
Provider: imv1.Provider{
ControlPlaneConfig: apimachneryruntime.RawExtension{Raw: []byte("{}")},
InfrastructureConfig: apimachneryruntime.RawExtension{Raw: []byte("{}")},
Workers: []gardener.Worker{},
Workers: []gardener.Worker{},
},
},
Security: imv1.Security{
Expand Down
104 changes: 37 additions & 67 deletions internal/gardener/shoot/converter.go
Original file line number Diff line number Diff line change
@@ -1,89 +1,59 @@
package shoot

import (
gardenerv1beta "github.com/gardener/gardener/pkg/apis/core/v1beta1"
gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"
imv1 "github.com/kyma-project/infrastructure-manager/api/v1"
"github.com/kyma-project/infrastructure-manager/internal/gardener/shoot/extender"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func ToShoot(runtime imv1.Runtime) gardenerv1beta.Shoot {
return gardenerv1beta.Shoot{
ObjectMeta: v1.ObjectMeta{
Name: runtime.Spec.Shoot.Name,
Namespace: runtime.Namespace,
Labels: getLabels(runtime),
Annotations: getAnnotations(runtime),
},
Spec: getShootSpec(runtime.Spec.Shoot),
}
}

func getLabels(_ imv1.Runtime) map[string]string {
return map[string]string{}
type Converter struct {
extenders []extender.Extend
}

func getAnnotations(_ imv1.Runtime) map[string]string {
return map[string]string{}
type ConverterConfig struct {
DefaultKubernetesVersion string
DNSSecretName string
DomainPrefix string
DNSProviderType string
}

func getShootSpec(runtimeShoot imv1.RuntimeShoot) gardenerv1beta.ShootSpec {
return gardenerv1beta.ShootSpec{
Purpose: &runtimeShoot.Purpose,
Region: runtimeShoot.Region,
SecretBindingName: &runtimeShoot.SecretBindingName,
Kubernetes: getKubernetes(runtimeShoot.Kubernetes),
Networking: getNetworking(runtimeShoot.Networking),
Provider: getProvider(runtimeShoot.Provider),
ControlPlane: &runtimeShoot.ControlPlane,
func NewConverter(config ConverterConfig) Converter {
extenders := []extender.Extend{
extender.ExtendWithAnnotations,
extender.NewExtendWithKubernetes(config.DefaultKubernetesVersion),
extender.ExtendWithNetworking,
extender.ExtendWithProvider,
extender.NewExtendWithDNS(config.DNSSecretName, config.DomainPrefix, config.DNSProviderType),
}
}

func getKubernetes(kubernetes imv1.Kubernetes) gardenerv1beta.Kubernetes {
return gardenerv1beta.Kubernetes{
Version: getKubernetesVersion(kubernetes),
KubeAPIServer: &gardenerv1beta.KubeAPIServerConfig{
OIDCConfig: getOIDCConfig(kubernetes.KubeAPIServer.OidcConfig),
},
return Converter{
extenders: extenders,
}
}

func getKubernetesVersion(kubernetes imv1.Kubernetes) string {
if kubernetes.Version != nil {
return *kubernetes.Version
}

// Determine the default Kubernetes version
// it must be read from the configuration (please refer to KEB)
return ""
}
func (c Converter) ToShoot(runtime imv1.Runtime) (gardener.Shoot, error) {
// The original implementation in the Provisioner: https://github.com/kyma-project/control-plane/blob/3dd257826747384479986d5d79eb20f847741aa6/components/provisioner/internal/model/gardener_config.go#L127
// Note: shoot.Spec.ExposureClassNames field is ignored as KEB didn't send this field to the Provisioner

func getOIDCConfig(oidcConfig gardenerv1beta.OIDCConfig) *gardenerv1beta.OIDCConfig {
return &gardenerv1beta.OIDCConfig{
CABundle: oidcConfig.CABundle,
ClientID: oidcConfig.ClientID,
GroupsClaim: oidcConfig.GroupsClaim,
GroupsPrefix: oidcConfig.GroupsPrefix,
IssuerURL: oidcConfig.IssuerURL,
RequiredClaims: oidcConfig.RequiredClaims,
SigningAlgs: oidcConfig.SigningAlgs,
UsernameClaim: oidcConfig.UsernameClaim,
UsernamePrefix: oidcConfig.UsernamePrefix,
shoot := gardener.Shoot{
ObjectMeta: v1.ObjectMeta{
Name: runtime.Spec.Shoot.Name,
Namespace: runtime.Namespace,
},
Spec: gardener.ShootSpec{
Purpose: &runtime.Spec.Shoot.Purpose,
Region: runtime.Spec.Shoot.Region,
SecretBindingName: &runtime.Spec.Shoot.SecretBindingName,
ControlPlane: &runtime.Spec.Shoot.ControlPlane,
},
}
}

func getProvider(runtimeProvider imv1.Provider) gardenerv1beta.Provider {
return gardenerv1beta.Provider{
Type: runtimeProvider.Type,
ControlPlaneConfig: &runtimeProvider.ControlPlaneConfig,
InfrastructureConfig: &runtimeProvider.InfrastructureConfig,
Workers: runtimeProvider.Workers,
for _, extend := range c.extenders {
if err := extend(runtime.Spec.Shoot, &shoot); err != nil {
return gardener.Shoot{}, err
}
}
}

func getNetworking(runtimeNetworking imv1.Networking) *gardenerv1beta.Networking {
return &gardenerv1beta.Networking{
Nodes: &runtimeNetworking.Nodes,
Pods: &runtimeNetworking.Pods,
Services: &runtimeNetworking.Services,
}
return shoot, nil
}
104 changes: 104 additions & 0 deletions internal/gardener/shoot/converter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package shoot

import (
"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"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestConverter(t *testing.T) {
t.Run("Create shoot from Runtime", func(t *testing.T) {
// given
runtime := fixRuntime()
converterConfig := fixConverterConfig()
converter := NewConverter(converterConfig)

// when
shoot, err := converter.ToShoot(runtime)

// then
require.NoError(t, err)
assert.Equal(t, runtime.Spec.Shoot.Purpose, *shoot.Spec.Purpose)
assert.Equal(t, runtime.Spec.Shoot.Region, shoot.Spec.Region)
assert.Equal(t, runtime.Spec.Shoot.SecretBindingName, *shoot.Spec.SecretBindingName)
assert.Equal(t, runtime.Spec.Shoot.ControlPlane, *shoot.Spec.ControlPlane)
})
}

func fixConverterConfig() ConverterConfig {
return ConverterConfig{
DefaultKubernetesVersion: "1.29",
DNSSecretName: "dns-secret",
DomainPrefix: "dev.mydomain.com",
}
}

func fixRuntime() imv1.Runtime {
kubernetesVersion := "1.28"
clientID := "client-id"
groupsClaim := "groups"
issuerURL := "https://my.cool.tokens.com"
usernameClaim := "sub"

return imv1.Runtime{
ObjectMeta: v1.ObjectMeta{
Name: "runtime",
Namespace: "kcp-system",
},
Spec: imv1.RuntimeSpec{
Shoot: imv1.RuntimeShoot{
Purpose: "production",
Region: "eu-central-1",
SecretBindingName: "my-secret",
Provider: imv1.Provider{
Type: "aws",
Workers: []gardener.Worker{
{
Name: "worker",
Machine: gardener.Machine{
Type: "m6i.large",
},
Minimum: 1,
Maximum: 3,
Zones: []string{
"eu-central-1a",
"eu-central-1b",
"eu-central-1c",
},
},
},
},
Kubernetes: imv1.Kubernetes{
Version: &kubernetesVersion,
KubeAPIServer: imv1.APIServer{
OidcConfig: gardener.OIDCConfig{
ClientID: &clientID,
GroupsClaim: &groupsClaim,
IssuerURL: &issuerURL,
SigningAlgs: []string{
"RS256",
},
UsernameClaim: &usernameClaim,
},
},
},
Networking: imv1.Networking{
Pods: "100.64.0.0/12",
Nodes: "10.250.0.0/16",
Services: "100.104.0.0/13",
},
ControlPlane: gardener.ControlPlane{
HighAvailability: &gardener.HighAvailability{
FailureTolerance: gardener.FailureTolerance{
Type: gardener.FailureToleranceTypeZone,
},
},
},
},
},
}
}
10 changes: 10 additions & 0 deletions internal/gardener/shoot/extender/annotations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package extender

import (
gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"
imv1 "github.com/kyma-project/infrastructure-manager/api/v1"
)

func ExtendWithAnnotations(imv1.RuntimeShoot, *gardener.Shoot) error {
return nil
}
Loading

0 comments on commit cdbbdaf

Please sign in to comment.