Skip to content

Commit 7e1a78f

Browse files
authored
Merge pull request #1208 from srm09/feature-0.7/failure-domain
Multi AZ failure domain support
2 parents c53f0be + 626ec21 commit 7e1a78f

File tree

68 files changed

+4472
-136
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+4472
-136
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ help: ## Display this help
106106
## --------------------------------------
107107

108108
.PHONY: test
109-
test: generate lint-go ## Run tests
110-
source ./hack/fetch_ext_bins.sh; fetch_tools; setup_envs; go test -v ./api/... ./controllers/... ./pkg/...
109+
test: $(GOVC)
110+
$(MAKE) generate lint-go
111+
source ./hack/fetch_ext_bins.sh; fetch_tools; setup_envs; export GOVC_BIN_PATH=$(GOVC); go test -v ./api/... ./controllers/... ./pkg/...
111112

112113
.PHONY: e2e-image
113114
e2e-image: ## Build the e2e manager image

PROJECT

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ resources:
2626
- group: infrastructure
2727
version: v1alpha3
2828
kind: HAProxyLoadBalancer
29-
29+
- group: infrastructure
30+
version: v1alpha3
31+
kind: VSphereFailureDomain
32+
- group: infrastructure
33+
version: v1alpha3
34+
kind: VSphereDeploymentZone

api/v1alpha2/vspherecluster_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (src *VSphereCluster) ConvertTo(dstRaw conversion.Hub) error { // nolint
6565
}
6666

6767
dst.Status.Conditions = restored.Status.Conditions
68+
dst.Status.FailureDomains = restored.Status.FailureDomains
6869

6970
return nil
7071
}

api/v1alpha2/vspheremachine_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (src *VSphereMachine) ConvertTo(dstRaw conversion.Hub) error { // nolint
3838

3939
dst.Spec.VirtualMachineCloneSpec = restored.Spec.VirtualMachineCloneSpec
4040
dst.Status.Conditions = restored.Status.Conditions
41+
dst.Spec.FailureDomain = restored.Spec.FailureDomain
4142

4243
return nil
4344
}

api/v1alpha2/vspheremachinetemplate_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func (src *VSphereMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { // n
3737
}
3838

3939
dst.Spec.Template.Spec.VirtualMachineCloneSpec = restored.Spec.Template.Spec.VirtualMachineCloneSpec
40+
dst.Spec.Template.Spec.FailureDomain = restored.Spec.Template.Spec.FailureDomain
4041

4142
return nil
4243
}

api/v1alpha2/zz_generated.conversion.go

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

api/v1alpha3/condition_consts.go

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ const (
4747
// while installing the container storage interface addon; those kind of errors are usually transient
4848
// the operation is automatically re-tried by the controller.
4949
CSIProvisioningFailedReason = "CSIProvisioningFailed"
50+
51+
// FailureDomainsAvailableCondition documents the status of the failure domains
52+
// associated to the VSphereCluster.
53+
FailureDomainsAvailableCondition clusterv1.ConditionType = "FailureDomainsAvailable"
54+
55+
// FailureDomainsSkippedReason (Severity=Info) documents that some of the failure domain statuses
56+
// associated to the VSphereCluster are reported as not ready.
57+
FailureDomainsSkippedReason = "FailureDomainsSkipped"
58+
59+
// WaitingForFailureDomainStatusReason (Severity=Info) documents that some of the failure domains
60+
// associated to the VSphereCluster are not reporting the Ready status.
61+
// Instead of reporting a false ready status, these failure domains are still under the process of reconciling
62+
// and hence not yet reporting their status.
63+
WaitingForFailureDomainStatusReason = "WaitingForFailureDomainStatus"
5064
)
5165

5266
// Conditions and condition Reasons for the VSphereMachine and the VSphereVM object.
@@ -105,13 +119,15 @@ const (
105119

106120
const (
107121
// VCenterAvailableCondition documents the connectivity with vcenter
108-
// for a given VSphereCluster
122+
// for a given resource
109123
VCenterAvailableCondition clusterv1.ConditionType = "VCenterAvailable"
110124

111-
// VCenterUnreachableReason (Severity=Error) documents a VSphereCluster controller detecting
112-
// issues with VCenter reachability;
125+
// VCenterUnreachableReason (Severity=Error) documents a controller detecting
126+
// issues with VCenter reachability
113127
VCenterUnreachableReason = "VCenterUnreachable"
128+
)
114129

130+
const (
115131
// CredentialsAvailableCondidtion is used by VSphereClusterIdentity when a credential secret is available and unused by other VSphereClusterIdentities
116132
CredentialsAvailableCondidtion clusterv1.ConditionType = "CredentialsAvailable"
117133

@@ -124,3 +140,48 @@ const (
124140
// SecretAlreadyInUseReason is used when another VSphereClusterIdentity is using the secret
125141
SecretAlreadyInUseReason = "SecretInUse"
126142
)
143+
144+
const (
145+
// PlacementConstraintMetCondition documents whether the placement constraint is configured correctly or not.
146+
PlacementConstraintMetCondition clusterv1.ConditionType = "PlacementConstraintMet"
147+
148+
// ResourcePoolNotFoundReason (Severity=Error) documents that the resource pool in the placement constraint
149+
// associated to the VSphereDeploymentZone is misconfigured.
150+
ResourcePoolNotFoundReason = "ResourcePoolNotFound"
151+
152+
// FolderNotFoundReason (Severity=Error) documents that the folder in the placement constraint
153+
// associated to the VSphereDeploymentZone is misconfigured.
154+
FolderNotFoundReason = "FolderNotFound"
155+
)
156+
157+
const (
158+
// VSphereFailureDomainValidatedCondition documents whether the failure domain for the deployment zone is configured correctly or not.
159+
VSphereFailureDomainValidatedCondition clusterv1.ConditionType = "VSphereFailureDomainValidated"
160+
161+
// RegionMisconfiguredReason (Severity=Error) documents that the region for the Failure Domain associated to
162+
// the VSphereDeploymentZone is misconfigured.
163+
RegionMisconfiguredReason = "FailureDomainRegionMisconfigured"
164+
165+
// ZoneMisconfiguredReason (Severity=Error) documents that the zone for the Failure Domain associated to
166+
// the VSphereDeploymentZone is misconfigured.
167+
ZoneMisconfiguredReason = "FailureDomainZoneMisconfigured"
168+
169+
// ComputeClusterNotFoundReason (Severity=Error) documents that the Compute Cluster for the Failure Domain
170+
// associated to the VSphereDeploymentZone cannot be found.
171+
ComputeClusterNotFoundReason = "ComputeClusterNotFound"
172+
173+
// HostsMisconfiguredReason (Severity=Error) documents that the VM & Host Group details for the Failure Domain
174+
// associated to the VSphereDeploymentZone are misconfigured.
175+
HostsMisconfiguredReason = "HostsMisconfigured"
176+
177+
// HostsAffinityMisconfiguredReason (Severity=Warning) documents that the VM & Host Group affinity rule for the FailureDomain is disabled.
178+
HostsAffinityMisconfiguredReason = "HostsAffinityMisconfigured"
179+
180+
// NetworkNotFoundReason (Severity=Error) documents that the networks in the topology for the Failure Domain
181+
// associated to the VSphereDeploymentZone are misconfigured.
182+
NetworkNotFoundReason = "NetworkNotFound"
183+
184+
// DatastoreNotFoundReason (Severity=Error) documents that the datastore in the topology for the Failure Domain
185+
// associated to the VSphereDeploymentZone is misconfigured.
186+
DatastoreNotFoundReason = "DatastoreNotFound"
187+
)

api/v1alpha3/vspherecluster_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ type VSphereClusterStatus struct {
7777
// Conditions defines current service state of the VSphereCluster.
7878
// +optional
7979
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
80+
81+
// FailureDomains is a list of failure domain objects synced from the infrastructure provider.
82+
FailureDomains clusterv1.FailureDomains `json:"failureDomains,omitempty"`
8083
}
8184

8285
// +kubebuilder:object:root=true
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha3
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
22+
)
23+
24+
// VSphereDeploymentZoneSpec defines the desired state of VSphereDeploymentZone
25+
type VSphereDeploymentZoneSpec struct {
26+
27+
// Server is the address of the vSphere endpoint.
28+
Server string `json:"server,omitempty"`
29+
30+
// failureDomain is the name of the VSphereFailureDomain used for this VSphereDeploymentZone
31+
FailureDomain string `json:"failureDomain,omitempty"`
32+
33+
// ControlPlane determines if this failure domain is suitable for use by control plane machines.
34+
// +optional
35+
ControlPlane *bool `json:"controlPlane,omitempty"`
36+
37+
// PlacementConstraint encapsulates the placement constraints
38+
// used within this deployment zone.
39+
PlacementConstraint PlacementConstraint `json:"placementConstraint"`
40+
}
41+
42+
// PlacementConstraint is the context information for VM placements within a failure domain
43+
type PlacementConstraint struct {
44+
// ResourcePool is the name or inventory path of the resource pool in which
45+
// the virtual machine is created/located.
46+
// +optional
47+
ResourcePool string `json:"resourcePool,omitempty"`
48+
49+
// Folder is the name or inventory path of the folder in which the
50+
// virtual machine is created/located.
51+
// +optional
52+
Folder string `json:"folder,omitempty"`
53+
}
54+
55+
type VSphereDeploymentZoneStatus struct {
56+
// Ready is true when the VSphereDeploymentZone resource is ready.
57+
// If set to false, it will be ignored by VSphereClusters
58+
// +optional
59+
Ready *bool `json:"ready,omitempty"`
60+
61+
// Conditions defines current service state of the VSphereMachine.
62+
// +optional
63+
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
64+
}
65+
66+
// +kubebuilder:object:root=true
67+
// +kubebuilder:resource:path=vspheredeploymentzones,scope=Cluster,categories=cluster-api
68+
// +kubebuilder:storageversion
69+
// +kubebuilder:subresource:status
70+
71+
// VSphereDeploymentZone is the Schema for the vspheredeploymentzones API
72+
type VSphereDeploymentZone struct {
73+
metav1.TypeMeta `json:",inline"`
74+
metav1.ObjectMeta `json:"metadata,omitempty"`
75+
76+
Spec VSphereDeploymentZoneSpec `json:"spec,omitempty"`
77+
Status VSphereDeploymentZoneStatus `json:"status,omitempty"`
78+
}
79+
80+
func (z *VSphereDeploymentZone) GetConditions() clusterv1.Conditions {
81+
return z.Status.Conditions
82+
}
83+
84+
func (z *VSphereDeploymentZone) SetConditions(conditions clusterv1.Conditions) {
85+
z.Status.Conditions = conditions
86+
}
87+
88+
// +kubebuilder:object:root=true
89+
90+
// VSphereDeploymentZoneList contains a list of VSphereDeploymentZone
91+
type VSphereDeploymentZoneList struct {
92+
metav1.TypeMeta `json:",inline"`
93+
metav1.ListMeta `json:"metadata,omitempty"`
94+
Items []VSphereDeploymentZone `json:"items"`
95+
}
96+
97+
func init() {
98+
SchemeBuilder.Register(&VSphereDeploymentZone{}, &VSphereDeploymentZoneList{})
99+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha3
18+
19+
import (
20+
"k8s.io/utils/pointer"
21+
ctrl "sigs.k8s.io/controller-runtime"
22+
"sigs.k8s.io/controller-runtime/pkg/webhook"
23+
)
24+
25+
func (r *VSphereDeploymentZone) SetupWebhookWithManager(mgr ctrl.Manager) error {
26+
return ctrl.NewWebhookManagedBy(mgr).
27+
For(r).
28+
Complete()
29+
}
30+
31+
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1alpha3-vspheredeploymentzone,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=vspheredeploymentzones,versions=v1alpha3,name=default.vspheredeploymentzone.infrastructure.cluster.x-k8s.io,sideEffects=None
32+
33+
var _ webhook.Defaulter = &VSphereDeploymentZone{}
34+
35+
// Default implements webhook.Defaulter so a webhook will be registered for the type
36+
func (r *VSphereDeploymentZone) Default() {
37+
if r.Spec.ControlPlane == nil {
38+
r.Spec.ControlPlane = pointer.BoolPtr(true)
39+
}
40+
}

0 commit comments

Comments
 (0)