github.com/kotalco/kotal@v0.3.0/apis/ethereum2/v1alpha1/validator_defaulting_webhook.go (about)

     1  package v1alpha1
     2  
     3  import (
     4  	"sigs.k8s.io/controller-runtime/pkg/webhook"
     5  )
     6  
     7  // +kubebuilder:webhook:path=/mutate-ethereum2-kotal-io-v1alpha1-validator,mutating=true,failurePolicy=fail,groups=ethereum2.kotal.io,resources=validators,verbs=create;update,versions=v1alpha1,name=mutate-ethereum2-v1alpha1-validator.kb.io,sideEffects=None,admissionReviewVersions=v1
     8  
     9  var _ webhook.Defaulter = &Validator{}
    10  
    11  // Default implements webhook.Defaulter so a webhook will be registered for the type
    12  func (r *Validator) Default() {
    13  	validatorlog.Info("default", "name", r.Name)
    14  
    15  	if r.Spec.Graffiti == "" {
    16  		r.Spec.Graffiti = DefaultGraffiti
    17  	}
    18  
    19  	if r.Spec.FeeRecipient == "" {
    20  		r.Spec.FeeRecipient = ZeroAddress
    21  	}
    22  
    23  	if r.Spec.Image == "" {
    24  		var image string
    25  
    26  		switch r.Spec.Client {
    27  		case TekuClient:
    28  			image = DefaultTekuValidatorImage
    29  		case LighthouseClient:
    30  			image = DefaultLighthouseValidatorImage
    31  		case NimbusClient:
    32  			image = DefaultNimbusValidatorImage
    33  		case PrysmClient:
    34  			image = DefaultPrysmValidatorImage
    35  		}
    36  
    37  		r.Spec.Image = image
    38  	}
    39  
    40  	if r.Spec.Replicas == nil {
    41  		// constants are not addressable
    42  		replicas := DefaltReplicas
    43  		r.Spec.Replicas = &replicas
    44  	}
    45  
    46  	r.DefaultNodeResources()
    47  
    48  }
    49  
    50  // DefaultNodeResources defaults Ethereum 2.0 validator client cpu, memory and storage resources
    51  func (r *Validator) DefaultNodeResources() {
    52  	if r.Spec.Resources.CPU == "" {
    53  		r.Spec.Resources.CPU = DefaultCPURequest
    54  	}
    55  
    56  	if r.Spec.Resources.CPULimit == "" {
    57  		r.Spec.Resources.CPULimit = DefaultCPULimit
    58  	}
    59  
    60  	if r.Spec.Resources.Memory == "" {
    61  		r.Spec.Resources.Memory = DefaultMemoryRequest
    62  	}
    63  
    64  	if r.Spec.Resources.MemoryLimit == "" {
    65  		r.Spec.Resources.MemoryLimit = DefaultMemoryLimit
    66  	}
    67  
    68  	if r.Spec.Resources.Storage == "" {
    69  		r.Spec.Resources.Storage = DefaultStorage
    70  	}
    71  
    72  	if r.Spec.Logging == "" {
    73  		r.Spec.Logging = DefaultLogging
    74  	}
    75  }