diff --git a/pkg/asset/machines/clusterapi.go b/pkg/asset/machines/clusterapi.go index 2804eab1b4..1e77ee5a74 100644 --- a/pkg/asset/machines/clusterapi.go +++ b/pkg/asset/machines/clusterapi.go @@ -377,6 +377,13 @@ func (c *ClusterAPI) Generate(dependencies asset.Parents) error { pool.Platform.OpenStack = &mpool imageName, _ := rhcosutils.GenerateOpenStackImageName(string(*rhcosImage), clusterID.InfraID) + trunkSupport, err := openstack.CheckNetworkExtensionAvailability( + ic.Platform.OpenStack.Cloud, + "trunk", + ) + if err != nil { + return fmt.Errorf("failed to check for trunk support: %w", err) + } for _, role := range []string{"master", "bootstrap"} { openStackMachines, err := openstack.GenerateMachines( @@ -385,6 +392,7 @@ func (c *ClusterAPI) Generate(dependencies asset.Parents) error { &pool, imageName, role, + trunkSupport, ) if err != nil { return fmt.Errorf("failed to create machine objects: %w", err) diff --git a/pkg/asset/machines/master.go b/pkg/asset/machines/master.go index 1df58bbaf9..3f95510b19 100644 --- a/pkg/asset/machines/master.go +++ b/pkg/asset/machines/master.go @@ -310,9 +310,16 @@ func (m *Master) Generate(dependencies asset.Parents) error { imageName, _ := rhcosutils.GenerateOpenStackImageName(string(*rhcosImage), clusterID.InfraID) - machines, controlPlaneMachineSet, err = openstack.Machines(clusterID.InfraID, ic, &pool, imageName, "master", masterUserDataSecretName) + trunkSupport, err := openstack.CheckNetworkExtensionAvailability( + ic.Platform.OpenStack.Cloud, + "trunk", + ) if err != nil { - return errors.Wrap(err, "failed to create master machine objects") + return fmt.Errorf("failed to check for trunk support: %w", err) + } + machines, controlPlaneMachineSet, err = openstack.Machines(clusterID.InfraID, ic, &pool, imageName, "master", masterUserDataSecretName, trunkSupport) + if err != nil { + return fmt.Errorf("failed to create master machine objects: %w", err) } openstack.ConfigMasters(machines, clusterID.InfraID) case azuretypes.Name: diff --git a/pkg/asset/machines/openstack/machines.go b/pkg/asset/machines/openstack/machines.go index 1dd83c111d..dcdba94708 100644 --- a/pkg/asset/machines/openstack/machines.go +++ b/pkg/asset/machines/openstack/machines.go @@ -7,7 +7,6 @@ import ( "github.com/gophercloud/gophercloud" netext "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions" "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" - "github.com/gophercloud/utils/openstack/clientconfig" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -35,7 +34,7 @@ const ( ) // Machines returns a list of machines for a machinepool. -func Machines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string) ([]machineapi.Machine, *machinev1.ControlPlaneMachineSet, error) { +func Machines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string, trunkSupport bool) ([]machineapi.Machine, *machinev1.ControlPlaneMachineSet, error) { if configPlatform := config.Platform.Name(); configPlatform != openstack.Name { return nil, nil, fmt.Errorf("non-OpenStack configuration: %q", configPlatform) } @@ -44,11 +43,6 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine } mpool := pool.Platform.OpenStack - platform := config.Platform.OpenStack - trunkSupport, err := checkNetworkExtensionAvailability(platform.Cloud, "trunk", nil) - if err != nil { - return nil, nil, err - } total := int64(1) if pool.Replicas != nil { @@ -61,7 +55,7 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine providerSpec, err := generateProviderSpec( clusterID, - platform, + config.Platform.OpenStack, mpool, osImage, role, @@ -99,7 +93,7 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine machineSetProviderSpec, err := generateProviderSpec( clusterID, - platform, + config.Platform.OpenStack, mpool, osImage, role, @@ -379,10 +373,10 @@ func failureDomainsFromSpec(mpool openstack.MachinePool) []machinev1.OpenStackFa return failureDomains } -func checkNetworkExtensionAvailability(cloud, alias string, opts *clientconfig.ClientOpts) (bool, error) { - if opts == nil { - opts = openstackdefaults.DefaultClientOpts(cloud) - } +// CheckNetworkExtensionAvailability interrogates the OpenStack API to validate +// the availability of a given Neutron extension. +func CheckNetworkExtensionAvailability(cloud, alias string) (bool, error) { + opts := openstackdefaults.DefaultClientOpts(cloud) conn, err := openstackdefaults.NewServiceClient("network", opts) if err != nil { return false, err diff --git a/pkg/asset/machines/openstack/machinesets.go b/pkg/asset/machines/openstack/machinesets.go index 1de6681ef0..90f51ffa97 100644 --- a/pkg/asset/machines/openstack/machinesets.go +++ b/pkg/asset/machines/openstack/machinesets.go @@ -4,7 +4,6 @@ package openstack import ( "fmt" - "github.com/gophercloud/utils/openstack/clientconfig" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -24,19 +23,14 @@ const maxInt32 int64 = int64(^uint32(0)) >> 1 // availability zones, Storage availability zones and Root volume types), when // more than one is specified, values of identical index are grouped in the // same MachineSet. -func MachineSets(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string, clientOpts *clientconfig.ClientOpts) ([]*clusterapi.MachineSet, error) { +func MachineSets(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string, trunkSupport bool) ([]*clusterapi.MachineSet, error) { if configPlatform := config.Platform.Name(); configPlatform != openstack.Name { return nil, fmt.Errorf("non-OpenStack configuration: %q", configPlatform) } if poolPlatform := pool.Platform.Name(); poolPlatform != openstack.Name { return nil, fmt.Errorf("non-OpenStack machine-pool: %q", poolPlatform) } - platform := config.Platform.OpenStack mpool := pool.Platform.OpenStack - trunkSupport, err := checkNetworkExtensionAvailability(platform.Cloud, "trunk", clientOpts) - if err != nil { - return nil, err - } failureDomains := failureDomainsFromSpec(*mpool) numberOfFailureDomains := int64(len(failureDomains)) @@ -60,7 +54,7 @@ func MachineSets(clusterID string, config *types.InstallConfig, pool *types.Mach providerSpec, err := generateProviderSpec( clusterID, - platform, + config.Platform.OpenStack, mpool, osImage, role, diff --git a/pkg/asset/machines/openstack/openstackmachines.go b/pkg/asset/machines/openstack/openstackmachines.go index fbf9612b5c..0a6631fc26 100644 --- a/pkg/asset/machines/openstack/openstackmachines.go +++ b/pkg/asset/machines/openstack/openstackmachines.go @@ -18,7 +18,7 @@ import ( ) // GenerateMachines returns manifests and runtime objects to provision the control plane (including bootstrap, if applicable) nodes using CAPI. -func GenerateMachines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role string) ([]*asset.RuntimeFile, error) { +func GenerateMachines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role string, trunkSupport bool) ([]*asset.RuntimeFile, error) { if configPlatform := config.Platform.Name(); configPlatform != openstack.Name { return nil, fmt.Errorf("non-OpenStack configuration: %q", configPlatform) } @@ -27,10 +27,6 @@ func GenerateMachines(clusterID string, config *types.InstallConfig, pool *types } mpool := pool.Platform.OpenStack - trunkSupport, err := checkNetworkExtensionAvailability(config.Platform.OpenStack.Cloud, "trunk", nil) - if err != nil { - return nil, err - } total := int64(1) if role == "master" && pool.Replicas != nil { diff --git a/pkg/asset/machines/worker.go b/pkg/asset/machines/worker.go index b3b197037a..7d46a0919b 100644 --- a/pkg/asset/machines/worker.go +++ b/pkg/asset/machines/worker.go @@ -584,9 +584,16 @@ func (w *Worker) Generate(dependencies asset.Parents) error { imageName, _ := rhcosutils.GenerateOpenStackImageName(string(*rhcosImage), clusterID.InfraID) - sets, err := openstack.MachineSets(clusterID.InfraID, ic, &pool, imageName, "worker", workerUserDataSecretName, nil) + trunkSupport, err := openstack.CheckNetworkExtensionAvailability( + ic.Platform.OpenStack.Cloud, + "trunk", + ) if err != nil { - return errors.Wrap(err, "failed to create worker machine objects") + return fmt.Errorf("failed to check for trunk support: %w", err) + } + sets, err := openstack.MachineSets(clusterID.InfraID, ic, &pool, imageName, "worker", workerUserDataSecretName, trunkSupport) + if err != nil { + return fmt.Errorf("failed to create worker machine objects: %w", err) } for _, set := range sets { machineSets = append(machineSets, set)