Skip to content

Commit

Permalink
[Gardenlet] Clean up technical debt in defaulting code (gardener#8985)
Browse files Browse the repository at this point in the history
* Unit test overall defaulting function

* Refactor defaulting to SetDefaults_* functions

* Restructure and add missing unit tests

* Cleanup and restructure defaulting

* Fix failing test

* Address PR review feedback
  • Loading branch information
ary1992 authored Dec 29, 2023
1 parent 0f7ea37 commit d6d240a
Show file tree
Hide file tree
Showing 5 changed files with 741 additions and 310 deletions.
107 changes: 61 additions & 46 deletions pkg/gardenlet/apis/config/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@ import (
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1"
"k8s.io/utils/pointer"

v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
)

func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}

// SetDefaults_GardenletConfiguration sets defaults for the configuration of the Gardenlet.
func SetDefaults_GardenletConfiguration(obj *GardenletConfiguration) {
if obj.GardenClientConnection == nil {
Expand Down Expand Up @@ -60,20 +55,6 @@ func SetDefaults_GardenletConfiguration(obj *GardenletConfiguration) {
obj.LogFormat = LogFormatJSON
}

if obj.Server.HealthProbes == nil {
obj.Server.HealthProbes = &Server{}
}
if obj.Server.HealthProbes.Port == 0 {
obj.Server.HealthProbes.Port = 2728
}

if obj.Server.Metrics == nil {
obj.Server.Metrics = &Server{}
}
if obj.Server.Metrics.Port == 0 {
obj.Server.Metrics.Port = 2729
}

if obj.Logging == nil {
obj.Logging = &Logging{}
}
Expand All @@ -92,23 +73,45 @@ func SetDefaults_GardenletConfiguration(obj *GardenletConfiguration) {
obj.ETCDConfig = &ETCDConfig{}
}

SetDefaults_ExposureClassHandler(obj.ExposureClassHandlers)
}

// SetDefaults_ServerConfiguration sets defaults for the configuration of the HTTP server.
func SetDefaults_ServerConfiguration(obj *ServerConfiguration) {
if obj.HealthProbes == nil {
obj.HealthProbes = &Server{}
}
if obj.HealthProbes.Port == 0 {
obj.HealthProbes.Port = 2728
}

if obj.Metrics == nil {
obj.Metrics = &Server{}
}
if obj.Metrics.Port == 0 {
obj.Metrics.Port = 2729
}
}

// SetDefaults_ExposureClassHandler sets defaults for the configuration for an exposure class handler.
func SetDefaults_ExposureClassHandler(obj []ExposureClassHandler) {
var defaultSVCName = v1beta1constants.DefaultSNIIngressServiceName
for i, handler := range obj.ExposureClassHandlers {
if obj.ExposureClassHandlers[i].SNI == nil {
obj.ExposureClassHandlers[i].SNI = &SNI{Ingress: &SNIIngress{}}
for i, handler := range obj {
if obj[i].SNI == nil {
obj[i].SNI = &SNI{Ingress: &SNIIngress{}}
}
if obj.ExposureClassHandlers[i].SNI.Ingress == nil {
obj.ExposureClassHandlers[i].SNI.Ingress = &SNIIngress{}
if obj[i].SNI.Ingress == nil {
obj[i].SNI.Ingress = &SNIIngress{}
}
if obj.ExposureClassHandlers[i].SNI.Ingress.Namespace == nil {
if obj[i].SNI.Ingress.Namespace == nil {
namespaceName := fmt.Sprintf("istio-ingress-handler-%s", handler.Name)
obj.ExposureClassHandlers[i].SNI.Ingress.Namespace = &namespaceName
obj[i].SNI.Ingress.Namespace = &namespaceName
}
if obj.ExposureClassHandlers[i].SNI.Ingress.ServiceName == nil {
obj.ExposureClassHandlers[i].SNI.Ingress.ServiceName = &defaultSVCName
if obj[i].SNI.Ingress.ServiceName == nil {
obj[i].SNI.Ingress.ServiceName = &defaultSVCName
}
if len(obj.ExposureClassHandlers[i].SNI.Ingress.Labels) == 0 {
obj.ExposureClassHandlers[i].SNI.Ingress.Labels = map[string]string{
if len(obj[i].SNI.Ingress.Labels) == 0 {
obj[i].SNI.Ingress.Labels = map[string]string{
v1beta1constants.LabelApp: v1beta1constants.DefaultIngressGatewayAppLabelValue,
v1beta1constants.GardenRole: v1beta1constants.GardenRoleExposureClassHandler,
}
Expand Down Expand Up @@ -243,7 +246,7 @@ func SetDefaults_ShootMonitoringConfig(obj *ShootMonitoringConfig) {
}
}

// SetDefaults_BastionControllerConfiguration sets defaults for the backup bucket controller.
// SetDefaults_BastionControllerConfiguration sets defaults for the bastion controller.
func SetDefaults_BastionControllerConfiguration(obj *BastionControllerConfiguration) {
if obj.ConcurrentSyncs == nil {
v := DefaultControllerConcurrentSyncs
Expand Down Expand Up @@ -364,7 +367,7 @@ func SetDefaults_StaleExtensionHealthChecks(obj *StaleExtensionHealthChecks) {
}
}

// SetDefaults_ShootStateControllerConfiguration sets defaults for the shoot secret controller.
// SetDefaults_ShootStateControllerConfiguration sets defaults for the shoot state controller.
func SetDefaults_ShootStateControllerConfiguration(obj *ShootStateControllerConfiguration) {
if obj.ConcurrentSyncs == nil {
obj.ConcurrentSyncs = pointer.Int(5)
Expand Down Expand Up @@ -476,28 +479,40 @@ func SetDefaults_ETCDConfig(obj *ETCDConfig) {
if obj.ETCDController == nil {
obj.ETCDController = &ETCDController{}
}
if obj.ETCDController.Workers == nil {
obj.ETCDController.Workers = pointer.Int64(50)
}
if obj.CustodianController == nil {
obj.CustodianController = &CustodianController{}
}
if obj.CustodianController.Workers == nil {
obj.CustodianController.Workers = pointer.Int64(10)
}
if obj.BackupCompactionController == nil {
obj.BackupCompactionController = &BackupCompactionController{}
}
if obj.BackupCompactionController.Workers == nil {
obj.BackupCompactionController.Workers = pointer.Int64(3)
}

// SetDefaults_ETCDController sets defaults for the ETCD controller.
func SetDefaults_ETCDController(obj *ETCDController) {
if obj.Workers == nil {
obj.Workers = pointer.Int64(50)
}
}

// SetDefaults_CustodianController sets defaults for the ETCD custodian controller.
func SetDefaults_CustodianController(obj *CustodianController) {
if obj.Workers == nil {
obj.Workers = pointer.Int64(10)
}
}

// SetDefaults_BackupCompactionController sets defaults for the ETCD backup compaction controller.
func SetDefaults_BackupCompactionController(obj *BackupCompactionController) {
if obj.Workers == nil {
obj.Workers = pointer.Int64(3)
}
if obj.BackupCompactionController.EnableBackupCompaction == nil {
obj.BackupCompactionController.EnableBackupCompaction = pointer.Bool(false)
if obj.EnableBackupCompaction == nil {
obj.EnableBackupCompaction = pointer.Bool(false)
}
if obj.BackupCompactionController.EventsThreshold == nil {
obj.BackupCompactionController.EventsThreshold = pointer.Int64(1000000)
if obj.EventsThreshold == nil {
obj.EventsThreshold = pointer.Int64(1000000)
}
if obj.BackupCompactionController.MetricsScrapeWaitDuration == nil {
obj.BackupCompactionController.MetricsScrapeWaitDuration = &metav1.Duration{Duration: 60 * time.Second}
if obj.MetricsScrapeWaitDuration == nil {
obj.MetricsScrapeWaitDuration = &metav1.Duration{Duration: 60 * time.Second}
}
}
Loading

0 comments on commit d6d240a

Please sign in to comment.