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.NetworkConfigurations) > 0 {
networks := make([]string, len(in.NetworkConfigurations))
for i := range in.NetworkConfigurations {
networks[i] = in.NetworkConfigurations[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.NetworkConfigurations) > 0 {
networks := make([]string, len(in.NetworkConfigurations))
for i := range in.NetworkConfigurations {
networks[i] = in.NetworkConfigurations[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.

55 changes: 55 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 @@ -74,6 +75,10 @@ type Topology struct {
// +optional
Networks []string `json:"networks,omitempty"`

// NetworkConfigurations is a list with new network configurations within this failure domain
// +optional
NetworkConfigurations []NetworkConfiguration `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 +93,56 @@ type FailureDomainHosts struct {
HostGroupName string `json:"hostGroupName"`
}

// NetworkConfiguration defines a network configuration that should be used when consuming
// a failure domain.
type NetworkConfiguration struct {
// NetworkName is the network name for this machine's VM.
NetworkName string `json:"name,omitempty"`

// DHCP4 is a flag that indicates whether or not to use DHCP for IPv4
// +optional
DHCP4 *bool `json:"dhcp4,omitempty"`

// DHCP6 is a flag that 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
4 changes: 4 additions & 0 deletions apis/v1beta1/vspherefailuredomain_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (r *VSphereFailureDomain) ValidateCreate() error {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "Topology", "ComputeCluster"), fmt.Sprintf("cannot be nil if zone's Failure Domain type is %s", r.Spec.Zone.Type)))
}

if len(r.Spec.Topology.NetworkConfigurations) != 0 && len(r.Spec.Topology.Networks) != 0 {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "Topology", "Networks"), "cannot be set if spec.Topology.NetworkConfigs is already set"))
}

return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
}

Expand Down
Loading