Skip to content

Commit

Permalink
Rename network config API and regenerate
Browse files Browse the repository at this point in the history
  • Loading branch information
rikatz committed Jul 3, 2023
1 parent 10a9ab4 commit c09ec63
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 80 deletions.
8 changes: 4 additions & 4 deletions apis/v1alpha3/topology_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
)

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
if len(in.NetworkConfigurations) > 0 {
networks := make([]string, len(in.NetworkConfigurations))
for i := range in.NetworkConfigurations {
networks[i] = in.NetworkConfigurations[i].NetworkName
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion apis/v1alpha3/zz_generated.conversion.go

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

8 changes: 4 additions & 4 deletions apis/v1alpha4/topology_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
)

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
if len(in.NetworkConfigurations) > 0 {
networks := make([]string, len(in.NetworkConfigurations))
for i := range in.NetworkConfigurations {
networks[i] = in.NetworkConfigurations[i].NetworkName
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion apis/v1alpha4/zz_generated.conversion.go

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

19 changes: 7 additions & 12 deletions apis/v1beta1/vspherefailuredomain_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ 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"`
// 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.
Expand All @@ -94,21 +93,17 @@ 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 {
// 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"`

// @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
// +optional
DHCP4 *bool `json:"dhcp4,omitempty"`

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

Expand Down
2 changes: 1 addition & 1 deletion apis/v1beta1/vspherefailuredomain_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ 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.NetworkConfigs) != 0 && len(r.Spec.Topology.Networks) != 0 {
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 not empty"))
}

Expand Down
4 changes: 2 additions & 2 deletions apis/v1beta1/vspherefailuredomain_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestVSphereFailureDomain_ValidateCreate(t *testing.T) {
Topology: Topology{
Datacenter: "/blah",
ComputeCluster: pointer.String("Cluster1"),
NetworkConfigs: []FailureDomainNetwork{
NetworkConfigurations: []NetworkConfiguration{
{
NetworkName: "network-a",
DHCP4: pointer.Bool(true),
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestVSphereFailureDomain_ValidateCreate(t *testing.T) {
Datacenter: "/blah",
ComputeCluster: pointer.String("Cluster1"),
Networks: []string{"network-a", "network-b"},
NetworkConfigs: []FailureDomainNetwork{
NetworkConfigurations: []NetworkConfiguration{
{
NetworkName: "network-a",
DHCP4: pointer.Bool(true),
Expand Down
64 changes: 32 additions & 32 deletions apis/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,11 @@ spec:
- vmGroupName
type: object
networkConfigs:
description: NetworkConfigs is a list with new network configurations
within this failure domain
description: NetworkConfigurations is a list with new network
configurations within this failure domain
items:
description: 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?
description: NetworkConfiguration defines a network configuration
that should be used when consuming a failure domain.
properties:
addressesFromPools:
description: AddressesFromPools is a list of IPAddressPools
Expand Down Expand Up @@ -371,15 +370,8 @@ spec:
type: object
type: array
dhcp4:
description: '@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'
description: DHCP4 is a flag that indicates whether or not
to use DHCP for IPv4
type: boolean
dhcp4Overrides:
description: DHCP4Overrides allows for the control over
Expand Down Expand Up @@ -435,8 +427,8 @@ spec:
type: string
type: object
dhcp6:
description: DHCP6 indicates whether or not to use DHCP
for IPv6
description: DHCP6 is a flag that indicates whether or not
to use DHCP for IPv6
type: boolean
dhcp6Overrides:
description: DHCP6Overrides allows for the control over
Expand Down Expand Up @@ -511,8 +503,8 @@ spec:
type: object
type: array
networks:
description: 'Networks is the list of networks within this failure
domain TODO (@rkatz): Deprecate in favor of NetworkConfigs?'
description: Networks is the list of networks within this failure
domain
items:
type: string
type: array
Expand Down
8 changes: 4 additions & 4 deletions pkg/services/vimmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,10 @@ func (v *VimMachineService) generateOverrideFunc(ctx *context.VIMMachineContext)
vm.Spec.Datastore = vsphereFailureDomain.Spec.Topology.Datastore
}

networkConfigs := vsphereFailureDomain.Spec.Topology.NetworkConfigs
networkConfigs := vsphereFailureDomain.Spec.Topology.NetworkConfigurations
// Convert the deprecated vsphereFailureDomain.Spec.Topology to networkConfigs if necessary.
if len(networkConfigs) == 0 && len(vsphereFailureDomain.Spec.Topology.Networks) > 0 {
networkConfigs = make([]infrav1.FailureDomainNetwork, len(vsphereFailureDomain.Spec.Topology.Networks))
networkConfigs = make([]infrav1.NetworkConfiguration, len(vsphereFailureDomain.Spec.Topology.Networks))
for i := range vsphereFailureDomain.Spec.Topology.Networks {
networkConfigs[i].NetworkName = vsphereFailureDomain.Spec.Topology.Networks[i]
}
Expand All @@ -518,7 +518,7 @@ func (v *VimMachineService) generateOverrideFunc(ctx *context.VIMMachineContext)
// The substitution is done based on the order in which the network devices have been defined.
//
// In case there are more network definitions than the number of network devices specified, the definitions are appended to the list.
func overrideNetworkDeviceSpecs(deviceSpecs []infrav1.NetworkDeviceSpec, networks []infrav1.FailureDomainNetwork) []infrav1.NetworkDeviceSpec {
func overrideNetworkDeviceSpecs(deviceSpecs []infrav1.NetworkDeviceSpec, networks []infrav1.NetworkConfiguration) []infrav1.NetworkDeviceSpec {
index, length := 0, len(networks)

devices := make([]infrav1.NetworkDeviceSpec, 0, integer.IntMax(length, len(deviceSpecs)))
Expand All @@ -541,7 +541,7 @@ func overrideNetworkDeviceSpecs(deviceSpecs []infrav1.NetworkDeviceSpec, network
return devices
}

func mergeFailureDomainNetSpecToNetworkDeviceSpec(fd infrav1.FailureDomainNetwork, vmNetworkDeviceSpec *infrav1.NetworkDeviceSpec) {
func mergeFailureDomainNetSpecToNetworkDeviceSpec(fd infrav1.NetworkConfiguration, vmNetworkDeviceSpec *infrav1.NetworkDeviceSpec) {
// We don't convert if destination is null
if vmNetworkDeviceSpec == nil {
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/vimmachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var _ = Describe("VimMachineService_GenerateOverrideFunc", func() {
Datacenter: fmt.Sprintf("dc-%s", suffix),
Datastore: fmt.Sprintf("ds-%s", suffix),
Networks: networks,
NetworkConfigs: []infrav1.FailureDomainNetwork{
NetworkConfigurations: []infrav1.NetworkConfiguration{
{
NetworkName: fmt.Sprintf("newnw-%s", suffix),
DHCP4: pointer.Bool(false),
Expand Down

0 comments on commit c09ec63

Please sign in to comment.