Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions pkg/cloudprovider/provider/vmwareclouddirector/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ func createVM(client *Client, machine *clusterv1alpha1.Machine, c *Config, org *
}
}

var networkConnections []*vcdapitypes.NetworkConnection
for i, network := range c.Networks {
networkConnections = append(networkConnections, &vcdapitypes.NetworkConnection{
Network: network,
NeedsCustomization: false,
IsConnected: true,
IPAddressAllocationMode: string(c.IPAllocationMode),
NetworkAdapterType: "VMXNET3",
NetworkConnectionIndex: i,
})
}

fmt.Printf("network connections: %+v\n", networkConnections)

// 4. At this point we are ready to create our initial VMs.
//
// Multiple API calls to re-compose the vApp are handled in a synchronous manner, where each request has to wait
Expand All @@ -145,15 +159,7 @@ func createVM(client *Client, machine *clusterv1alpha1.Machine, c *Config, org *
},
InstantiationParams: &vcdapitypes.InstantiationParams{
NetworkConnectionSection: &vcdapitypes.NetworkConnectionSection{
NetworkConnection: []*vcdapitypes.NetworkConnection{
{
Network: c.Network,
NeedsCustomization: false,
IsConnected: true,
IPAddressAllocationMode: string(c.IPAllocationMode),
NetworkAdapterType: "VMXNET3",
},
},
NetworkConnection: networkConnections,
},
},
StorageProfile: storageProfile,
Expand Down
31 changes: 25 additions & 6 deletions pkg/cloudprovider/provider/vmwareclouddirector/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type Config struct {
SizingPolicy *string

// Network configuration.
Network string
Networks []string
IPAllocationMode vcdtypes.IPAllocationMode

// Compute configuration.
Expand Down Expand Up @@ -375,11 +375,23 @@ func (p *provider) getConfig(provSpec clusterv1alpha1.ProviderSpec) (*Config, *p
return nil, nil, nil, err
}

c.Network, err = p.configVarResolver.GetStringValue(rawConfig.Network)
singleNetwork, err := p.configVarResolver.GetStringValue(rawConfig.Network)
if err != nil {
return nil, nil, nil, err
}

if singleNetwork != "" && len(rawConfig.Networks) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why only if len(Networks) == 0? I suggest to use it anyway, as a first c.Networks element.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change that if you want, my thoughts were, that you would use one of both and not both, but it wouldnt hurt

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, since this commit will deprecate a single Network and suggest to use []Network in code we'd want to use only the new way and somehow convert the old deprecated single Network to the new []Network.

My suggestion is this exact convertion.

c.Networks = append(c.Networks, singleNetwork)
}

for _, network := range rawConfig.Networks {
networkValue, err := p.configVarResolver.GetStringValue(network)
if err != nil {
return nil, nil, nil, err
}
c.Networks = append(c.Networks, networkValue)
}

c.IPAllocationMode = rawConfig.IPAllocationMode

if rawConfig.DiskSizeGB != nil && *rawConfig.DiskSizeGB < 0 {
Expand Down Expand Up @@ -509,11 +521,18 @@ func (p *provider) Validate(_ context.Context, _ *zap.SugaredLogger, spec cluste
return fmt.Errorf("diskSizeGB '%v' cannot be less than the template size '%v': %w", *c.DiskSizeGB, catalogItem.CatalogItem.Size, err)
}

// Ensure that the network exists
// Ensure that the networks exists
// It can either be a vApp network or a vApp Org network.
_, err = GetVappNetworkType(c.Network, *vapp)
if err != nil {
return fmt.Errorf("failed to get network '%s' for vapp '%s': %w", c.Network, c.VApp, err)

if len(c.Networks) == 0 {
return fmt.Errorf("at least one network must be specified")
}

for _, network := range c.Networks {
_, err = GetVappNetworkType(network, *vapp)
if err != nil {
return fmt.Errorf("failed to get network '%s' for vapp '%s': %w", network, c.VApp, err)
}
}

if c.SizingPolicy != nil || c.PlacementPolicy != nil {
Expand Down
6 changes: 4 additions & 2 deletions sdk/cloudprovider/vmwareclouddirector/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ type RawConfig struct {
PlacementPolicy *string `json:"placementPolicy,omitempty"`

// Network configuration.
Network providerconfig.ConfigVarString `json:"network"`
IPAllocationMode IPAllocationMode `json:"ipAllocationMode,omitempty"`
// Deprecated: Use networks instead.
Network providerconfig.ConfigVarString `json:"network,omitempty"`
Networks []providerconfig.ConfigVarString `json:"networks"`
IPAllocationMode IPAllocationMode `json:"ipAllocationMode,omitempty"`

// Compute configuration.
CPUs int64 `json:"cpus"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ spec:
vapp: "kubermatic-e2e"
catalog: "kubermatic"
template: "machine-controller-<< OS_NAME >>"
network: "kubermatic-e2e-routed-network"
networks:
- "kubermatic-e2e-routed-network"
ipAllocationMode: "DHCP"
cpus: 2
cpuCores: 1
Expand Down