|
| 1 | +package config |
| 2 | + |
| 3 | +import ( |
| 4 | + "k8s.io/apimachinery/pkg/api/resource" |
| 5 | +) |
| 6 | + |
| 7 | +type ContainersResourceRequirements map[string]*ContainerResource |
| 8 | + |
| 9 | +// Resources mirrors trident/operator/crd/apis/netapp/v1/Resources exactly. |
| 10 | +// The duplication exists because Trident currently has no admission webhook to validate CRD fields. |
| 11 | +// TODO(pshashan): Remove or refactor this if an admission webhook is ever implemented. |
| 12 | +type Resources struct { |
| 13 | + Controller ContainersResourceRequirements `json:"controller,omitempty"` |
| 14 | + Node *NodeResources `json:"node,omitempty"` |
| 15 | +} |
| 16 | + |
| 17 | +type NodeResources struct { |
| 18 | + Linux ContainersResourceRequirements `json:"linux,omitempty"` |
| 19 | + Windows ContainersResourceRequirements `json:"windows,omitempty"` |
| 20 | +} |
| 21 | + |
| 22 | +type ContainerResource struct { |
| 23 | + Requests *ResourceRequirements `json:"requests,omitempty"` |
| 24 | + Limits *ResourceRequirements `json:"limits,omitempty"` |
| 25 | +} |
| 26 | + |
| 27 | +type ResourceRequirements struct { |
| 28 | + CPU *resource.Quantity `json:"cpu,omitempty"` |
| 29 | + Memory *resource.Quantity `json:"memory,omitempty"` |
| 30 | +} |
| 31 | + |
| 32 | +// These manual DeepCopy implementations are required because: |
| 33 | +// 1. The Resources types above are used in the operator CRD (trident/operator/crd/apis/netapp/v1/types.go) |
| 34 | +// 2. Kubernetes controller-gen requires DeepCopy methods for all types used in CRDs |
| 35 | +// 3. controller-gen only generates DeepCopy methods for types within the same package, not for imported types |
| 36 | +// 4. Since these types are defined in the config package but referenced by the operator CRD package, |
| 37 | +// controller-gen cannot auto-generate DeepCopy methods for them in the operator package |
| 38 | + |
| 39 | +// DeepCopyInto creates a deep copy of the receiver, writing into out. |
| 40 | +func (in ContainersResourceRequirements) DeepCopyInto(out *ContainersResourceRequirements) { |
| 41 | + { |
| 42 | + in := &in |
| 43 | + *out = make(ContainersResourceRequirements, len(*in)) |
| 44 | + for key, val := range *in { |
| 45 | + var outVal *ContainerResource |
| 46 | + if val == nil { |
| 47 | + (*out)[key] = nil |
| 48 | + } else { |
| 49 | + in, out := &val, &outVal |
| 50 | + *out = new(ContainerResource) |
| 51 | + (*in).DeepCopyInto(*out) |
| 52 | + } |
| 53 | + (*out)[key] = outVal |
| 54 | + } |
| 55 | + return |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +// DeepCopy creates a deep copy of the receiver. |
| 60 | +func (in ContainersResourceRequirements) DeepCopy() ContainersResourceRequirements { |
| 61 | + if in == nil { |
| 62 | + return nil |
| 63 | + } |
| 64 | + out := new(ContainersResourceRequirements) |
| 65 | + in.DeepCopyInto(out) |
| 66 | + return *out |
| 67 | +} |
| 68 | + |
| 69 | +// DeepCopyInto creates a deep copy of the receiver, writing into out. |
| 70 | +func (in *Resources) DeepCopyInto(out *Resources) { |
| 71 | + *out = *in |
| 72 | + if in.Controller != nil { |
| 73 | + in, out := &in.Controller, &out.Controller |
| 74 | + (*in).DeepCopyInto(out) |
| 75 | + } |
| 76 | + if in.Node != nil { |
| 77 | + in, out := &in.Node, &out.Node |
| 78 | + *out = new(NodeResources) |
| 79 | + (*in).DeepCopyInto(*out) |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +// DeepCopy creates a deep copy of the receiver. |
| 84 | +func (in *Resources) DeepCopy() *Resources { |
| 85 | + if in == nil { |
| 86 | + return nil |
| 87 | + } |
| 88 | + out := new(Resources) |
| 89 | + in.DeepCopyInto(out) |
| 90 | + return out |
| 91 | +} |
| 92 | + |
| 93 | +// DeepCopyInto creates a deep copy of the receiver, writing into out. |
| 94 | +func (in *NodeResources) DeepCopyInto(out *NodeResources) { |
| 95 | + *out = *in |
| 96 | + if in.Linux != nil { |
| 97 | + in, out := &in.Linux, &out.Linux |
| 98 | + (*in).DeepCopyInto(out) |
| 99 | + } |
| 100 | + if in.Windows != nil { |
| 101 | + in, out := &in.Windows, &out.Windows |
| 102 | + (*in).DeepCopyInto(out) |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +// DeepCopy creates a deep copy of the receiver. |
| 107 | +func (in *NodeResources) DeepCopy() *NodeResources { |
| 108 | + if in == nil { |
| 109 | + return nil |
| 110 | + } |
| 111 | + out := new(NodeResources) |
| 112 | + in.DeepCopyInto(out) |
| 113 | + return out |
| 114 | +} |
| 115 | + |
| 116 | +// DeepCopyInto creates a deep copy of the receiver, writing into out. |
| 117 | +func (in *ContainerResource) DeepCopyInto(out *ContainerResource) { |
| 118 | + *out = *in |
| 119 | + if in.Requests != nil { |
| 120 | + in, out := &in.Requests, &out.Requests |
| 121 | + *out = new(ResourceRequirements) |
| 122 | + (*in).DeepCopyInto(*out) |
| 123 | + } |
| 124 | + if in.Limits != nil { |
| 125 | + in, out := &in.Limits, &out.Limits |
| 126 | + *out = new(ResourceRequirements) |
| 127 | + (*in).DeepCopyInto(*out) |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +// DeepCopy creates a deep copy of the receiver. |
| 132 | +func (in *ContainerResource) DeepCopy() *ContainerResource { |
| 133 | + if in == nil { |
| 134 | + return nil |
| 135 | + } |
| 136 | + out := new(ContainerResource) |
| 137 | + in.DeepCopyInto(out) |
| 138 | + return out |
| 139 | +} |
| 140 | + |
| 141 | +// DeepCopyInto creates a deep copy of the receiver, writing into out. |
| 142 | +func (in *ResourceRequirements) DeepCopyInto(out *ResourceRequirements) { |
| 143 | + *out = *in |
| 144 | + if in.CPU != nil { |
| 145 | + in, out := &in.CPU, &out.CPU |
| 146 | + x := (*in).DeepCopy() |
| 147 | + *out = &x |
| 148 | + } |
| 149 | + if in.Memory != nil { |
| 150 | + in, out := &in.Memory, &out.Memory |
| 151 | + x := (*in).DeepCopy() |
| 152 | + *out = &x |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +// DeepCopy creates a deep copy of the receiver. |
| 157 | +func (in *ResourceRequirements) DeepCopy() *ResourceRequirements { |
| 158 | + if in == nil { |
| 159 | + return nil |
| 160 | + } |
| 161 | + out := new(ResourceRequirements) |
| 162 | + in.DeepCopyInto(out) |
| 163 | + return out |
| 164 | +} |
0 commit comments