|
| 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