Skip to content

Commit 556cf20

Browse files
authored
Add support for NutanixFailureDomain (#523)
* NCN-106555: Add support for CRD/controller of NutanixFailureDomain * NCN-106558: NutanixCluster CRD/controller changes to support NutanixFailureDomain * NCN-107724: NutanixMachine CRD/status and controller changes to support NutanixFailureDomain
1 parent 23d5ea8 commit 556cf20

22 files changed

+1182
-149
lines changed

api/v1beta1/conditions.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,25 @@ const (
2424
VolumeGroupDetachFailed = "VolumeGroupDetachFailed"
2525
)
2626

27+
// Conditions and Reasons releated to failure domain
2728
const (
28-
// FailureDomainsReconciled indicates the status of the failure domain reconciliation
29-
FailureDomainsReconciled capiv1.ConditionType = "FailureDomainsReconciled"
29+
// FailureDomainSafeForDeletionCondition indicates whether the failure domain object is safe for deletion,
30+
// ie., when it is not used or referenced by other resources
31+
FailureDomainSafeForDeletionCondition capiv1.ConditionType = "FailureDomainSafeForDeletion"
3032

31-
// NoFailureDomainsReconciled indicates no failure domains have been defined
32-
NoFailureDomainsReconciled capiv1.ConditionType = "NoFailureDomainsReconciled"
33+
// FailureDomainInUseReason indicates that the failure domain is used by
34+
// Machines and/or referenced by cluster
35+
FailureDomainInUseReason = "FailureDomainInUse"
3336

34-
// FailureDomainsReconciliationFailed indicates the failure domain reconciliation failed
35-
FailureDomainsReconciliationFailed = "FailureDomainsReconciliationFailed"
37+
// NoFailureDomainsConfiguredCondition indicates no failure domains have been configured
38+
NoFailureDomainsConfiguredCondition capiv1.ConditionType = "NoFailureDomainsConfigured"
39+
40+
// FailureDomainsValidatedCondition indicates whether the failure domains are configured correctly or not.
41+
FailureDomainsValidatedCondition capiv1.ConditionType = "FailureDomainsValidated"
42+
43+
// FailureDomainsMisconfiguredReason (Severity=Warning) indicates that some of the failure domains
44+
// are misconfigured.
45+
FailureDomainsMisconfiguredReason = "FailureDomainsMisconfigured"
3646
)
3747

3848
const (

api/v1beta1/nutanixcluster_types.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,16 @@ type NutanixClusterSpec struct {
6464
// +listType=map
6565
// +listMapKey=name
6666
// +optional
67-
FailureDomains []NutanixFailureDomain `json:"failureDomains"`
67+
//
68+
// Deprecated: This field is replaced by the field controlPlaneFailureDomains and will be removed in the next apiVersion.
69+
//
70+
FailureDomains []NutanixFailureDomainConfig `json:"failureDomains,omitempty"`
71+
72+
// controlPlaneFailureDomains configures references to the NutanixFailureDomain objects
73+
// that the cluster uses to deploy its control-plane machines.
74+
// +listType=set
75+
// +optional
76+
ControlPlaneFailureDomains []corev1.LocalObjectReference `json:"controlPlaneFailureDomains,omitempty"`
6877
}
6978

7079
// NutanixClusterStatus defines the observed state of NutanixCluster
@@ -75,6 +84,8 @@ type NutanixClusterStatus struct {
7584
// +optional
7685
Ready bool `json:"ready,omitempty"`
7786

87+
// failureDomains are a list of failure domains configured in the
88+
// cluster's spec and validated by the cluster controller.
7889
FailureDomains capiv1.FailureDomains `json:"failureDomains,omitempty"`
7990

8091
// Conditions defines current service state of the NutanixCluster.
@@ -96,6 +107,7 @@ type NutanixClusterStatus struct {
96107
// +kubebuilder:storageversion
97108
// +kubebuilder:printcolumn:name="ControlplaneEndpoint",type="string",JSONPath=".spec.controlPlaneEndpoint.host",description="ControlplaneEndpoint"
98109
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="in ready status"
110+
// +kubebuilder:printcolumn:name="FailureDomains",type="string",JSONPath=".status.failureDomains",description="NutanixCluster FailureDomains"
99111

100112
// NutanixCluster is the Schema for the nutanixclusters API
101113
type NutanixCluster struct {
@@ -106,8 +118,10 @@ type NutanixCluster struct {
106118
Status NutanixClusterStatus `json:"status,omitempty"`
107119
}
108120

109-
// NutanixFailureDomain configures failure domain information for Nutanix.
110-
type NutanixFailureDomain struct {
121+
// NutanixFailureDomainConfig configures failure domain information for Nutanix.
122+
//
123+
// Deprecated: This type is replaced by the NutanixFailureDomain CRD type and will be removed in the next apiVersion.
124+
type NutanixFailureDomainConfig struct {
111125
// name defines the unique name of a failure domain.
112126
// Name is required and must be at most 64 characters in length.
113127
// It must consist of only lower case alphanumeric characters and hyphens (-).
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
Copyright 2025 Nutanix
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 v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
22+
)
23+
24+
const (
25+
// NutanixFailureDomainKind represents the Kind of NutanixFailureDomain
26+
NutanixFailureDomainKind = "NutanixFailureDomain"
27+
28+
// NutanixFailureDomainFinalizer is the finalizer used by the NutanixFailureDomain controller to block
29+
// deletion of the NutanixFailureDomain object if there are references to this object by other resources.
30+
NutanixFailureDomainFinalizer = "infrastructure.cluster.x-k8s.io/nutanixfailuredomain"
31+
)
32+
33+
// NutanixFailureDomainSpec defines the desired state of NutanixFailureDomain.
34+
type NutanixFailureDomainSpec struct {
35+
// prismElementCluster is to identify the Prism Element cluster in the Prism Central for the failure domain.
36+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="prismElementCluster is immutable once set"
37+
// +kubebuilder:validation:Required
38+
PrismElementCluster NutanixResourceIdentifier `json:"prismElementCluster"`
39+
40+
// subnets holds a list of identifiers (one or more) of the PE cluster's network subnets
41+
// for the Machine's VM to connect to.
42+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="subnets is immutable once set"
43+
// +kubebuilder:validation:Required
44+
// +kubebuilder:validation:MinItems=1
45+
Subnets []NutanixResourceIdentifier `json:"subnets"`
46+
}
47+
48+
// NutanixFailureDomainStatus defines the observed state of NutanixFailureDomain resource.
49+
type NutanixFailureDomainStatus struct {
50+
// conditions represent the latest states of the failure domain.
51+
// +optional
52+
Conditions []capiv1.Condition `json:"conditions,omitempty"`
53+
}
54+
55+
// +kubebuilder:object:root=true
56+
// +kubebuilder:resource:path=nutanixfailuredomains,shortName=nfd,scope=Namespaced,categories=cluster-api
57+
// +kubebuilder:subresource:status
58+
// +kubebuilder:storageversion
59+
60+
// NutanixFailureDomain is the Schema for the NutanixFailureDomain API.
61+
type NutanixFailureDomain struct {
62+
metav1.TypeMeta `json:",inline"`
63+
metav1.ObjectMeta `json:"metadata,omitempty"`
64+
65+
Spec NutanixFailureDomainSpec `json:"spec,omitempty"`
66+
Status NutanixFailureDomainStatus `json:"status,omitempty"`
67+
}
68+
69+
// GetConditions returns the set of conditions for this object.
70+
func (nfd *NutanixFailureDomain) GetConditions() capiv1.Conditions {
71+
return nfd.Status.Conditions
72+
}
73+
74+
// SetConditions sets the conditions on this object.
75+
func (nfd *NutanixFailureDomain) SetConditions(conditions capiv1.Conditions) {
76+
nfd.Status.Conditions = conditions
77+
}
78+
79+
// +kubebuilder:object:root=true
80+
81+
// NutanixFailureDomainList contains a list of NutanixFailureDomain
82+
type NutanixFailureDomainList struct {
83+
metav1.TypeMeta `json:",inline"`
84+
metav1.ListMeta `json:"metadata,omitempty"`
85+
Items []NutanixFailureDomain `json:"items"`
86+
}
87+
88+
func init() {
89+
SchemeBuilder.Register(&NutanixFailureDomain{}, &NutanixFailureDomainList{})
90+
}

api/v1beta1/nutanixmachine_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ type NutanixMachineStatus struct {
275275
// Will be set in case of failure of Machine instance
276276
// +optional
277277
FailureMessage *string `json:"failureMessage,omitempty"`
278+
279+
// failureDomain is the name of the failure domain where this Machine has been placed in.
280+
// +optional
281+
FailureDomain *string `json:"failureDomain,omitempty"`
278282
}
279283

280284
// +kubebuilder:object:root=true
@@ -284,6 +288,7 @@ type NutanixMachineStatus struct {
284288
// +kubebuilder:printcolumn:name="Address",type="string",JSONPath=".status.addresses[0].address",description="The VM address"
285289
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="NutanixMachine ready status"
286290
// +kubebuilder:printcolumn:name="ProviderID",type="string",JSONPath=".spec.providerID",description="NutanixMachine instance ID"
291+
// +kubebuilder:printcolumn:name="FailureDomain",type="string",JSONPath=".status.failureDomain",description="NutanixMachine FailureDomain"
287292
// NutanixMachine is the Schema for the nutanixmachines API
288293
type NutanixMachine struct {
289294
metav1.TypeMeta `json:",inline"`

api/v1beta1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)