github.com/kotalco/kotal@v0.3.0/apis/chainlink/v1alpha1/node_defaulting_webhook.go (about)

     1  package v1alpha1
     2  
     3  import (
     4  	"github.com/kotalco/kotal/apis/shared"
     5  	"sigs.k8s.io/controller-runtime/pkg/webhook"
     6  )
     7  
     8  // +kubebuilder:webhook:path=/mutate-chainlink-kotal-io-v1alpha1-node,mutating=true,failurePolicy=fail,groups=chainlink.kotal.io,resources=nodes,verbs=create;update,versions=v1alpha1,name=mutate-chainlink-v1alpha1-node.kb.io,sideEffects=None,admissionReviewVersions=v1
     9  
    10  var _ webhook.Defaulter = &Node{}
    11  
    12  // Default implements webhook.Defaulter so a webhook will be registered for the type
    13  func (r *Node) Default() {
    14  	nodelog.Info("default", "name", r.Name)
    15  
    16  	if r.Spec.Image == "" {
    17  		r.Spec.Image = DefaultChainlinkImage
    18  	}
    19  
    20  	if r.Spec.Replicas == nil {
    21  		// constants are not addressable
    22  		replicas := DefaltReplicas
    23  		r.Spec.Replicas = &replicas
    24  	}
    25  
    26  	if r.Spec.P2PPort == 0 {
    27  		r.Spec.P2PPort = DefaultP2PPort
    28  	}
    29  
    30  	if r.Spec.APIPort == 0 {
    31  		r.Spec.APIPort = DefaultAPIPort
    32  	}
    33  
    34  	if r.Spec.CPU == "" {
    35  		r.Spec.CPU = DefaultNodeCPURequest
    36  	}
    37  
    38  	if r.Spec.CPULimit == "" {
    39  		r.Spec.CPULimit = DefaultNodeCPULimit
    40  	}
    41  
    42  	if r.Spec.Memory == "" {
    43  		r.Spec.Memory = DefaultNodeMemoryRequest
    44  	}
    45  
    46  	if r.Spec.MemoryLimit == "" {
    47  		r.Spec.MemoryLimit = DefaultNodeMemoryLimit
    48  	}
    49  
    50  	if r.Spec.Storage == "" {
    51  		r.Spec.Storage = DefaultNodeStorageRequest
    52  	}
    53  
    54  	if r.Spec.TLSPort == 0 {
    55  		r.Spec.TLSPort = DefaultTLSPort
    56  	}
    57  
    58  	if r.Spec.Logging == "" {
    59  		r.Spec.Logging = shared.InfoLogs
    60  	}
    61  
    62  	if len(r.Spec.CORSDomains) == 0 {
    63  		r.Spec.CORSDomains = DefaultCorsDomains
    64  	}
    65  
    66  }