Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Extend Failure Domain API to support extra network configuration #1967

Closed
wants to merge 10 commits into from
32 changes: 32 additions & 0 deletions apis/v1alpha3/topology_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2023 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha3

import (
conversion "k8s.io/apimachinery/pkg/conversion"
v1beta1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1"
)

func Convert_v1beta1_Topology_To_v1alpha3_Topology(in *v1beta1.Topology, out *Topology, s conversion.Scope) error {
if len(in.NetworkConfigs) > 0 {
networks := make([]string, len(in.NetworkConfigs))
for i := range in.NetworkConfigs {
networks[i] = in.NetworkConfigs[i].NetworkName
}
}
return nil
}
40 changes: 28 additions & 12 deletions apis/v1alpha3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions apis/v1alpha4/topology_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2023 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha4

import (
conversion "k8s.io/apimachinery/pkg/conversion"
v1beta1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1"
)

func Convert_v1beta1_Topology_To_v1alpha4_Topology(in *v1beta1.Topology, out *Topology, s conversion.Scope) error {
if len(in.NetworkConfigs) > 0 {
networks := make([]string, len(in.NetworkConfigs))
for i := range in.NetworkConfigs {
networks[i] = in.NetworkConfigs[i].NetworkName
}
}
return nil
}
40 changes: 28 additions & 12 deletions apis/v1alpha4/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions apis/v1beta1/vspherefailuredomain_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package v1beta1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -71,9 +72,14 @@ type Topology struct {
Hosts *FailureDomainHosts `json:"hosts,omitempty"`

// Networks is the list of networks within this failure domain
// TODO (@rkatz): Deprecate in favor of NetworkConfigs?
// +optional
Networks []string `json:"networks,omitempty"`

// NetworkConfigs is a list with new network configurations within this failure domain
// + optional
NetworkConfigs []FailureDomainNetwork `json:"networkConfigs,omitempty"`

// Datastore is the name or inventory path of the datastore in which the
// virtual machine is created/located.
// +optional
Expand All @@ -88,6 +94,60 @@ type FailureDomainHosts struct {
HostGroupName string `json:"hostGroupName"`
}

// FailureDomainNetwork defines a network configuration that should be used when consuming
// this failure domain.
// @rkatz - To be discussed with team, should we just embed NetworkDeviceSpec?
type FailureDomainNetwork struct {
rikatz marked this conversation as resolved.
Show resolved Hide resolved
rikatz marked this conversation as resolved.
Show resolved Hide resolved
// NetworkName is the network name for this machine's VM.
NetworkName string `json:"name,omitempty"`

// @rkatz - The reason NetworkDeviceSpec is not being copied here, is because DHCP4 and DHCP6 are not pointers there
// This means that, in a case like "I want DHCP4 to be enabled on my template" and "I want DHCP4 to be disabled on this failure domain"
// we cannot verify if DHCP4 was unset (nil, we don't care about it on failure domain) vs set to false (I want to FORCE it to be false)
// DHCP4 is a flag that indicates whether or not to use DHCP for IPv4
rikatz marked this conversation as resolved.
Show resolved Hide resolved
// +optional
DHCP4 *bool `json:"dhcp4,omitempty"`

// DHCP6 indicates whether or not to use DHCP for IPv6
// +optional
DHCP6 *bool `json:"dhcp6,omitempty"`

// Nameservers is a list of IPv4 and/or IPv6 addresses used as DNS
// nameservers.
// Please note that Linux allows only three nameservers (https://linux.die.net/man/5/resolv.conf).
// +optional
Nameservers []string `json:"nameservers,omitempty"`

// SearchDomains is a list of search domains used when resolving IP
// addresses with DNS.
// +optional
SearchDomains []string `json:"searchDomains,omitempty"`

// DHCP4Overrides allows for the control over several DHCP behaviors.
// Overrides will only be applied when the corresponding DHCP flag is set.
// Only configured values will be sent, omitted values will default to
// distribution defaults.
// Dependent on support in the network stack for your distribution.
// For more information see the netplan reference (https://netplan.io/reference#dhcp-overrides)
// +optional
DHCP4Overrides *DHCPOverrides `json:"dhcp4Overrides,omitempty"`

// DHCP6Overrides allows for the control over several DHCP behaviors.
// Overrides will only be applied when the corresponding DHCP flag is set.
// Only configured values will be sent, omitted values will default to
// distribution defaults.
// Dependent on support in the network stack for your distribution.
// For more information see the netplan reference (https://netplan.io/reference#dhcp-overrides)
// +optional
DHCP6Overrides *DHCPOverrides `json:"dhcp6Overrides,omitempty"`

// AddressesFromPools is a list of IPAddressPools that should be assigned
// to IPAddressClaims. The machine's cloud-init metadata will be populated
// with IPAddresses fulfilled by an IPAM provider.
// +optional
AddressesFromPools []corev1.TypedLocalObjectReference `json:"addressesFromPools,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// +kubebuilder:resource:path=vspherefailuredomains,scope=Cluster,categories=cluster-api
Expand Down
11 changes: 11 additions & 0 deletions apis/v1beta1/vspherefailuredomain_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,15 @@ func (r *VSphereFailureDomain) Default() {
if r.Spec.Region.AutoConfigure == nil {
r.Spec.Region.AutoConfigure = pointer.Bool(false)
}

// Converts the old Networks field to NetworkConfigs
// TODO (@rkatz) - Can this be harmful for Gitops and other users that check spec and re-apply? Probably it will generate
// a difference between "what is expected" and "what we have" as there's going to be the additional "NetworkConfigs" field
//
if len(r.Spec.Topology.NetworkConfigs) == 0 && len(r.Spec.Topology.Networks) > 0 {
r.Spec.Topology.NetworkConfigs = make([]FailureDomainNetwork, len(r.Spec.Topology.Networks))
for i := range r.Spec.Topology.Networks {
r.Spec.Topology.NetworkConfigs[i].NetworkName = r.Spec.Topology.Networks[i]
}
}
rikatz marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading