@@ -2,6 +2,7 @@ package createcluster
2
2
3
3
import (
4
4
"bytes"
5
+ "encoding/json"
5
6
"fmt"
6
7
"os"
7
8
"os/user"
@@ -32,6 +33,7 @@ import (
32
33
"github.com/openshift/hive/pkg/gcpclient"
33
34
"github.com/openshift/hive/pkg/util/scheme"
34
35
installertypes "github.com/openshift/installer/pkg/types"
36
+ installervsphere "github.com/openshift/installer/pkg/types/vsphere"
35
37
"github.com/openshift/installer/pkg/validate"
36
38
)
37
39
@@ -208,6 +210,7 @@ type Options struct {
208
210
VSphereAPIVIP string
209
211
VSphereIngressVIP string
210
212
VSphereNetwork string
213
+ VSpherePlatformSpecJSON string
211
214
VSphereCACerts string
212
215
213
216
// Ovirt
@@ -380,6 +383,7 @@ OpenShift Installer publishes all the services of the cluster like API server an
380
383
flags .StringVar (& opt .VSphereAPIVIP , "vsphere-api-vip" , "" , "Virtual IP address for the api endpoint" )
381
384
flags .StringVar (& opt .VSphereIngressVIP , "vsphere-ingress-vip" , "" , "Virtual IP address for ingress application routing" )
382
385
flags .StringVar (& opt .VSphereNetwork , "vsphere-network" , "" , "Name of the network to be used by the cluster" )
386
+ flags .StringVar (& opt .VSpherePlatformSpecJSON , "vsphere-platform-spec-json" , "" , "Installer vsphere platform spec, encoded as JSON" )
383
387
flags .StringVar (& opt .VSphereCACerts , "vsphere-ca-certs" , "" , "Path to vSphere CA certificate, multiple CA paths can be : delimited" )
384
388
385
389
// Nutanix
@@ -786,22 +790,52 @@ func (o *Options) GenerateObjects() ([]runtime.Object, error) {
786
790
if o .VSphereDatacenter != "" {
787
791
vSphereDatacenter = o .VSphereDatacenter
788
792
}
789
- if vSphereDatacenter == "" {
790
- return nil , fmt .Errorf ("must provide --vsphere-datacenter or set %s env var" , constants .VSphereDataCenterEnvVar )
791
- }
792
793
793
794
vSphereDatastore := os .Getenv (constants .VSphereDataStoreEnvVar )
794
795
if o .VSphereDefaultDataStore != "" {
795
796
vSphereDatastore = o .VSphereDefaultDataStore
796
797
}
797
- if vSphereDatastore == "" {
798
- return nil , fmt .Errorf ("must provide --vsphere-default-datastore or set %s env var" , constants .VSphereDataStoreEnvVar )
799
- }
800
798
801
799
vSphereVCenter := os .Getenv (constants .VSphereVCenterEnvVar )
802
800
if o .VSphereVCenter != "" {
803
801
vSphereVCenter = o .VSphereVCenter
804
802
}
803
+
804
+ vSphereFolder := o .VSphereFolder
805
+ vSphereCluster := o .VSphereCluster
806
+ vSphereAPIVIP := o .VSphereAPIVIP
807
+ vSphereIngressVIP := o .VSphereIngressVIP
808
+
809
+ platformBytes := []byte (os .Getenv (constants .VSpherePlatformSpecJSONEnvVar ))
810
+ if o .VSpherePlatformSpecJSON != "" {
811
+ platformBytes = []byte (o .VSpherePlatformSpecJSON )
812
+ }
813
+
814
+ if len (platformBytes ) > 0 {
815
+ o .log .Info ("using provided installer platform spec instead of other flags for vsphere (size: %v)" , len (platformBytes ))
816
+ platform := installervsphere.Platform {}
817
+ err = json .Unmarshal (platformBytes , & platform )
818
+ if err != nil {
819
+ return nil , fmt .Errorf ("error decoding platform %s: %w" , o .VSpherePlatformSpecJSON , err )
820
+ }
821
+
822
+ vSphereVCenter = platform .VCenters [0 ].Server
823
+ vSphereDatacenter = platform .VCenters [0 ].Datacenters [0 ]
824
+ if vSphereDatacenter == "" {
825
+ vSphereDatacenter = platform .FailureDomains [0 ].Topology .Datacenter
826
+ }
827
+ vSphereDatastore = platform .FailureDomains [0 ].Topology .Datastore
828
+ vSphereFolder = platform .FailureDomains [0 ].Topology .Folder
829
+ vSphereCluster = platform .FailureDomains [0 ].Topology .ComputeCluster
830
+ vSphereNetwork = platform .FailureDomains [0 ].Topology .Networks [0 ]
831
+ }
832
+
833
+ if vSphereDatacenter == "" {
834
+ return nil , fmt .Errorf ("must provide --vsphere-datacenter or set %s env var" , constants .VSphereDataCenterEnvVar )
835
+ }
836
+ if vSphereDatastore == "" {
837
+ return nil , fmt .Errorf ("must provide --vsphere-default-datastore or set %s env var" , constants .VSphereDataStoreEnvVar )
838
+ }
805
839
if vSphereVCenter == "" {
806
840
return nil , fmt .Errorf ("must provide --vsphere-vcenter or set %s env var" , constants .VSphereVCenterEnvVar )
807
841
}
@@ -812,10 +846,10 @@ func (o *Options) GenerateObjects() ([]runtime.Object, error) {
812
846
Password : vspherePassword ,
813
847
Datacenter : vSphereDatacenter ,
814
848
DefaultDatastore : vSphereDatastore ,
815
- Folder : o . VSphereFolder ,
816
- Cluster : o . VSphereCluster ,
817
- APIVIP : o . VSphereAPIVIP ,
818
- IngressVIP : o . VSphereIngressVIP ,
849
+ Folder : vSphereFolder ,
850
+ Cluster : vSphereCluster ,
851
+ APIVIP : vSphereAPIVIP ,
852
+ IngressVIP : vSphereIngressVIP ,
819
853
Network : vSphereNetwork ,
820
854
CACert : bytes .Join (caCerts , []byte ("\n " )),
821
855
}
0 commit comments