1
1
package vsphere
2
2
3
3
import (
4
+ "fmt"
5
+ "strings"
6
+
7
+ "github.com/go-logr/logr"
8
+ configv1 "github.com/openshift/api/config/v1"
4
9
corev1 "k8s.io/api/core/v1"
5
10
)
6
11
7
12
// Platform stores any global configuration used for vSphere platforms.
8
13
type Platform struct {
9
14
// VCenter is the domain name or IP address of the vCenter.
10
- VCenter string `json:"vCenter"`
15
+ // Deprecated: Please use Platform.VSphere instead
16
+ // See also: Platform.ConvertDeprecatedFields
17
+ // +optional
18
+ VCenter string `json:"vCenter,omitempty"`
11
19
12
20
// CredentialsSecretRef refers to a secret that contains the vSphere account access
13
21
// credentials: GOVC_USERNAME, GOVC_PASSWORD fields.
@@ -18,18 +26,95 @@ type Platform struct {
18
26
CertificatesSecretRef corev1.LocalObjectReference `json:"certificatesSecretRef"`
19
27
20
28
// Datacenter is the name of the datacenter to use in the vCenter.
21
- Datacenter string `json:"datacenter"`
29
+ // Deprecated: Please use Platform.VSphere instead
30
+ // See also: Platform.ConvertDeprecatedFields
31
+ // +optional
32
+ Datacenter string `json:"datacenter,omitempty"`
22
33
23
34
// DefaultDatastore is the default datastore to use for provisioning volumes.
24
- DefaultDatastore string `json:"defaultDatastore"`
35
+ // Deprecated: Please use Platform.VSphere instead
36
+ // See also: Platform.ConvertDeprecatedFields
37
+ // +optional
38
+ DefaultDatastore string `json:"defaultDatastore,omitempty"`
25
39
26
40
// Folder is the name of the folder that will be used and/or created for
27
41
// virtual machines.
42
+ // Deprecated: Please use Platform.VSphere instead
43
+ // See also: Platform.ConvertDeprecatedFields
44
+ // +optional
28
45
Folder string `json:"folder,omitempty"`
29
46
30
47
// Cluster is the name of the cluster virtual machines will be cloned into.
48
+ // Deprecated: Please use Platform.VSphere instead
49
+ // See also: Platform.ConvertDeprecatedFields
50
+ // +optional
31
51
Cluster string `json:"cluster,omitempty"`
32
52
33
53
// Network specifies the name of the network to be used by the cluster.
54
+ // Deprecated: Please use Platform.VSphere instead
55
+ // See also: Platform.ConvertDeprecatedFields
56
+ // +optional
34
57
Network string `json:"network,omitempty"`
58
+
59
+ // VSphere is the full spec of the vSphere platform.
60
+ VSphere * configv1.VSpherePlatformSpec `json:"vSphere,omitempty"`
61
+ }
62
+
63
+ func (p * Platform ) ConvertDeprecatedFields (logger logr.Logger ) {
64
+ if p .VSphere != nil {
65
+ return
66
+ }
67
+
68
+ p .VSphere = & configv1.VSpherePlatformSpec {
69
+ VCenters : []configv1.VSpherePlatformVCenterSpec {
70
+ {
71
+ Server : p .VCenter ,
72
+ Port : 443 ,
73
+ Datacenters : []string {p .Datacenter },
74
+ },
75
+ },
76
+ FailureDomains : []configv1.VSpherePlatformFailureDomainSpec {
77
+ {
78
+ // names from https://github.com/openshift/installer/blob/f7731922a0f17a8339a3e837f72898ac77643611/pkg/types/vsphere/conversion/installconfig.go#L58-L61
79
+ Name : "generated-failure-domain" ,
80
+ Region : "generated-region" ,
81
+ Zone : "generated-zone" ,
82
+ Server : p .VCenter ,
83
+ Topology : configv1.VSpherePlatformTopology {
84
+ Datacenter : p .Datacenter ,
85
+ Datastore : setDatastorePath (p .DefaultDatastore , p .Datacenter , logger ),
86
+ Folder : setFolderPath (p .Folder , p .Datacenter , logger ),
87
+ ComputeCluster : setComputeClusterPath (p .Cluster , p .Datacenter , logger ),
88
+ Networks : []string {p .Network },
89
+ },
90
+ },
91
+ },
92
+ }
93
+
94
+ }
95
+
96
+ // Copied (and slightly modified) from https://github.com/openshift/installer/blob/f7731922a0f17a8339a3e837f72898ac77643611/pkg/types/vsphere/conversion/installconfig.go#L75-L97
97
+
98
+ func setComputeClusterPath (cluster , datacenter string , logger logr.Logger ) string {
99
+ if cluster != "" && ! strings .HasPrefix (cluster , "/" ) {
100
+ logger .V (1 ).Info (fmt .Sprintf ("computeCluster as a non-path is now depreciated please use the form: /%s/host/%s" , datacenter , cluster ))
101
+ return fmt .Sprintf ("/%s/host/%s" , datacenter , cluster )
102
+ }
103
+ return cluster
104
+ }
105
+
106
+ func setDatastorePath (datastore , datacenter string , logger logr.Logger ) string {
107
+ if datastore != "" && ! strings .HasPrefix (datastore , "/" ) {
108
+ logger .V (1 ).Info (fmt .Sprintf ("datastore as a non-path is now depreciated please use the form: /%s/datastore/%s" , datacenter , datastore ))
109
+ return fmt .Sprintf ("/%s/datastore/%s" , datacenter , datastore )
110
+ }
111
+ return datastore
112
+ }
113
+
114
+ func setFolderPath (folder , datacenter string , logger logr.Logger ) string {
115
+ if folder != "" && ! strings .HasPrefix (folder , "/" ) {
116
+ logger .V (1 ).Info (fmt .Sprintf ("folder as a non-path is now depreciated please use the form: /%s/vm/%s" , datacenter , folder ))
117
+ return fmt .Sprintf ("/%s/vm/%s" , datacenter , folder )
118
+ }
119
+ return folder
35
120
}
0 commit comments