Skip to content

Commit

Permalink
Add KThreesConfig defaults
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Mazzotti <[email protected]>
  • Loading branch information
anmazzotti committed May 24, 2024
1 parent 07376f4 commit 7ca51bf
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion bootstrap/api/v1beta2/kthreesconfig_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ package v1beta2

import (
"context"
"fmt"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)
Expand Down Expand Up @@ -55,6 +58,18 @@ func (c *KThreesConfig) ValidateDelete(_ context.Context, _ runtime.Object) (adm
}

// Default will set default values for the KThreesConfig.
func (c *KThreesConfig) Default(_ context.Context, _ runtime.Object) error {
func (c *KThreesConfig) Default(_ context.Context, obj runtime.Object) error {
c, ok := obj.(*KThreesConfig)
if !ok {
return apierrors.NewBadRequest(fmt.Sprintf("expected a KThreesConfig but got a %T", obj))
}

if c.Spec.ServerConfig.DisableCloudController == nil {
c.Spec.ServerConfig.DisableCloudController = ptr.To(true)
}

if c.Spec.ServerConfig.CloudProviderName == nil {
c.Spec.ServerConfig.CloudProviderName = ptr.To("external")
}
return nil
}

0 comments on commit 7ca51bf

Please sign in to comment.