forked from kyma-project/infrastructure-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into shoot-comparison
- Loading branch information
Showing
20 changed files
with
620 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.