Skip to content

Commit 9cdeec9

Browse files
committed
Revert "Revert openshift#8221 "SPLAT-1553: Added multi vCenter support for capi installer.""
1 parent b80f72c commit 9cdeec9

File tree

25 files changed

+379
-224
lines changed

25 files changed

+379
-224
lines changed

data/data/install.openshift.io_installconfigs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4638,7 +4638,7 @@ spec:
46384638
- server
46394639
- user
46404640
type: object
4641-
maxItems: 1
4641+
maxItems: 3
46424642
minItems: 1
46434643
type: array
46444644
type: object

pkg/asset/cluster/vsphere/vsphere.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ import (
99
func Metadata(config *types.InstallConfig) *typesvsphere.Metadata {
1010
terraformPlatform := "vsphere"
1111

12-
// Since currently we only support a single vCenter
13-
// just use the first entry in the VCenters slice.
14-
return &typesvsphere.Metadata{
15-
VCenter: config.VSphere.VCenters[0].Server,
16-
Username: config.VSphere.VCenters[0].Username,
17-
Password: config.VSphere.VCenters[0].Password,
12+
metadata := &typesvsphere.Metadata{
1813
TerraformPlatform: terraformPlatform,
1914
}
15+
16+
vcenterList := []typesvsphere.VCenters{}
17+
for _, vcenter := range config.VSphere.VCenters {
18+
vcenterDef := typesvsphere.VCenters{
19+
VCenter: vcenter.Server,
20+
Username: vcenter.Username,
21+
Password: vcenter.Password,
22+
}
23+
vcenterList = append(vcenterList, vcenterDef)
24+
}
25+
metadata.VCenters = vcenterList
26+
27+
return metadata
2028
}

pkg/asset/machines/vsphere/capimachines.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ func GenerateMachines(ctx context.Context, clusterID string, config *types.Insta
156156
Object: vsphereMachine,
157157
})
158158

159+
// Need to determine the infrastructure ref since there may be multi vcenters.
160+
clusterName := clusterID
161+
for index, vcenter := range config.Platform.VSphere.VCenters {
162+
if vcenter.Server == providerSpec.Workspace.Server {
163+
clusterName = fmt.Sprintf("%v-%d", clusterID, index)
164+
break
165+
}
166+
}
167+
168+
// Create capi machine for vspheremachine
159169
machine := &capi.Machine{
160170
ObjectMeta: metav1.ObjectMeta{
161171
Namespace: capiutils.Namespace,
@@ -165,7 +175,7 @@ func GenerateMachines(ctx context.Context, clusterID string, config *types.Insta
165175
},
166176
},
167177
Spec: capi.MachineSpec{
168-
ClusterName: clusterID,
178+
ClusterName: clusterName,
169179
Bootstrap: capi.Bootstrap{
170180
DataSecretName: ptr.To(fmt.Sprintf("%s-%s", clusterID, role)),
171181
},
@@ -215,6 +225,15 @@ func GenerateMachines(ctx context.Context, clusterID string, config *types.Insta
215225
Object: bootstrapVSphereMachine,
216226
})
217227

228+
// Need to determine the infrastructure ref since there may be multi vcenters.
229+
clusterName := clusterID
230+
for index, vcenter := range config.Platform.VSphere.VCenters {
231+
if vcenter.Server == bootstrapSpec.Server {
232+
clusterName = fmt.Sprintf("%v-%d", clusterID, index)
233+
break
234+
}
235+
}
236+
218237
bootstrapMachine := &capi.Machine{
219238
ObjectMeta: metav1.ObjectMeta{
220239
Name: bootstrapVSphereMachine.Name,
@@ -223,7 +242,7 @@ func GenerateMachines(ctx context.Context, clusterID string, config *types.Insta
223242
},
224243
},
225244
Spec: capi.MachineSpec{
226-
ClusterName: clusterID,
245+
ClusterName: clusterName,
227246
Bootstrap: capi.Bootstrap{
228247
DataSecretName: ptr.To(fmt.Sprintf("%s-bootstrap", clusterID)),
229248
},

pkg/asset/manifests/aws/cluster.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,13 @@ func GenerateClusterAssets(ic *installconfig.InstallConfig, clusterID *installco
276276

277277
return &capiutils.GenerateClusterAssetsOutput{
278278
Manifests: manifests,
279-
InfrastructureRef: &corev1.ObjectReference{
280-
APIVersion: capa.GroupVersion.String(),
281-
Kind: "AWSCluster",
282-
Name: awsCluster.Name,
283-
Namespace: awsCluster.Namespace,
279+
InfrastructureRefs: []*corev1.ObjectReference{
280+
{
281+
APIVersion: capa.GroupVersion.String(),
282+
Kind: "AWSCluster",
283+
Name: awsCluster.Name,
284+
Namespace: awsCluster.Namespace,
285+
},
284286
},
285287
}, nil
286288
}

pkg/asset/manifests/azure/cluster.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,13 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
208208

209209
return &capiutils.GenerateClusterAssetsOutput{
210210
Manifests: manifests,
211-
InfrastructureRef: &corev1.ObjectReference{
212-
APIVersion: capz.GroupVersion.String(),
213-
Kind: "AzureCluster",
214-
Name: azureCluster.Name,
215-
Namespace: azureCluster.Namespace,
211+
InfrastructureRefs: []*corev1.ObjectReference{
212+
{
213+
APIVersion: capz.GroupVersion.String(),
214+
Kind: "AzureCluster",
215+
Name: azureCluster.Name,
216+
Namespace: azureCluster.Namespace,
217+
},
216218
},
217219
}, nil
218220
}

pkg/asset/manifests/capiutils/manifest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const (
1313

1414
// GenerateClusterAssetsOutput is the output of GenerateClusterAssets.
1515
type GenerateClusterAssetsOutput struct {
16-
Manifests []*asset.RuntimeFile
17-
InfrastructureRef *corev1.ObjectReference
16+
Manifests []*asset.RuntimeFile
17+
InfrastructureRefs []*corev1.ObjectReference
1818
}
1919

2020
// GenerateMachinesOutput is the output of GenerateMachines.

pkg/asset/manifests/cloudproviderconfig.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212
"sigs.k8s.io/yaml"
1313

14+
"github.com/openshift/api/features"
1415
"github.com/openshift/installer/pkg/asset"
1516
"github.com/openshift/installer/pkg/asset/installconfig"
1617
ibmcloudmachines "github.com/openshift/installer/pkg/asset/machines/ibmcloud"
@@ -316,7 +317,15 @@ func (cpc *CloudProviderConfig) Generate(ctx context.Context, dependencies asset
316317
}
317318
cm.Data[cloudProviderConfigDataKey] = powervsConfig
318319
case vspheretypes.Name:
319-
vsphereConfig, err := vspheremanifests.CloudProviderConfigIni(clusterID.InfraID, installConfig.Config.Platform.VSphere)
320+
var vsphereConfig string
321+
var err error
322+
// When we GA multi vcenter, we should only support yaml generation here.
323+
if installConfig.Config.EnabledFeatureGates().Enabled(features.FeatureGateVSphereMultiVCenters) {
324+
vsphereConfig, err = vspheremanifests.CloudProviderConfigYaml(clusterID.InfraID, installConfig.Config.Platform.VSphere)
325+
} else {
326+
vsphereConfig, err = vspheremanifests.CloudProviderConfigIni(clusterID.InfraID, installConfig.Config.Platform.VSphere)
327+
}
328+
320329
if err != nil {
321330
return errors.Wrap(err, "could not create cloud provider config")
322331
}

pkg/asset/manifests/clusterapi/cluster.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/pkg/errors"
10+
"github.com/sirupsen/logrus"
1011
corev1 "k8s.io/api/core/v1"
1112
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1213
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -87,20 +88,6 @@ func (c *Cluster) Generate(_ context.Context, dependencies asset.Parents) error
8788
namespace.SetGroupVersionKind(corev1.SchemeGroupVersion.WithKind("Namespace"))
8889
c.FileList = append(c.FileList, &asset.RuntimeFile{Object: namespace, File: asset.File{Filename: "000_capi-namespace.yaml"}})
8990

90-
cluster := &clusterv1.Cluster{
91-
ObjectMeta: metav1.ObjectMeta{
92-
Name: clusterID.InfraID,
93-
Namespace: capiutils.Namespace,
94-
},
95-
Spec: clusterv1.ClusterSpec{
96-
ClusterNetwork: &clusterv1.ClusterNetwork{
97-
APIServerPort: ptr.To[int32](6443),
98-
},
99-
},
100-
}
101-
cluster.SetGroupVersionKind(clusterv1.GroupVersion.WithKind("Cluster"))
102-
c.FileList = append(c.FileList, &asset.RuntimeFile{Object: cluster, File: asset.File{Filename: "01_capi-cluster.yaml"}})
103-
10491
var out *capiutils.GenerateClusterAssetsOutput
10592
switch platform := installConfig.Config.Platform.Name(); platform {
10693
case awstypes.Name:
@@ -150,12 +137,28 @@ func (c *Cluster) Generate(_ context.Context, dependencies asset.Parents) error
150137
return fmt.Errorf("unsupported platform %q", platform)
151138
}
152139

153-
// Set the infrastructure reference in the Cluster object.
154-
cluster.Spec.InfrastructureRef = out.InfrastructureRef
155-
if cluster.Spec.InfrastructureRef == nil {
140+
if len(out.InfrastructureRefs) == 0 {
156141
return fmt.Errorf("failed to generate manifests: cluster.Spec.InfrastructureRef was never set")
157142
}
158143

144+
logrus.Infof("Adding clusters...")
145+
for index, infra := range out.InfrastructureRefs {
146+
cluster := &clusterv1.Cluster{
147+
ObjectMeta: metav1.ObjectMeta{
148+
Name: infra.Name,
149+
Namespace: capiutils.Namespace,
150+
},
151+
Spec: clusterv1.ClusterSpec{
152+
ClusterNetwork: &clusterv1.ClusterNetwork{
153+
APIServerPort: ptr.To[int32](6443),
154+
},
155+
},
156+
}
157+
cluster.Spec.InfrastructureRef = infra
158+
cluster.SetGroupVersionKind(clusterv1.GroupVersion.WithKind("Cluster"))
159+
c.FileList = append(c.FileList, &asset.RuntimeFile{Object: cluster, File: asset.File{Filename: fmt.Sprintf("01_capi-cluster-%d.yaml", index)}})
160+
}
161+
159162
// Append the infrastructure manifests.
160163
c.FileList = append(c.FileList, out.Manifests...)
161164

pkg/asset/manifests/gcp/cluster.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,13 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
171171

172172
return &capiutils.GenerateClusterAssetsOutput{
173173
Manifests: manifests,
174-
InfrastructureRef: &corev1.ObjectReference{
175-
APIVersion: capg.GroupVersion.String(),
176-
Kind: "GCPCluster",
177-
Name: gcpCluster.Name,
178-
Namespace: gcpCluster.Namespace,
174+
InfrastructureRefs: []*corev1.ObjectReference{
175+
{
176+
APIVersion: capg.GroupVersion.String(),
177+
Kind: "GCPCluster",
178+
Name: gcpCluster.Name,
179+
Namespace: gcpCluster.Namespace,
180+
},
179181
},
180182
}, nil
181183
}

pkg/asset/manifests/nutanix/cluster.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
102102

103103
return &capiutils.GenerateClusterAssetsOutput{
104104
Manifests: manifests,
105-
InfrastructureRef: &corev1.ObjectReference{
106-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
107-
Kind: "NutanixCluster",
108-
Name: clusterID.InfraID,
109-
Namespace: capiutils.Namespace,
105+
InfrastructureRefs: []*corev1.ObjectReference{
106+
{
107+
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
108+
Kind: "NutanixCluster",
109+
Name: clusterID.InfraID,
110+
Namespace: capiutils.Namespace,
111+
},
110112
},
111113
}, nil
112114
}

0 commit comments

Comments
 (0)