@@ -20,8 +20,6 @@ import (
2020 corev1 "k8s.io/api/core/v1"
2121 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
23-
24- ipamicv1 "sigs.k8s.io/cluster-api-ipam-provider-in-cluster/api/v1alpha2"
2523)
2624
2725const (
@@ -44,25 +42,49 @@ type ProxmoxClusterSpec struct {
4442 // +optional
4543 AllowedNodes []string `json:"allowedNodes,omitempty"`
4644
45+ ClusterNetworkConfig `json:",inline"`
46+ }
47+
48+ // ClusterNetworkConfig represents information about the cluster network configuration.
49+ type ClusterNetworkConfig struct {
4750 // IPv4Config contains information about available IPV4 address pools and the gateway.
48- // this can be combined with ipv6Config in order to enable dual stack.
51+ // this can be combined with ipv6Config to enable dual stack.
4952 // either IPv4Config or IPv6Config must be provided.
5053 // +optional
51- // +kubebuilder:validation:XValidation:rule="self.addresses.size() > 0",message="IPv4Config addresses must be provided"
52- IPv4Config * ipamicv1.InClusterIPPoolSpec `json:"ipv4Config,omitempty"`
54+ IPv4Config * IPConfig `json:"ipv4Config,omitempty"`
5355
5456 // IPv6Config contains information about available IPV6 address pools and the gateway.
55- // this can be combined with ipv4Config in order to enable dual stack.
57+ // this can be combined with ipv4Config to enable dual stack.
5658 // either IPv4Config or IPv6Config must be provided.
5759 // +optional
58- // +kubebuilder:validation:XValidation:rule="self.addresses.size() > 0",message="IPv6Config addresses must be provided"
59- IPv6Config * ipamicv1.InClusterIPPoolSpec `json:"ipv6Config,omitempty"`
60+ IPv6Config * IPConfig `json:"ipv6Config,omitempty"`
6061
6162 // DNSServers contains information about nameservers used by machines network-config.
6263 // +kubebuilder:validation:MinItems=1
6364 DNSServers []string `json:"dnsServers"`
6465}
6566
67+ // IPConfig contains information about available IP config.
68+ type IPConfig struct {
69+ // Addresses is a list of IP addresses that can be assigned. This set of
70+ // addresses can be non-contiguous.
71+ // +kubebuilder:validation:MinItems=1
72+ Addresses []string `json:"addresses,omitempty"`
73+
74+ // Prefix is the network prefix to use.
75+ // +kubebuilder:validation:Maximum=128
76+ // +optional
77+ Prefix int `json:"prefix,omitempty"`
78+
79+ // Gateway
80+ // +optional
81+ Gateway string `json:"gateway,omitempty"`
82+
83+ // DHCP indicates if DHCP should be used to assign IP addresses.
84+ // +optional
85+ DHCP bool `json:"dhcp,omitempty"`
86+ }
87+
6688// ProxmoxClusterStatus defines the observed state of ProxmoxCluster.
6789type ProxmoxClusterStatus struct {
6890 // Ready indicates that the cluster is ready.
@@ -142,141 +164,6 @@ func (c *ProxmoxCluster) SetConditions(conditions clusterv1.Conditions) {
142164 c .Status .Conditions = conditions
143165}
144166
145- // SetInClusterIPPoolRef will set the reference to the provided InClusterIPPool.
146- // If nil was provided, the status field will be cleared.
147- func (c * ProxmoxCluster ) SetInClusterIPPoolRef (pool * ipamicv1.InClusterIPPool ) {
148- if pool == nil || pool .GetName () == "" {
149- c .Status .InClusterIPPoolRef = nil
150- return
151- }
152-
153- if c .Status .InClusterIPPoolRef == nil {
154- c .Status .InClusterIPPoolRef = []corev1.LocalObjectReference {
155- {Name : pool .GetName ()},
156- }
157- }
158-
159- found := false
160- for _ , ref := range c .Status .InClusterIPPoolRef {
161- if ref .Name == pool .GetName () {
162- found = true
163- }
164- }
165- if ! found {
166- c .Status .InClusterIPPoolRef = append (c .Status .InClusterIPPoolRef , corev1.LocalObjectReference {Name : pool .GetName ()})
167- }
168- }
169-
170- // AddNodeLocation will add a node location to either the control plane or worker
171- // node locations based on the `isControlPlane` parameter.
172- func (c * ProxmoxCluster ) AddNodeLocation (loc NodeLocation , isControlPlane bool ) {
173- if c .Status .NodeLocations == nil {
174- c .Status .NodeLocations = new (NodeLocations )
175- }
176-
177- if ! c .HasMachine (loc .Machine .Name , isControlPlane ) {
178- c .addNodeLocation (loc , isControlPlane )
179- }
180- }
181-
182- // RemoveNodeLocation removes a node location from the status.
183- func (c * ProxmoxCluster ) RemoveNodeLocation (machineName string , isControlPlane bool ) {
184- nodeLocations := c .Status .NodeLocations
185-
186- if nodeLocations == nil {
187- return
188- }
189-
190- if ! c .HasMachine (machineName , isControlPlane ) {
191- return
192- }
193-
194- if isControlPlane {
195- for i , v := range nodeLocations .ControlPlane {
196- if v .Machine .Name == machineName {
197- nodeLocations .ControlPlane = append (nodeLocations .ControlPlane [:i ], nodeLocations .ControlPlane [i + 1 :]... )
198- }
199- }
200- return
201- }
202-
203- for i , v := range nodeLocations .Workers {
204- if v .Machine .Name == machineName {
205- nodeLocations .Workers = append (nodeLocations .Workers [:i ], nodeLocations .Workers [i + 1 :]... )
206- }
207- }
208- }
209-
210- // UpdateNodeLocation will update the node location based on the provided machine name.
211- // If the node location does not exist, it will be added.
212- //
213- // The function returns true if the value was added or updated, otherwise false.
214- func (c * ProxmoxCluster ) UpdateNodeLocation (machineName , node string , isControlPlane bool ) bool {
215- if ! c .HasMachine (machineName , isControlPlane ) {
216- loc := NodeLocation {
217- Node : node ,
218- Machine : corev1.LocalObjectReference {Name : machineName },
219- }
220- c .AddNodeLocation (loc , isControlPlane )
221- return true
222- }
223-
224- locations := c .Status .NodeLocations .Workers
225- if isControlPlane {
226- locations = c .Status .NodeLocations .ControlPlane
227- }
228-
229- for i , loc := range locations {
230- if loc .Machine .Name == machineName {
231- if loc .Node != node {
232- locations [i ].Node = node
233- return true
234- }
235-
236- return false
237- }
238- }
239-
240- return false
241- }
242-
243- // HasMachine returns if true if a machine was found on any node.
244- func (c * ProxmoxCluster ) HasMachine (machineName string , isControlPlane bool ) bool {
245- return c .GetNode (machineName , isControlPlane ) != ""
246- }
247-
248- // GetNode tries to return the Proxmox node for the provided machine name.
249- func (c * ProxmoxCluster ) GetNode (machineName string , isControlPlane bool ) string {
250- if c .Status .NodeLocations == nil {
251- return ""
252- }
253-
254- if isControlPlane {
255- for _ , cpl := range c .Status .NodeLocations .ControlPlane {
256- if cpl .Machine .Name == machineName {
257- return cpl .Node
258- }
259- }
260- } else {
261- for _ , wloc := range c .Status .NodeLocations .Workers {
262- if wloc .Machine .Name == machineName {
263- return wloc .Node
264- }
265- }
266- }
267-
268- return ""
269- }
270-
271- func (c * ProxmoxCluster ) addNodeLocation (loc NodeLocation , isControlPlane bool ) {
272- if isControlPlane {
273- c .Status .NodeLocations .ControlPlane = append (c .Status .NodeLocations .ControlPlane , loc )
274- return
275- }
276-
277- c .Status .NodeLocations .Workers = append (c .Status .NodeLocations .Workers , loc )
278- }
279-
280167func init () {
281168 SchemeBuilder .Register (& ProxmoxCluster {}, & ProxmoxClusterList {})
282169}
0 commit comments