Skip to content

Commit 361a725

Browse files
committed
enables storage policy in failure domain and disables cluster module creation when failure domain is used
1 parent a2bac7b commit 361a725

File tree

9 files changed

+52
-1
lines changed

9 files changed

+52
-1
lines changed

apis/v1alpha3/vspherefailuredomain_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ type Topology struct {
7878
// virtual machine is created/located.
7979
// +optional
8080
Datastore string `json:"datastore,omitempty"`
81+
82+
// StoragePolicy is the name of the policy that is used to target a datastore
83+
// in which the virtual machine is created/located
84+
// +optional
85+
StoragePolicy string `json:"storagePolicy,omitempty"`
8186
}
8287

8388
type FailureDomainHosts struct {

apis/v1alpha3/zz_generated.conversion.go

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

apis/v1alpha4/vspherefailuredomain_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ type Topology struct {
7979
// virtual machine is created/located.
8080
// +optional
8181
Datastore string `json:"datastore,omitempty"`
82+
83+
// StoragePolicy is the name of the policy that is used to target a datastore
84+
// in which the virtual machine is created/located
85+
// +optional
86+
StoragePolicy string `json:"storagePolicy,omitempty"`
8287
}
8388

8489
type FailureDomainHosts struct {

apis/v1alpha4/zz_generated.conversion.go

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

apis/v1beta1/vspherefailuredomain_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ type Topology struct {
8585
// virtual machine is created/located.
8686
// +optional
8787
Datastore string `json:"datastore,omitempty"`
88+
89+
// StoragePolicy is the name of the policy that is used to target a datastore
90+
// in which the virtual machine is created/located
91+
// +optional
92+
StoragePolicy string `json:"storagePolicy,omitempty"`
8893
}
8994

9095
// FailureDomainHosts has information required for placement of machines on VSphere hosts.

config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspherefailuredomains.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ spec:
109109
items:
110110
type: string
111111
type: array
112+
storagePolicy:
113+
description: |-
114+
StoragePolicy is the name of the policy that is used to target a datastore
115+
in which the virtual machine is created/located
116+
type: string
112117
required:
113118
- datacenter
114119
type: object
@@ -240,6 +245,11 @@ spec:
240245
items:
241246
type: string
242247
type: array
248+
storagePolicy:
249+
description: |-
250+
StoragePolicy is the name of the policy that is used to target a datastore
251+
in which the virtual machine is created/located
252+
type: string
243253
required:
244254
- datacenter
245255
type: object
@@ -368,6 +378,11 @@ spec:
368378
items:
369379
type: string
370380
type: array
381+
storagePolicy:
382+
description: |-
383+
StoragePolicy is the name of the policy that is used to target a datastore
384+
in which the virtual machine is created/located
385+
type: string
371386
required:
372387
- datacenter
373388
type: object

controllers/vspherecluster_reconciler.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,12 @@ func (r *clusterReconciler) reconcileDeploymentZones(ctx context.Context, cluste
359359
}
360360

361361
func (r *clusterReconciler) reconcileClusterModules(ctx context.Context, clusterCtx *capvcontext.ClusterContext) (reconcile.Result, error) {
362-
if feature.Gates.Enabled(feature.NodeAntiAffinity) {
362+
// We want to enable cluster module only when NodeAntiAffinity flag is true and failure domains are not used.
363+
// When failure domain is used and an empty value is passed for data center or the resource pool in a vm template,
364+
// cluster module creation will fail as there are no values in dc or resource pool.
365+
// These values in the vm template gets replaced at a later stage by the values in the failure domain.
366+
// When failure domain is used, we do not need the cluster module
367+
if feature.Gates.Enabled(feature.NodeAntiAffinity) && clusterCtx.VSphereCluster.Spec.FailureDomainSelector == nil {
363368
return r.clusterModuleReconciler.Reconcile(ctx, clusterCtx)
364369
}
365370
return reconcile.Result{}, nil

internal/webhooks/vspherefailuredomain.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func (webhook *VSphereFailureDomainWebhook) ValidateCreate(_ context.Context, ra
6161
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "Topology", "ComputeCluster"), "cannot be empty if Hosts is not empty"))
6262
}
6363

64+
// We should either pass a datastore or a storage policy, not both at the same time
65+
if obj.Spec.Topology.Datastore != "" && obj.Spec.Topology.StoragePolicy != "" {
66+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "Topology", "Datastore"), "should be empty if StoragePolicy is not empty"))
67+
}
68+
6469
if obj.Spec.Region.Type == infrav1.HostGroupFailureDomain {
6570
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "Region", "Type"), fmt.Sprintf("region's Failure Domain type cannot be %s", obj.Spec.Region.Type)))
6671
}
@@ -93,6 +98,10 @@ func (webhook *VSphereFailureDomainWebhook) ValidateUpdate(_ context.Context, ol
9398
if !reflect.DeepEqual(newTyped.Spec, oldTyped.Spec) {
9499
return nil, field.Forbidden(field.NewPath("spec"), "VSphereFailureDomainSpec is immutable")
95100
}
101+
// We should either pass a datastore or a storage policy, not both at the same time
102+
if newTyped.Spec.Topology.Datastore != "" && newTyped.Spec.Topology.StoragePolicy != "" {
103+
return nil, field.Forbidden(field.NewPath("spec", "Topology", "Datastore"), "should be empty if StoragePolicy is not empty")
104+
}
96105
return nil, nil
97106
}
98107

pkg/services/vimmachine.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ func (v *VimMachineService) generateOverrideFunc(ctx context.Context, vimMachine
432432
if vsphereDeploymentZone.Spec.PlacementConstraint.ResourcePool != "" {
433433
vm.Spec.ResourcePool = vsphereDeploymentZone.Spec.PlacementConstraint.ResourcePool
434434
}
435+
if vsphereFailureDomain.Spec.Topology.StoragePolicy != "" {
436+
vm.Spec.StoragePolicyName = vsphereFailureDomain.Spec.Topology.StoragePolicy
437+
}
435438
if vsphereFailureDomain.Spec.Topology.Datastore != "" {
436439
vm.Spec.Datastore = vsphereFailureDomain.Spec.Topology.Datastore
437440
}

0 commit comments

Comments
 (0)