@@ -19,10 +19,8 @@ package v1alpha1
1919import (
2020 corev1 "k8s.io/api/core/v1"
2121 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22- clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
23-
2422 "k8s.io/utils/ptr"
25- ipamicv1 "sigs.k8s.io/cluster-api-ipam-provider-in-cluster /api/v1alpha2 "
23+ clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1 "
2624)
2725
2826const (
@@ -50,25 +48,49 @@ type ProxmoxClusterSpec struct {
5048 // +optional
5149 SchedulerHints * SchedulerHints `json:"schedulerHints,omitempty"`
5250
51+ ClusterNetworkConfig `json:",inline"`
52+ }
53+
54+ // ClusterNetworkConfig represents information about the cluster network configuration.
55+ type ClusterNetworkConfig struct {
5356 // IPv4Config contains information about available IPV4 address pools and the gateway.
54- // this can be combined with ipv6Config in order to enable dual stack.
57+ // this can be combined with ipv6Config to enable dual stack.
5558 // either IPv4Config or IPv6Config must be provided.
5659 // +optional
57- // +kubebuilder:validation:XValidation:rule="self.addresses.size() > 0",message="IPv4Config addresses must be provided"
58- IPv4Config * ipamicv1.InClusterIPPoolSpec `json:"ipv4Config,omitempty"`
60+ IPv4Config * IPConfig `json:"ipv4Config,omitempty"`
5961
6062 // IPv6Config contains information about available IPV6 address pools and the gateway.
61- // this can be combined with ipv4Config in order to enable dual stack.
63+ // this can be combined with ipv4Config to enable dual stack.
6264 // either IPv4Config or IPv6Config must be provided.
6365 // +optional
64- // +kubebuilder:validation:XValidation:rule="self.addresses.size() > 0",message="IPv6Config addresses must be provided"
65- IPv6Config * ipamicv1.InClusterIPPoolSpec `json:"ipv6Config,omitempty"`
66+ IPv6Config * IPConfig `json:"ipv6Config,omitempty"`
6667
6768 // DNSServers contains information about nameservers used by machines network-config.
6869 // +kubebuilder:validation:MinItems=1
6970 DNSServers []string `json:"dnsServers"`
7071}
7172
73+ // IPConfig contains information about available IP config.
74+ type IPConfig struct {
75+ // Addresses is a list of IP addresses that can be assigned. This set of
76+ // addresses can be non-contiguous.
77+ // +kubebuilder:validation:MinItems=1
78+ Addresses []string `json:"addresses,omitempty"`
79+
80+ // Prefix is the network prefix to use.
81+ // +kubebuilder:validation:Maximum=128
82+ // +optional
83+ Prefix int `json:"prefix,omitempty"`
84+
85+ // Gateway
86+ // +optional
87+ Gateway string `json:"gateway,omitempty"`
88+
89+ // DHCP indicates if DHCP should be used to assign IP addresses.
90+ // +optional
91+ DHCP bool `json:"dhcp,omitempty"`
92+ }
93+
7294// SchedulerHints allows to pass the scheduler instructions to (dis)allow over- or enforce underprovisioning of resources.
7395type SchedulerHints struct {
7496 // MemoryAdjustment allows to adjust a node's memory by a given percentage.
@@ -170,141 +192,6 @@ func (c *ProxmoxCluster) SetConditions(conditions clusterv1.Conditions) {
170192 c .Status .Conditions = conditions
171193}
172194
173- // SetInClusterIPPoolRef will set the reference to the provided InClusterIPPool.
174- // If nil was provided, the status field will be cleared.
175- func (c * ProxmoxCluster ) SetInClusterIPPoolRef (pool * ipamicv1.InClusterIPPool ) {
176- if pool == nil || pool .GetName () == "" {
177- c .Status .InClusterIPPoolRef = nil
178- return
179- }
180-
181- if c .Status .InClusterIPPoolRef == nil {
182- c .Status .InClusterIPPoolRef = []corev1.LocalObjectReference {
183- {Name : pool .GetName ()},
184- }
185- }
186-
187- found := false
188- for _ , ref := range c .Status .InClusterIPPoolRef {
189- if ref .Name == pool .GetName () {
190- found = true
191- }
192- }
193- if ! found {
194- c .Status .InClusterIPPoolRef = append (c .Status .InClusterIPPoolRef , corev1.LocalObjectReference {Name : pool .GetName ()})
195- }
196- }
197-
198- // AddNodeLocation will add a node location to either the control plane or worker
199- // node locations based on the `isControlPlane` parameter.
200- func (c * ProxmoxCluster ) AddNodeLocation (loc NodeLocation , isControlPlane bool ) {
201- if c .Status .NodeLocations == nil {
202- c .Status .NodeLocations = new (NodeLocations )
203- }
204-
205- if ! c .HasMachine (loc .Machine .Name , isControlPlane ) {
206- c .addNodeLocation (loc , isControlPlane )
207- }
208- }
209-
210- // RemoveNodeLocation removes a node location from the status.
211- func (c * ProxmoxCluster ) RemoveNodeLocation (machineName string , isControlPlane bool ) {
212- nodeLocations := c .Status .NodeLocations
213-
214- if nodeLocations == nil {
215- return
216- }
217-
218- if ! c .HasMachine (machineName , isControlPlane ) {
219- return
220- }
221-
222- if isControlPlane {
223- for i , v := range nodeLocations .ControlPlane {
224- if v .Machine .Name == machineName {
225- nodeLocations .ControlPlane = append (nodeLocations .ControlPlane [:i ], nodeLocations .ControlPlane [i + 1 :]... )
226- }
227- }
228- return
229- }
230-
231- for i , v := range nodeLocations .Workers {
232- if v .Machine .Name == machineName {
233- nodeLocations .Workers = append (nodeLocations .Workers [:i ], nodeLocations .Workers [i + 1 :]... )
234- }
235- }
236- }
237-
238- // UpdateNodeLocation will update the node location based on the provided machine name.
239- // If the node location does not exist, it will be added.
240- //
241- // The function returns true if the value was added or updated, otherwise false.
242- func (c * ProxmoxCluster ) UpdateNodeLocation (machineName , node string , isControlPlane bool ) bool {
243- if ! c .HasMachine (machineName , isControlPlane ) {
244- loc := NodeLocation {
245- Node : node ,
246- Machine : corev1.LocalObjectReference {Name : machineName },
247- }
248- c .AddNodeLocation (loc , isControlPlane )
249- return true
250- }
251-
252- locations := c .Status .NodeLocations .Workers
253- if isControlPlane {
254- locations = c .Status .NodeLocations .ControlPlane
255- }
256-
257- for i , loc := range locations {
258- if loc .Machine .Name == machineName {
259- if loc .Node != node {
260- locations [i ].Node = node
261- return true
262- }
263-
264- return false
265- }
266- }
267-
268- return false
269- }
270-
271- // HasMachine returns if true if a machine was found on any node.
272- func (c * ProxmoxCluster ) HasMachine (machineName string , isControlPlane bool ) bool {
273- return c .GetNode (machineName , isControlPlane ) != ""
274- }
275-
276- // GetNode tries to return the Proxmox node for the provided machine name.
277- func (c * ProxmoxCluster ) GetNode (machineName string , isControlPlane bool ) string {
278- if c .Status .NodeLocations == nil {
279- return ""
280- }
281-
282- if isControlPlane {
283- for _ , cpl := range c .Status .NodeLocations .ControlPlane {
284- if cpl .Machine .Name == machineName {
285- return cpl .Node
286- }
287- }
288- } else {
289- for _ , wloc := range c .Status .NodeLocations .Workers {
290- if wloc .Machine .Name == machineName {
291- return wloc .Node
292- }
293- }
294- }
295-
296- return ""
297- }
298-
299- func (c * ProxmoxCluster ) addNodeLocation (loc NodeLocation , isControlPlane bool ) {
300- if isControlPlane {
301- c .Status .NodeLocations .ControlPlane = append (c .Status .NodeLocations .ControlPlane , loc )
302- return
303- }
304-
305- c .Status .NodeLocations .Workers = append (c .Status .NodeLocations .Workers , loc )
306- }
307-
308195func init () {
309196 SchemeBuilder .Register (& ProxmoxCluster {}, & ProxmoxClusterList {})
310197}
0 commit comments