github.com/kotalco/kotal@v0.3.0/apis/polkadot/v1alpha1/node_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-polkadot-kotal-io-v1alpha1-node,mutating=true,failurePolicy=fail,groups=polkadot.kotal.io,resources=nodes,verbs=create;update,versions=v1alpha1,name=mutate-polkadot-v1alpha1-node.kb.io,sideEffects=None,admissionReviewVersions=v1 8 9 var _ webhook.Defaulter = &Node{} 10 11 func (r *Node) DefaultNodeResources() { 12 if r.Spec.Resources.CPU == "" { 13 r.Spec.Resources.CPU = DefaultNodeCPURequest 14 } 15 16 if r.Spec.Resources.CPULimit == "" { 17 r.Spec.Resources.CPULimit = DefaultNodeCPULimit 18 } 19 20 if r.Spec.Resources.Memory == "" { 21 r.Spec.Resources.Memory = DefaultNodeMemoryRequest 22 } 23 24 if r.Spec.Resources.MemoryLimit == "" { 25 r.Spec.Resources.MemoryLimit = DefaultNodeMemoryLimit 26 } 27 28 if r.Spec.Resources.Storage == "" { 29 r.Spec.Resources.Storage = DefaultNodeStorageRequest 30 } 31 } 32 33 // Default implements webhook.Defaulter so a webhook will be registered for the type 34 func (r *Node) Default() { 35 nodelog.Info("default", "name", r.Name) 36 37 r.DefaultNodeResources() 38 39 if r.Spec.Image == "" { 40 r.Spec.Image = DefaultPolkadotImage 41 } 42 43 if r.Spec.Replicas == nil { 44 // constants are not addressable 45 replicas := DefaltReplicas 46 r.Spec.Replicas = &replicas 47 } 48 49 if r.Spec.SyncMode == "" { 50 r.Spec.SyncMode = DefaultSyncMode 51 } 52 53 if r.Spec.P2PPort == 0 { 54 r.Spec.P2PPort = DefaultP2PPort 55 } 56 57 if r.Spec.Pruning == nil { 58 t := true 59 r.Spec.Pruning = &t 60 } 61 62 if r.Spec.Database == "" { 63 r.Spec.Database = DefaultDatabaseBackend 64 } 65 66 if r.Spec.RetainedBlocks == 0 { 67 r.Spec.RetainedBlocks = DefaultRetainedBlocks 68 } 69 70 if r.Spec.Logging == "" { 71 r.Spec.Logging = DefaultLoggingVerbosity 72 } 73 74 if r.Spec.RPCPort == 0 { 75 r.Spec.RPCPort = DefaultRPCPort 76 } 77 78 if r.Spec.WSPort == 0 { 79 r.Spec.WSPort = DefaultWSPort 80 } 81 82 if len(r.Spec.CORSDomains) == 0 { 83 r.Spec.CORSDomains = []string{DefaultCORSDomain} 84 } 85 86 if r.Spec.TelemetryURL == "" { 87 r.Spec.TelemetryURL = DefaultTelemetryURL 88 } 89 90 if r.Spec.PrometheusPort == 0 { 91 r.Spec.PrometheusPort = DefaultPrometheusPort 92 } 93 94 }