Skip to content

Commit 5a40e4e

Browse files
committed
Centralize dstore/pool/folder in CCM config
This patch moves the machine config properties for datastore, resource pool, and folder into the cluster's cloud provider configuration. CAPV cannot deploy clusters that do not use the vSphere cloud provider anyway due to the way ready state is determined by the node ref controller.
1 parent 03ca46a commit 5a40e4e

File tree

14 files changed

+20
-87
lines changed

14 files changed

+20
-87
lines changed

cmd/clusterctl/examples/vsphere/cluster.yaml.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ spec:
2424
secretNamespace: "kube-system"
2525
virtualCenter:
2626
"${VSPHERE_SERVER}":
27+
datacenters: "${VSPHERE_DATACENTER}"
2728
network:
2829
name: "${VSPHERE_NETWORK}"
2930
workspace:

cmd/clusterctl/examples/vsphere/machines.yaml.template

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ items:
1313
apiVersion: vsphere.cluster.k8s.io/v1alpha1
1414
kind: VsphereMachineProviderSpec
1515
datacenter: "${VSPHERE_DATACENTER}"
16-
datastore: "${VSPHERE_DATASTORE}"
17-
resourcePool: "${VSPHERE_RESOURCE_POOL}"
18-
folder: "${VSPHERE_FOLDER}"
1916
network:
2017
devices:
2118
- networkName: "${VSPHERE_NETWORK}"

cmd/clusterctl/examples/vsphere/machineset.yaml.template

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ spec:
2222
apiVersion: vsphere.cluster.k8s.io/v1alpha1
2323
kind: VsphereMachineProviderSpec
2424
datacenter: "${VSPHERE_DATACENTER}"
25-
datastore: "${VSPHERE_DATASTORE}"
26-
resourcePool: "${VSPHERE_RESOURCE_POOL}"
27-
folder: "${VSPHERE_FOLDER}"
2825
network:
2926
devices:
3027
- networkName: "${VSPHERE_NETWORK}"

config/crds/vsphere_v1alpha1_vspheremachineproviderspec.yaml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,12 @@ spec:
2323
description: Datacenter is the name or inventory path of the datacenter
2424
where this machine's VM is created/located.
2525
type: string
26-
datastore:
27-
description: Datastore is the name or inventory path of the datastore where
28-
this machine's VM is created/located. When omitted, GoVmomi's DatastoreOrDefault
29-
method is used to determine the default datastore. It is recommended to
30-
explicitly set this value.
31-
type: string
3226
diskGiB:
3327
description: DiskGiB is the size of a virtual machine's disk, in GiB. Defaults
3428
to the analogue property value in the template from which this machine
3529
is cloned.
3630
format: int32
3731
type: integer
38-
folder:
39-
description: Folder is the name or inventory path of the folder where this
40-
machine's VM is created/located. When omitted, GoVmomi's FolderOrDefault
41-
method is used to determine the default folder. It is recommended to explicitly
42-
set this value.
43-
type: string
4432
kind:
4533
description: 'Kind is a string value representing the REST resource this
4634
object represents. Servers may infer this from the endpoint the client
@@ -342,7 +330,7 @@ spec:
342330
properties:
343331
devices:
344332
description: Devices is the list of network devices used by the virtual
345-
machine.
333+
machine. TODO(akutz) Make sure at least one network matches the ClusterSpec.CloudProviderConfiguration.Network.Name
346334
items:
347335
properties:
348336
dhcp4:
@@ -469,12 +457,6 @@ spec:
469457
template from which this machine is cloned.
470458
format: int32
471459
type: integer
472-
resourcePool:
473-
description: ResourcePool is the name or inventory path of the resource
474-
pool where this machine's VM is created/located. When omitted, GoVmomi's
475-
ResourcePoolOrDefault method is used to determine the default resource
476-
pool. It is recommended to explicitly set this value.
477-
type: string
478460
template:
479461
description: Template is the name, inventory path, or instance UUID of the
480462
template used to clone new machines.

pkg/apis/vsphere/v1alpha1/cloud/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type Config struct {
2929

3030
// Network is the vSphere cloud provider's network configuration.
3131
// +optional
32-
Network NetworConfig `gcfg:"Network,omitempty" json:"network,omitempty"`
32+
Network NetworkConfig `gcfg:"Network,omitempty" json:"network,omitempty"`
3333

3434
// Disk is the vSphere cloud provider's disk configuration.
3535
// +optional
@@ -148,8 +148,8 @@ type VCenterConfig struct {
148148
Thumbprint string `gcfg:"thumbprint,omitempty" json:"thumbprint,omitempty"`
149149
}
150150

151-
// NetworConfig is the network configuration for the vSphere cloud provider.
152-
type NetworConfig struct {
151+
// NetworkConfig is the network configuration for the vSphere cloud provider.
152+
type NetworkConfig struct {
153153
// Name is the name of the network to which VMs are connected.
154154
// +optional
155155
Name string `gcfg:"public-network,omitempty" json:"name,omitempty"`

pkg/apis/vsphere/v1alpha1/cloud/zz_generated.deepcopy.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/vsphere/v1alpha1/vspheremachineproviderspec_types.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,6 @@ type VsphereMachineProviderSpec struct {
4343
// Datacenter is the name or inventory path of the datacenter where this
4444
// machine's VM is created/located.
4545
Datacenter string `json:"datacenter"`
46-
// Datastore is the name or inventory path of the datastore where this
47-
// machine's VM is created/located.
48-
// When omitted, GoVmomi's DatastoreOrDefault method is used to determine
49-
// the default datastore. It is recommended to explicitly set this value.
50-
// +optional
51-
Datastore string `json:"datastore,omitempty"`
52-
// ResourcePool is the name or inventory path of the resource pool where this
53-
// machine's VM is created/located.
54-
// When omitted, GoVmomi's ResourcePoolOrDefault method is used to determine
55-
// the default resource pool. It is recommended to explicitly set this value.
56-
// +optional
57-
ResourcePool string `json:"resourcePool,omitempty"`
58-
// Folder is the name or inventory path of the folder where this
59-
// machine's VM is created/located.
60-
// When omitted, GoVmomi's FolderOrDefault method is used to determine
61-
// the default folder. It is recommended to explicitly set this value.
62-
// +optional
63-
Folder string `json:"folder,omitempty"`
6446

6547
// Network is the network configuration for this machine's VM.
6648
Network NetworkSpec `json:"network"`
@@ -115,6 +97,8 @@ type KubeadmConfiguration struct {
11597
// NetworkSpec defines the virtual machine's network configuration.
11698
type NetworkSpec struct {
11799
// Devices is the list of network devices used by the virtual machine.
100+
// TODO(akutz) Make sure at least one network matches the
101+
// ClusterSpec.CloudProviderConfiguration.Network.Name
118102
Devices []NetworkDeviceSpec `json:"devices"`
119103

120104
// Routes is a list of optional, static routes applied to the virtual

pkg/apis/vsphere/v1alpha1/vspheremachineproviderspec_types_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ func TestStorageVsphereMachineProviderSpec(t *testing.T) {
3535
Name: "foo",
3636
Namespace: "default",
3737
},
38-
MachineRef: "ref123",
39-
Datacenter: "dc1",
40-
Datastore: "ds1",
41-
ResourcePool: "rp1",
38+
MachineRef: "ref123",
39+
Datacenter: "dc1",
4240
Network: NetworkSpec{
4341
Devices: []NetworkDeviceSpec{
4442
{

pkg/cloud/vsphere/services/govmomi/create_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ func TestCreate(t *testing.T) {
118118
TypeMeta: metav1.TypeMeta{
119119
APIVersion: "vsphereproviderconfig/v1alpha1",
120120
},
121-
Datacenter: "",
122-
Datastore: "",
123-
ResourcePool: "",
124-
Folder: "",
121+
Datacenter: "",
125122
Network: v1alpha1.NetworkSpec{
126123
Devices: []v1alpha1.NetworkDeviceSpec{
127124
{

pkg/cloud/vsphere/services/govmomi/vcenter/clone.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ func Clone(ctx *context.MachineContext, userData []byte) error {
4343
return err
4444
}
4545

46-
folder, err := ctx.Session.Finder.FolderOrDefault(ctx, ctx.MachineConfig.Folder)
46+
folder, err := ctx.Session.Finder.FolderOrDefault(ctx, ctx.ClusterConfig.CloudProviderConfiguration.Workspace.Folder)
4747
if err != nil {
4848
return errors.Wrapf(err, "unable to get folder for %q", ctx)
4949
}
5050

51-
datastore, err := ctx.Session.Finder.DatastoreOrDefault(ctx, ctx.MachineConfig.Datastore)
51+
datastore, err := ctx.Session.Finder.DatastoreOrDefault(ctx, ctx.ClusterConfig.CloudProviderConfiguration.Workspace.Datastore)
5252
if err != nil {
5353
return errors.Wrapf(err, "unable to get datastore for %q", ctx)
5454
}
5555

56-
pool, err := ctx.Session.Finder.ResourcePoolOrDefault(ctx, ctx.MachineConfig.ResourcePool)
56+
pool, err := ctx.Session.Finder.ResourcePoolOrDefault(ctx, ctx.ClusterConfig.CloudProviderConfiguration.Workspace.ResourcePool)
5757
if err != nil {
5858
return errors.Wrapf(err, "unable to get resource pool for %q", ctx)
5959
}

0 commit comments

Comments
 (0)