github.com/kotalco/kotal@v0.3.0/apis/ipfs/v1alpha1/peer_defaulting_webhook.go (about) 1 package v1alpha1 2 3 import "sigs.k8s.io/controller-runtime/pkg/webhook" 4 5 // +kubebuilder:webhook:path=/mutate-ipfs-kotal-io-v1alpha1-peer,mutating=true,failurePolicy=fail,groups=ipfs.kotal.io,resources=peers,verbs=create;update,versions=v1alpha1,name=mutate-ipfs-v1alpha1-peer.kb.io,sideEffects=None,admissionReviewVersions=v1 6 7 var _ webhook.Defaulter = &Peer{} 8 9 // DefaultPeerResources defaults peer resources 10 func (r *Peer) DefaultPeerResources() { 11 if r.Spec.Resources.CPU == "" { 12 r.Spec.Resources.CPU = DefaultNodeCPURequest 13 } 14 15 if r.Spec.Resources.CPULimit == "" { 16 r.Spec.Resources.CPULimit = DefaultNodeCPULimit 17 } 18 19 if r.Spec.Resources.Memory == "" { 20 r.Spec.Resources.Memory = DefaultNodeMemoryRequest 21 } 22 23 if r.Spec.Resources.MemoryLimit == "" { 24 r.Spec.Resources.MemoryLimit = DefaultNodeMemoryLimit 25 } 26 27 if r.Spec.Resources.Storage == "" { 28 r.Spec.Resources.Storage = DefaultNodeStorageRequest 29 } 30 } 31 32 // Default implements webhook.Defaulter so a webhook will be registered for the type 33 func (r *Peer) Default() { 34 peerlog.Info("default", "name", r.Name) 35 36 if r.Spec.Image == "" { 37 r.Spec.Image = DefaultGoIPFSImage 38 } 39 40 if r.Spec.Replicas == nil { 41 // constants are not addressable 42 replicas := DefaltReplicas 43 r.Spec.Replicas = &replicas 44 } 45 46 if r.Spec.Routing == "" { 47 r.Spec.Routing = DefaultRoutingMode 48 } 49 50 if r.Spec.APIPort == 0 { 51 r.Spec.APIPort = DefaultAPIPort 52 } 53 54 if r.Spec.GatewayPort == 0 { 55 r.Spec.GatewayPort = DefaultGatewayPort 56 } 57 58 if len(r.Spec.InitProfiles) == 0 { 59 r.Spec.InitProfiles = []Profile{DefaultDatastoreProfile} 60 } 61 62 if r.Spec.Logging == "" { 63 r.Spec.Logging = DefaultLogging 64 } 65 66 r.DefaultPeerResources() 67 68 }