Skip to content

Commit 560cd09

Browse files
mandreMaysaMacedo
andcommitted
Make OpenStack use Provider interface
Co-Authored-By: Maysa Macedo <[email protected]>
1 parent 24dbc57 commit 560cd09

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package clusterapi
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
capo "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7"
8+
"sigs.k8s.io/controller-runtime/pkg/client"
9+
10+
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
11+
"github.com/openshift/installer/pkg/asset/manifests/capiutils"
12+
"github.com/openshift/installer/pkg/infrastructure/clusterapi"
13+
openstackdefaults "github.com/openshift/installer/pkg/types/openstack/defaults"
14+
)
15+
16+
// Provider defines the InfraProvider.
17+
type Provider struct {
18+
clusterapi.InfraProvider
19+
}
20+
21+
// func (p Provider) PreProvision(in clusterapi.PreProvisionInput) error {
22+
// return nil
23+
// }
24+
25+
func (p Provider) ControlPlaneAvailable(in clusterapi.ControlPlaneAvailableInput) error {
26+
ospCluster := &capo.OpenStackCluster{}
27+
key := client.ObjectKey{
28+
Name: in.InfraID,
29+
Namespace: capiutils.Namespace,
30+
}
31+
if err := in.Client.Get(context.Background(), key, ospCluster); err != nil {
32+
return fmt.Errorf("failed to get OSPCluster: %w", err)
33+
}
34+
35+
networkClient, err := openstackdefaults.NewServiceClient("network", openstackdefaults.DefaultClientOpts(in.InstallConfig.Config.Platform.OpenStack.Cloud))
36+
if err != nil {
37+
return err
38+
}
39+
40+
createOtps := ports.CreateOpts{
41+
Name: "CAPO test",
42+
NetworkID: ospCluster.Status.Network.ID,
43+
}
44+
45+
_, err = ports.Create(networkClient, createOtps).Extract()
46+
if err != nil {
47+
return err
48+
}
49+
50+
_, err = ports.Create(networkClient, createOtps).Extract()
51+
if err != nil {
52+
return err
53+
}
54+
55+
return nil
56+
}

pkg/infrastructure/platform/platform.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
awscapi "github.com/openshift/installer/pkg/infrastructure/aws/clusterapi"
1313
"github.com/openshift/installer/pkg/infrastructure/clusterapi"
1414
gcpcapi "github.com/openshift/installer/pkg/infrastructure/gcp/clusterapi"
15+
openstackcapi "github.com/openshift/installer/pkg/infrastructure/openstack/clusterapi"
1516
powervscapi "github.com/openshift/installer/pkg/infrastructure/powervs/clusterapi"
1617
vspherecapi "github.com/openshift/installer/pkg/infrastructure/vsphere/clusterapi"
1718
"github.com/openshift/installer/pkg/terraform"
@@ -76,6 +77,9 @@ func ProviderForPlatform(platform string, fg featuregates.FeatureGate) (infrastr
7677
}
7778
return terraform.InitializeProvider(powervs.PlatformStages), nil
7879
case openstacktypes.Name:
80+
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
81+
return clusterapi.InitializeProvider(openstackcapi.Provider{}), nil
82+
}
7983
return terraform.InitializeProvider(openstack.PlatformStages), nil
8084
case ovirttypes.Name:
8185
return terraform.InitializeProvider(ovirt.PlatformStages), nil

pkg/infrastructure/platform/platform_altinfra.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import (
1212
awscapi "github.com/openshift/installer/pkg/infrastructure/aws/clusterapi"
1313
"github.com/openshift/installer/pkg/infrastructure/clusterapi"
1414
gcpcapi "github.com/openshift/installer/pkg/infrastructure/gcp/clusterapi"
15+
openstackcapi "github.com/openshift/installer/pkg/infrastructure/openstack/clusterapi"
1516
powervscapi "github.com/openshift/installer/pkg/infrastructure/powervs/clusterapi"
1617
vspherecapi "github.com/openshift/installer/pkg/infrastructure/vsphere/clusterapi"
1718
awstypes "github.com/openshift/installer/pkg/types/aws"
1819
azuretypes "github.com/openshift/installer/pkg/types/azure"
1920
"github.com/openshift/installer/pkg/types/featuregates"
2021
gcptypes "github.com/openshift/installer/pkg/types/gcp"
22+
openstacktypes "github.com/openshift/installer/pkg/types/openstack"
2123
powervstypes "github.com/openshift/installer/pkg/types/powervs"
2224
vspheretypes "github.com/openshift/installer/pkg/types/vsphere"
2325
)
@@ -47,6 +49,10 @@ func ProviderForPlatform(platform string, fg featuregates.FeatureGate) (infrastr
4749
return clusterapi.InitializeProvider(powervscapi.Provider{}), nil
4850
}
4951
return nil, nil
52+
case openstacktypes.Name:
53+
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
54+
return clusterapi.InitializeProvider(openstackcapi.Provider{}), nil
55+
}
5056
}
5157
return nil, fmt.Errorf("platform %q is not supported in the altinfra Installer build", platform)
5258
}

0 commit comments

Comments
 (0)