Skip to content

Commit 84eacc1

Browse files
stephenfinMaysaMacedomandre
committed
cluster-api: Implement cluster generation for OpenStack
Signed-off-by: Stephen Finucane <[email protected]> Co-authored-by: Maysa Macedo <[email protected]> Co-authored-by: Martin André <[email protected]>
1 parent 3b50513 commit 84eacc1

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

pkg/asset/manifests/clusterapi/cluster.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ import (
2020
"github.com/openshift/installer/pkg/asset/manifests/azure"
2121
"github.com/openshift/installer/pkg/asset/manifests/capiutils"
2222
"github.com/openshift/installer/pkg/asset/manifests/gcp"
23+
"github.com/openshift/installer/pkg/asset/manifests/openstack"
2324
"github.com/openshift/installer/pkg/asset/manifests/vsphere"
2425
"github.com/openshift/installer/pkg/asset/openshiftinstall"
2526
"github.com/openshift/installer/pkg/asset/rhcos"
2627
"github.com/openshift/installer/pkg/clusterapi"
2728
awstypes "github.com/openshift/installer/pkg/types/aws"
2829
azuretypes "github.com/openshift/installer/pkg/types/azure"
2930
gcptypes "github.com/openshift/installer/pkg/types/gcp"
31+
openstacktypes "github.com/openshift/installer/pkg/types/openstack"
3032
vsphereplatform "github.com/openshift/installer/pkg/types/vsphere"
3133
)
3234

@@ -121,6 +123,12 @@ func (c *Cluster) Generate(dependencies asset.Parents) error {
121123
if err != nil {
122124
return fmt.Errorf("failed to generate vSphere manifests %w", err)
123125
}
126+
case openstacktypes.Name:
127+
var err error
128+
out, err = openstack.GenerateClusterAssets(installConfig, clusterID)
129+
if err != nil {
130+
return errors.Wrap(err, "failed to generate OpenStack manifests")
131+
}
124132
default:
125133
return fmt.Errorf("unsupported platform %q", platform)
126134
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package openstack
2+
3+
import (
4+
"fmt"
5+
6+
corev1 "k8s.io/api/core/v1"
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
capo "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7"
9+
capi "sigs.k8s.io/cluster-api/api/v1beta1"
10+
11+
"github.com/openshift/installer/pkg/asset"
12+
"github.com/openshift/installer/pkg/asset/installconfig"
13+
"github.com/openshift/installer/pkg/asset/manifests/capiutils"
14+
)
15+
16+
const (
17+
CloudName = "openstack"
18+
CredentialsSecretName = "openstack-cloud-credentials"
19+
)
20+
21+
func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID *installconfig.ClusterID) (*capiutils.GenerateClusterAssetsOutput, error) {
22+
manifests := []*asset.RuntimeFile{}
23+
openstackInstallConfig := installConfig.Config.OpenStack
24+
openStackCluster := &capo.OpenStackCluster{
25+
ObjectMeta: metav1.ObjectMeta{
26+
Name: clusterID.InfraID,
27+
Namespace: capiutils.Namespace,
28+
Labels: map[string]string{
29+
capi.ClusterNameLabel: clusterID.InfraID,
30+
},
31+
},
32+
Spec: capo.OpenStackClusterSpec{
33+
CloudName: CloudName,
34+
// TODO(stephenfin): Create credentials
35+
IdentityRef: &capo.OpenStackIdentityReference{
36+
Kind: "Secret",
37+
Name: CredentialsSecretName,
38+
},
39+
// We disable management of most networking resources since either
40+
// we (the installer) will create them, or the user will have
41+
// pre-created them as part of a "Bring Your Own Network (BYON)"
42+
// configuration
43+
ManagedSecurityGroups: false,
44+
DisableAPIServerFloatingIP: true,
45+
// TODO(stephenfin): update when we support dual-stack (there are
46+
// potentially *two* IPs here)
47+
APIServerFixedIP: openstackInstallConfig.APIVIPs[0],
48+
DNSNameservers: openstackInstallConfig.ExternalDNS,
49+
ExternalNetworkID: openstackInstallConfig.ExternalNetwork,
50+
Tags: []string{
51+
fmt.Sprintf("openshiftClusterID=%s", clusterID.InfraID),
52+
},
53+
},
54+
}
55+
if openstackInstallConfig.ControlPlanePort != nil {
56+
// TODO(maysa): update when BYO dual-stack is supported in CAPO
57+
openStackCluster.Spec.Network.ID = openstackInstallConfig.ControlPlanePort.Network.ID
58+
openStackCluster.Spec.Network.Name = openstackInstallConfig.ControlPlanePort.Network.Name
59+
openStackCluster.Spec.Subnet.ID = openstackInstallConfig.ControlPlanePort.FixedIPs[0].Subnet.ID
60+
openStackCluster.Spec.Subnet.Name = openstackInstallConfig.ControlPlanePort.FixedIPs[0].Subnet.Name
61+
} else {
62+
openStackCluster.Spec.NodeCIDR = capiutils.CIDRFromInstallConfig(installConfig).String()
63+
}
64+
openStackCluster.SetGroupVersionKind(capo.GroupVersion.WithKind("OpenStackCluster"))
65+
66+
manifests = append(manifests, &asset.RuntimeFile{
67+
Object: openStackCluster,
68+
File: asset.File{Filename: "02_infra-cluster.yaml"},
69+
})
70+
71+
// TODO(stephenfin): Create credentials request/cloud secret
72+
73+
return &capiutils.GenerateClusterAssetsOutput{
74+
Manifests: manifests,
75+
InfrastructureRef: &corev1.ObjectReference{
76+
APIVersion: "infrastructure.cluster.x-k8s.io/v1alpha7",
77+
Kind: "OpenStackCluster",
78+
Name: openStackCluster.Name,
79+
Namespace: openStackCluster.Namespace,
80+
},
81+
}, nil
82+
}

0 commit comments

Comments
 (0)