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

     1  package v1alpha1
     2  
     3  import "sigs.k8s.io/controller-runtime/pkg/webhook"
     4  
     5  // +kubebuilder:webhook:path=/mutate-ethereum2-kotal-io-v1alpha1-beaconnode,mutating=true,failurePolicy=fail,groups=ethereum2.kotal.io,resources=beaconnodes,verbs=create;update,versions=v1alpha1,name=mutate-ethereum2-v1alpha1-beaconnode.kb.io,sideEffects=None,admissionReviewVersions=v1
     6  
     7  var _ webhook.Defaulter = &BeaconNode{}
     8  
     9  // Default implements webhook.Defaulter so a webhook will be registered for the type
    10  func (r *BeaconNode) Default() {
    11  	nodelog.Info("default", "name", r.Name)
    12  
    13  	if r.Spec.Image == "" {
    14  		var image string
    15  
    16  		switch r.Spec.Client {
    17  		case TekuClient:
    18  			image = DefaultTekuBeaconNodeImage
    19  		case PrysmClient:
    20  			image = DefaultPrysmBeaconNodeImage
    21  		case NimbusClient:
    22  			image = DefaultNimbusBeaconNodeImage
    23  		case LighthouseClient:
    24  			image = DefaultLighthouseBeaconNodeImage
    25  		}
    26  
    27  		r.Spec.Image = image
    28  	}
    29  
    30  	if r.Spec.Replicas == nil {
    31  		// constants are not addressable
    32  		replicas := DefaltReplicas
    33  		r.Spec.Replicas = &replicas
    34  	}
    35  
    36  	if r.Spec.P2PPort == 0 {
    37  		r.Spec.P2PPort = DefaultP2PPort
    38  	}
    39  
    40  	if r.Spec.Logging == "" {
    41  		r.Spec.Logging = DefaultLogging
    42  	}
    43  
    44  	if r.Spec.RESTPort == 0 {
    45  		r.Spec.RESTPort = DefaultRestPort
    46  	}
    47  
    48  	if r.Spec.RPCPort == 0 {
    49  		r.Spec.RPCPort = DefaultRPCPort
    50  	}
    51  
    52  	if r.Spec.GRPCPort == 0 {
    53  		r.Spec.GRPCPort = DefaultGRPCPort
    54  	}
    55  
    56  	if len(r.Spec.CORSDomains) == 0 {
    57  		r.Spec.CORSDomains = DefaultOrigins
    58  	}
    59  	if len(r.Spec.Hosts) == 0 {
    60  		r.Spec.Hosts = DefaultOrigins
    61  	}
    62  
    63  	if r.Spec.FeeRecipient == "" {
    64  		r.Spec.FeeRecipient = ZeroAddress
    65  	}
    66  
    67  	r.DefaultNodeResources()
    68  
    69  }
    70  
    71  // DefaultNodeResources defaults Ethereum 2.0 node cpu, memory and storage resources
    72  func (r *BeaconNode) DefaultNodeResources() {
    73  	if r.Spec.Resources.CPU == "" {
    74  		r.Spec.Resources.CPU = DefaultCPURequest
    75  	}
    76  
    77  	if r.Spec.Resources.CPULimit == "" {
    78  		r.Spec.Resources.CPULimit = DefaultCPULimit
    79  	}
    80  
    81  	if r.Spec.Resources.Memory == "" {
    82  		r.Spec.Resources.Memory = DefaultMemoryRequest
    83  	}
    84  
    85  	if r.Spec.Resources.MemoryLimit == "" {
    86  		r.Spec.Resources.MemoryLimit = DefaultMemoryLimit
    87  	}
    88  
    89  	if r.Spec.Resources.Storage == "" {
    90  		r.Spec.Resources.Storage = DefaultStorage
    91  	}
    92  }