Skip to content

Commit a80b417

Browse files
authored
✨ Add NetworkConfigurations, VMTemplate to FailureDomain (#3049)
* add Topology.NetworkConfigurations * fix errs, conversions * add webhook test * fix
1 parent 3c6373f commit a80b417

14 files changed

+714
-36
lines changed

apis/v1alpha3/topology_conversion.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha3
18+
19+
import (
20+
conversion "k8s.io/apimachinery/pkg/conversion"
21+
v1beta1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1"
22+
)
23+
24+
func Convert_v1beta1_Topology_To_v1alpha3_Topology(in *v1beta1.Topology, out *Topology, s conversion.Scope) error {
25+
return autoConvert_v1beta1_Topology_To_v1alpha3_Topology(in, out, s)
26+
}

apis/v1alpha3/vspherefailuredomain_conversion.go

+26-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha3
1818

1919
import (
20+
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
2021
"sigs.k8s.io/controller-runtime/pkg/conversion"
2122

2223
infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1"
@@ -25,13 +26,36 @@ import (
2526
// ConvertTo converts this VSphereFailureDomain to the Hub version (v1beta1).
2627
func (src *VSphereFailureDomain) ConvertTo(dstRaw conversion.Hub) error {
2728
dst := dstRaw.(*infrav1.VSphereFailureDomain)
28-
return Convert_v1alpha3_VSphereFailureDomain_To_v1beta1_VSphereFailureDomain(src, dst, nil)
29+
30+
if err := Convert_v1alpha3_VSphereFailureDomain_To_v1beta1_VSphereFailureDomain(src, dst, nil); err != nil {
31+
return err
32+
}
33+
34+
// Manually restore data.
35+
restored := &infrav1.VSphereFailureDomain{}
36+
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
37+
return err
38+
}
39+
40+
dst.Spec.Topology.NetworkConfigurations = restored.Spec.Topology.NetworkConfigurations
41+
42+
return nil
2943
}
3044

3145
// ConvertFrom converts from the Hub version (v1beta1) to this VSphereFailureDomain.
3246
func (dst *VSphereFailureDomain) ConvertFrom(srcRaw conversion.Hub) error {
3347
src := srcRaw.(*infrav1.VSphereFailureDomain)
34-
return Convert_v1beta1_VSphereFailureDomain_To_v1alpha3_VSphereFailureDomain(src, dst, nil)
48+
49+
if err := Convert_v1beta1_VSphereFailureDomain_To_v1alpha3_VSphereFailureDomain(src, dst, nil); err != nil {
50+
return err
51+
}
52+
53+
// Preserve Hub data on down-conversion except for metadata
54+
if err := utilconversion.MarshalData(src, dst); err != nil {
55+
return err
56+
}
57+
58+
return nil
3559
}
3660

3761
// ConvertTo converts this VSphereFailureDomainList to the Hub version (v1beta1).

apis/v1alpha3/zz_generated.conversion.go

+28-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha4/topology_conversion.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha4
18+
19+
import (
20+
conversion "k8s.io/apimachinery/pkg/conversion"
21+
v1beta1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1"
22+
)
23+
24+
func Convert_v1beta1_Topology_To_v1alpha4_Topology(in *v1beta1.Topology, out *Topology, s conversion.Scope) error {
25+
return autoConvert_v1beta1_Topology_To_v1alpha4_Topology(in, out, s)
26+
}

apis/v1alpha4/vspherefailuredomain_conversion.go

+26-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha4
1818

1919
import (
20+
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
2021
"sigs.k8s.io/controller-runtime/pkg/conversion"
2122

2223
infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1"
@@ -25,13 +26,36 @@ import (
2526
// ConvertTo converts this VSphereFailureDomain to the Hub version (v1beta1).
2627
func (src *VSphereFailureDomain) ConvertTo(dstRaw conversion.Hub) error {
2728
dst := dstRaw.(*infrav1.VSphereFailureDomain)
28-
return Convert_v1alpha4_VSphereFailureDomain_To_v1beta1_VSphereFailureDomain(src, dst, nil)
29+
30+
if err := Convert_v1alpha4_VSphereFailureDomain_To_v1beta1_VSphereFailureDomain(src, dst, nil); err != nil {
31+
return err
32+
}
33+
34+
// Manually restore data.
35+
restored := &infrav1.VSphereFailureDomain{}
36+
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
37+
return err
38+
}
39+
40+
dst.Spec.Topology.NetworkConfigurations = restored.Spec.Topology.NetworkConfigurations
41+
42+
return nil
2943
}
3044

3145
// ConvertFrom converts from the Hub version (v1beta1) to this VSphereFailureDomain.
3246
func (dst *VSphereFailureDomain) ConvertFrom(srcRaw conversion.Hub) error {
3347
src := srcRaw.(*infrav1.VSphereFailureDomain)
34-
return Convert_v1beta1_VSphereFailureDomain_To_v1alpha4_VSphereFailureDomain(src, dst, nil)
48+
49+
if err := Convert_v1beta1_VSphereFailureDomain_To_v1alpha4_VSphereFailureDomain(src, dst, nil); err != nil {
50+
return err
51+
}
52+
53+
// Preserve Hub data on down-conversion except for metadata
54+
if err := utilconversion.MarshalData(src, dst); err != nil {
55+
return err
56+
}
57+
58+
return nil
3559
}
3660

3761
// ConvertTo converts this VSphereFailureDomainList to the Hub version (v1beta1).

apis/v1alpha4/zz_generated.conversion.go

+28-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1beta1/vspherefailuredomain_types.go

+58
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
corev1 "k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

@@ -81,12 +82,69 @@ type Topology struct {
8182
// +optional
8283
Networks []string `json:"networks,omitempty"`
8384

85+
// NetworkConfigurations is a list of network configurations within this failure domain.
86+
// +optional
87+
// +listType=map
88+
// +listMapKey=networkName
89+
NetworkConfigurations []NetworkConfiguration `json:"networkConfigurations,omitempty"`
90+
8491
// Datastore is the name or inventory path of the datastore in which the
8592
// virtual machine is created/located.
8693
// +optional
8794
Datastore string `json:"datastore,omitempty"`
8895
}
8996

97+
// NetworkConfiguration defines a network configuration that should be used when consuming
98+
// a failure domain.
99+
type NetworkConfiguration struct {
100+
// NetworkName is the network name for this machine's VM.
101+
// +kubebuilder:validation:Required
102+
NetworkName string `json:"networkName"`
103+
104+
// DHCP4 is a flag that indicates whether or not to use DHCP for IPv4.
105+
// +optional
106+
DHCP4 *bool `json:"dhcp4,omitempty"`
107+
108+
// DHCP6 is a flag that indicates whether or not to use DHCP for IPv6.
109+
// +optional
110+
DHCP6 *bool `json:"dhcp6,omitempty"`
111+
112+
// Nameservers is a list of IPv4 and/or IPv6 addresses used as DNS
113+
// nameservers.
114+
// Please note that Linux allows only three nameservers (https://linux.die.net/man/5/resolv.conf).
115+
// +optional
116+
Nameservers []string `json:"nameservers,omitempty"`
117+
118+
// SearchDomains is a list of search domains used when resolving IP
119+
// addresses with DNS.
120+
// +optional
121+
SearchDomains []string `json:"searchDomains,omitempty"`
122+
123+
// DHCP4Overrides allows for the control over several DHCP behaviors.
124+
// Overrides will only be applied when the corresponding DHCP flag is set.
125+
// Only configured values will be sent, omitted values will default to
126+
// distribution defaults.
127+
// Dependent on support in the network stack for your distribution.
128+
// For more information see the netplan reference (https://netplan.io/reference#dhcp-overrides)
129+
// +optional
130+
DHCP4Overrides *DHCPOverrides `json:"dhcp4Overrides,omitempty"`
131+
132+
// DHCP6Overrides allows for the control over several DHCP behaviors.
133+
// Overrides will only be applied when the corresponding DHCP flag is set.
134+
// Only configured values will be sent, omitted values will default to
135+
// distribution defaults.
136+
// Dependent on support in the network stack for your distribution.
137+
// For more information see the netplan reference (https://netplan.io/reference#dhcp-overrides)
138+
// +optional
139+
DHCP6Overrides *DHCPOverrides `json:"dhcp6Overrides,omitempty"`
140+
141+
// AddressesFromPools is a list of IPAddressPools that should be assigned
142+
// to IPAddressClaims. The machine's cloud-init metadata will be populated
143+
// with IPAddresses fulfilled by an IPAM provider.
144+
// +optional
145+
AddressesFromPools []corev1.TypedLocalObjectReference `json:"addressesFromPools,omitempty"`
146+
}
147+
90148
// FailureDomainHosts has information required for placement of machines on VSphere hosts.
91149
type FailureDomainHosts struct {
92150
// VMGroupName is the name of the VM group

0 commit comments

Comments
 (0)