/
vsphere.go
147 lines (124 loc) · 4.05 KB
/
vsphere.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package clusterresource
import (
"fmt"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
installertypes "github.com/openshift/installer/pkg/types"
installervsphere "github.com/openshift/installer/pkg/types/vsphere"
hivev1 "github.com/openshift/hive/apis/hive/v1"
hivev1vsphere "github.com/openshift/hive/apis/hive/v1/vsphere"
"github.com/openshift/hive/pkg/constants"
)
var _ CloudBuilder = (*VSphereCloudBuilder)(nil)
// VSphereCloudBuilder encapsulates cluster artifact generation logic specific to vSphere.
type VSphereCloudBuilder struct {
// VCenter is the domain name or IP address of the vCenter.
VCenter string
// Username is the name of the user to use to connect to the vCenter.
Username string
// Password is the password for the user to use to connect to the vCenter.
Password string
// Datacenter is the name of the datacenter to use in the vCenter.
Datacenter string
// DefaultDatastore is the default datastore to use for provisioning volumes.
DefaultDatastore string
// Folder is the name of the folder that will be used and/or created for
// virtual machines.
Folder string
// Cluster is the name of the cluster virtual machines will be cloned into.
Cluster string
// APIVIP is the virtual IP address for the api endpoint
APIVIP string
// IngressVIP is the virtual IP address for ingress
IngressVIP string
// Network specifies the name of the network to be used by the cluster.
Network string
// CACert is the CA certificate(s) used to communicate with the vCenter.
CACert []byte
}
func (p *VSphereCloudBuilder) GenerateCredentialsSecret(o *Builder) *corev1.Secret {
return &corev1.Secret{
TypeMeta: metav1.TypeMeta{
Kind: "Secret",
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: p.CredsSecretName(o),
Namespace: o.Namespace,
},
Type: corev1.SecretTypeOpaque,
StringData: map[string]string{
constants.UsernameSecretKey: p.Username,
constants.PasswordSecretKey: p.Password,
},
}
}
func (p *VSphereCloudBuilder) GenerateCloudObjects(o *Builder) []runtime.Object {
return []runtime.Object{
&corev1.Secret{
TypeMeta: metav1.TypeMeta{
Kind: "Secret",
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: p.certificatesSecretName(o),
Namespace: o.Namespace,
},
Type: corev1.SecretTypeOpaque,
Data: map[string][]byte{
".cacert": p.CACert,
},
},
}
}
func (p *VSphereCloudBuilder) GetCloudPlatform(o *Builder) hivev1.Platform {
return hivev1.Platform{
VSphere: &hivev1vsphere.Platform{
CredentialsSecretRef: corev1.LocalObjectReference{
Name: p.CredsSecretName(o),
},
CertificatesSecretRef: corev1.LocalObjectReference{
Name: p.certificatesSecretName(o),
},
VCenter: p.VCenter,
Datacenter: p.Datacenter,
DefaultDatastore: p.DefaultDatastore,
Folder: p.Folder,
Cluster: p.Cluster,
Network: p.Network,
},
}
}
func (p *VSphereCloudBuilder) addMachinePoolPlatform(o *Builder, mp *hivev1.MachinePool) {
mp.Spec.Platform.VSphere = &hivev1vsphere.MachinePool{
NumCPUs: 2,
NumCoresPerSocket: 1,
MemoryMiB: 8192,
OSDisk: hivev1vsphere.OSDisk{
DiskSizeGB: 120,
},
}
}
func (p *VSphereCloudBuilder) addInstallConfigPlatform(o *Builder, ic *installertypes.InstallConfig) {
ic.Platform = installertypes.Platform{
VSphere: &installervsphere.Platform{
VCenter: p.VCenter,
Username: p.Username,
Password: p.Password,
Datacenter: p.Datacenter,
DefaultDatastore: p.DefaultDatastore,
Folder: p.Folder,
Cluster: p.Cluster,
APIVIP: p.APIVIP,
IngressVIP: p.IngressVIP,
Network: p.Network,
},
}
}
func (p *VSphereCloudBuilder) CredsSecretName(o *Builder) string {
return fmt.Sprintf("%s-vsphere-creds", o.Name)
}
func (p *VSphereCloudBuilder) certificatesSecretName(o *Builder) string {
return fmt.Sprintf("%s-vsphere-certs", o.Name)
}