Skip to content

Commit 3a17acc

Browse files
authored
Merge pull request kubernetes-sigs#3401 from chrischdi/pr-govmomi-vspheredeploymentzone
🌱 vspheredeploymentzone/vsphereclusteridentity: implement v1beta2 conditions, govmomi
2 parents 6674313 + 0f128a1 commit 3a17acc

8 files changed

+308
-29
lines changed

apis/v1beta1/vsphereclusteridentity_types.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ const (
2828
VSphereClusterIdentityFinalizer = "vsphereclusteridentity/infrastructure.cluster.x-k8s.io"
2929
)
3030

31+
// VSphereClusterIdentity's Available condition and corresponding reasons that will be used in v1Beta2 API version.
32+
const (
33+
// VSphereClusterIdentityAvailableV1Beta2Condition documents the availability for a VSphereClusterIdentity.
34+
VSphereClusterIdentityAvailableV1Beta2Condition = clusterv1.AvailableV1Beta2Condition
35+
36+
// VSphereClusterIdentityAvailableV1Beta2Reason surfaces when the VSphereClusterIdentity is available.
37+
VSphereClusterIdentityAvailableV1Beta2Reason = clusterv1.AvailableV1Beta2Reason
38+
39+
// VSphereClusterIdentitySecretNotAvailableV1Beta2Reason surfaces when the VSphereClusterIdentity secret is not available.
40+
VSphereClusterIdentitySecretNotAvailableV1Beta2Reason = "SecretNotAvailable"
41+
42+
// VSphereClusterIdentitySecretAlreadyInUseV1Beta2Reason surfaces when the VSphereClusterIdentity secret is already in use.
43+
VSphereClusterIdentitySecretAlreadyInUseV1Beta2Reason = "SecretAlreadyInUse"
44+
45+
// VSphereClusterIdentitySettingSecretOwnerReferenceFailedV1Beta2Reason surfaces when setting the owner reference on the VSphereClusterIdentity secret failed.
46+
VSphereClusterIdentitySettingSecretOwnerReferenceFailedV1Beta2Reason = "SettingSecretOwnerReferenceFailed"
47+
48+
// VSphereClusterIdentityDeletingV1Beta2Reason surfaces when the VSphereClusterIdentity is being deleted.
49+
VSphereClusterIdentityDeletingV1Beta2Reason = clusterv1.DeletingV1Beta2Reason
50+
)
51+
3152
// VSphereClusterIdentitySpec contains a secret reference and a group of allowed namespaces.
3253
type VSphereClusterIdentitySpec struct {
3354
// SecretName references a Secret inside the controller namespace with the credentials to use
@@ -59,7 +80,7 @@ type VSphereClusterIdentityStatus struct {
5980
// See https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more context.
6081
type VSphereClusterIdentityV1Beta2Status struct {
6182
// conditions represents the observations of a VSphereClusterIdentity's current state.
62-
// Known condition types are Paused.
83+
// Known condition types are Available and Paused.
6384
// +optional
6485
// +listType=map
6586
// +listMapKey=type

apis/v1beta1/vspheredeploymentzone_types.go

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,92 @@ const (
2828
DeploymentZoneFinalizer = "vspheredeploymentzone.infrastructure.cluster.x-k8s.io"
2929
)
3030

31+
// VSphereDeploymentZone's Ready condition and corresponding reasons that will be used in v1Beta2 API version.
32+
const (
33+
// VSphereDeploymentZoneReadyV1Beta2Condition is true if the VSphereDeploymentZone's deletionTimestamp is not set, VSphereDeploymentZone's
34+
// VCenterAvailable, PlacementConstraintReady and FailureDomainValidated conditions are true.
35+
VSphereDeploymentZoneReadyV1Beta2Condition = clusterv1.ReadyV1Beta2Condition
36+
37+
// VSphereDeploymentZoneReadyV1Beta2Reason surfaces when the VSphereDeploymentZone readiness criteria is met.
38+
VSphereDeploymentZoneReadyV1Beta2Reason = clusterv1.ReadyV1Beta2Reason
39+
40+
// VSphereDeploymentZoneNotReadyV1Beta2Reason surfaces when the VSphereDeploymentZone readiness criteria is not met.
41+
VSphereDeploymentZoneNotReadyV1Beta2Reason = clusterv1.NotReadyV1Beta2Reason
42+
43+
// VSphereDeploymentZoneReadyUnknownV1Beta2Reason surfaces when at least one VSphereDeploymentZone readiness criteria is unknown
44+
// and no VSphereDeploymentZone readiness criteria is not met.
45+
VSphereDeploymentZoneReadyUnknownV1Beta2Reason = clusterv1.ReadyUnknownV1Beta2Reason
46+
)
47+
48+
// VSphereDeploymentZone's VCenterAvailable condition and corresponding reasons that will be used in v1Beta2 API version.
49+
const (
50+
// VSphereDeploymentZoneVCenterAvailableV1Beta2Condition documents the status of vCenter for a VSphereDeploymentZone.
51+
VSphereDeploymentZoneVCenterAvailableV1Beta2Condition = "VCenterAvailable"
52+
53+
// VSphereDeploymentZoneVCenterAvailableV1Beta2Reason surfaces when the vCenter for a VSphereDeploymentZone is available.
54+
VSphereDeploymentZoneVCenterAvailableV1Beta2Reason = clusterv1.AvailableV1Beta2Reason
55+
56+
// VSphereDeploymentZoneVCenterUnreachableV1Beta2Reason surfaces when the vCenter for a VSphereDeploymentZone is unreachable.
57+
VSphereDeploymentZoneVCenterUnreachableV1Beta2Reason = "VCenterUnreachable"
58+
59+
// VSphereDeploymentZoneVCenterAvailableDeletingV1Beta2Reason surfaces when the vCenter for a VSphereDeploymentZone is being deleted.
60+
VSphereDeploymentZoneVCenterAvailableDeletingV1Beta2Reason = clusterv1.DeletingV1Beta2Reason
61+
)
62+
63+
// VSphereDeploymentZone's PlacementConstraintReady condition and corresponding reasons that will be used in v1Beta2 API version.
64+
const (
65+
// VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition documents the placement constraint status for a VSphereDeploymentZone.
66+
VSphereDeploymentZonePlacementConstraintReadyV1Beta2Condition = "PlacementConstraintReady"
67+
68+
// VSphereDeploymentZonePlacementConstraintReadyV1Beta2Reason surfaces when the placement status for a VSphereDeploymentZone is ready.
69+
VSphereDeploymentZonePlacementConstraintReadyV1Beta2Reason = clusterv1.ReadyV1Beta2Reason
70+
71+
// VSphereDeploymentZonePlacementConstraintResourcePoolNotFoundV1Beta2Reason surfaces when the resource pool for a VSphereDeploymentZone is not found.
72+
VSphereDeploymentZonePlacementConstraintResourcePoolNotFoundV1Beta2Reason = "ResourcePoolNotFound"
73+
74+
// VSphereDeploymentZonePlacementConstraintFolderNotFoundV1Beta2Reason surfaces when the folder for a VSphereDeploymentZone is not found.
75+
VSphereDeploymentZonePlacementConstraintFolderNotFoundV1Beta2Reason = "FolderNotFound"
76+
77+
// VSphereDeploymentZonePlacementConstraintDeletingV1Beta2Reason surfaces when the VSphereDeploymentZone is being deleted.
78+
VSphereDeploymentZonePlacementConstraintDeletingV1Beta2Reason = clusterv1.DeletingV1Beta2Reason
79+
)
80+
81+
// VSphereDeploymentZone's FailureDomainValidated condition and corresponding reasons that will be used in v1Beta2 API version.
82+
const (
83+
// VSphereDeploymentZoneFailureDomainValidatedV1Beta2Condition documents failure domain validation status for a VSphereDeploymentZone.
84+
VSphereDeploymentZoneFailureDomainValidatedV1Beta2Condition = "FailureDomainValidated"
85+
86+
// VSphereDeploymentZoneFailureDomainValidatedV1Beta2Reason surfaces when the failure domain for a VSphereDeploymentZone is validated.
87+
VSphereDeploymentZoneFailureDomainValidatedV1Beta2Reason = "Validated"
88+
89+
// VSphereDeploymentZoneFailureDomainValidationFailedV1Beta2Reason surfaces when the failure domain's validation for a VSphereDeploymentZone failed.
90+
VSphereDeploymentZoneFailureDomainValidationFailedV1Beta2Reason = "ValidationFailed"
91+
92+
// VSphereDeploymentZoneFailureDomainRegionMisconfiguredV1Beta2Reason surfaces when the failure domain's region for a VSphereDeploymentZone is misconfigured.
93+
VSphereDeploymentZoneFailureDomainRegionMisconfiguredV1Beta2Reason = "RegionMisconfigured"
94+
95+
// VSphereDeploymentZoneFailureDomainZoneMisconfiguredV1Beta2Reason surfaces when the failure domain's zone for a VSphereDeploymentZone is misconfigured.
96+
VSphereDeploymentZoneFailureDomainZoneMisconfiguredV1Beta2Reason = "ZoneMisconfigured"
97+
98+
// VSphereDeploymentZoneFailureDomainHostsMisconfiguredV1Beta2Reason surfaces when the failure domain's hosts for a VSphereDeploymentZone are misconfigured.
99+
VSphereDeploymentZoneFailureDomainHostsMisconfiguredV1Beta2Reason = "HostsMisconfigured"
100+
101+
// VSphereDeploymentZoneFailureDomainDatastoreNotFoundV1Beta2Reason surfaces when the failure domain's datastore for a VSphereDeploymentZone is not found.
102+
VSphereDeploymentZoneFailureDomainDatastoreNotFoundV1Beta2Reason = "DatastoreNotFound"
103+
104+
// VSphereDeploymentZoneFailureDomainNetworkNotFoundV1Beta2Reason surfaces when the failure domain's network for a VSphereDeploymentZone is not found.
105+
VSphereDeploymentZoneFailureDomainNetworkNotFoundV1Beta2Reason = "NetworkNotFound"
106+
107+
// VSphereDeploymentZoneFailureDomainComputeClusterNotFoundV1Beta2Reason surfaces when the failure domain's compute cluster for a VSphereDeploymentZone is not found.
108+
VSphereDeploymentZoneFailureDomainComputeClusterNotFoundV1Beta2Reason = "ComputeClusterNotFound"
109+
110+
// VSphereDeploymentZoneFailureDomainResourcePoolNotFoundV1Beta2Reason surfaces when the failure domain's resource pool for a VSphereDeploymentZone is not found.
111+
VSphereDeploymentZoneFailureDomainResourcePoolNotFoundV1Beta2Reason = "ResourcePoolNotFound"
112+
113+
// VSphereDeploymentZoneFailureDomainDeletingV1Beta2Reason surfaces when the VSphereDeploymentZone is being deleted.
114+
VSphereDeploymentZoneFailureDomainDeletingV1Beta2Reason = clusterv1.DeletingV1Beta2Reason
115+
)
116+
31117
// VSphereDeploymentZoneSpec defines the desired state of VSphereDeploymentZone.
32118
type VSphereDeploymentZoneSpec struct {
33119

@@ -93,7 +179,7 @@ type VSphereDeploymentZoneStatus struct {
93179
// See https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more context.
94180
type VSphereDeploymentZoneV1Beta2Status struct {
95181
// conditions represents the observations of a VSphereDeploymentZone's current state.
96-
// Known condition types are Paused.
182+
// Known condition types are Ready, VCenterAvailable, PlacementConstraintReady, FailureDomainValidated and Paused.
97183
// +optional
98184
// +listType=map
99185
// +listMapKey=type

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ spec:
451451
conditions:
452452
description: |-
453453
conditions represents the observations of a VSphereClusterIdentity's current state.
454-
Known condition types are Paused.
454+
Known condition types are Available and Paused.
455455
items:
456456
description: Condition contains details for one aspect of the
457457
current state of this API Resource.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ spec:
371371
conditions:
372372
description: |-
373373
conditions represents the observations of a VSphereDeploymentZone's current state.
374-
Known condition types are Paused.
374+
Known condition types are Ready, VCenterAvailable, PlacementConstraintReady, FailureDomainValidated and Paused.
375375
items:
376376
description: Condition contains details for one aspect of the
377377
current state of this API Resource.

controllers/vsphereclusteridentity_controller.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3131
clusterutilv1 "sigs.k8s.io/cluster-api/util"
3232
"sigs.k8s.io/cluster-api/util/conditions"
33+
v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
3334
"sigs.k8s.io/cluster-api/util/finalizers"
3435
"sigs.k8s.io/cluster-api/util/patch"
3536
"sigs.k8s.io/cluster-api/util/paused"
@@ -102,6 +103,7 @@ func (r clusterIdentityReconciler) Reconcile(ctx context.Context, req reconcile.
102103

103104
if err := patchHelper.Patch(ctx, identity, patch.WithOwnedV1Beta2Conditions{Conditions: []string{
104105
clusterv1.PausedV1Beta2Condition,
106+
infrav1.VSphereClusterIdentityAvailableV1Beta2Condition,
105107
}}); err != nil {
106108
reterr = kerrors.NewAggregate([]error{reterr, err})
107109
}
@@ -119,12 +121,24 @@ func (r clusterIdentityReconciler) Reconcile(ctx context.Context, req reconcile.
119121
}
120122
if err := r.Client.Get(ctx, secretKey, secret); err != nil {
121123
conditions.MarkFalse(identity, infrav1.CredentialsAvailableCondidtion, infrav1.SecretNotAvailableReason, clusterv1.ConditionSeverityWarning, err.Error())
124+
v1beta2conditions.Set(identity, metav1.Condition{
125+
Type: infrav1.VSphereClusterIdentityAvailableV1Beta2Condition,
126+
Status: metav1.ConditionFalse,
127+
Reason: infrav1.VSphereClusterIdentitySecretNotAvailableV1Beta2Reason,
128+
Message: err.Error(),
129+
})
122130
return reconcile.Result{}, errors.Wrapf(err, "failed to get Secret %s", klog.KRef(secretKey.Namespace, secretKey.Name))
123131
}
124132

125133
// If this secret is owned by a different VSphereClusterIdentity or a VSphereCluster, mark the identity as not ready and return an error.
126134
if !clusterutilv1.IsOwnedByObject(secret, identity) && pkgidentity.IsOwnedByIdentityOrCluster(secret.GetOwnerReferences()) {
127135
conditions.MarkFalse(identity, infrav1.CredentialsAvailableCondidtion, infrav1.SecretAlreadyInUseReason, clusterv1.ConditionSeverityError, "secret being used by another Cluster/VSphereIdentity")
136+
v1beta2conditions.Set(identity, metav1.Condition{
137+
Type: infrav1.VSphereClusterIdentityAvailableV1Beta2Condition,
138+
Status: metav1.ConditionFalse,
139+
Reason: infrav1.VSphereClusterIdentitySecretAlreadyInUseV1Beta2Reason,
140+
Message: "secret being used by another Cluster/VSphereIdentity",
141+
})
128142
identity.Status.Ready = false
129143
return reconcile.Result{}, errors.New("secret being used by another Cluster/VSphereIdentity")
130144
}
@@ -145,10 +159,22 @@ func (r clusterIdentityReconciler) Reconcile(ctx context.Context, req reconcile.
145159
err = r.Client.Update(ctx, secret)
146160
if err != nil {
147161
conditions.MarkFalse(identity, infrav1.CredentialsAvailableCondidtion, infrav1.SecretOwnerReferenceFailedReason, clusterv1.ConditionSeverityWarning, err.Error())
162+
v1beta2conditions.Set(identity, metav1.Condition{
163+
Type: infrav1.VSphereClusterIdentityAvailableV1Beta2Condition,
164+
Status: metav1.ConditionFalse,
165+
Reason: infrav1.VSphereClusterIdentitySettingSecretOwnerReferenceFailedV1Beta2Reason,
166+
Message: err.Error(),
167+
})
148168
return reconcile.Result{}, err
149169
}
150170

151171
conditions.MarkTrue(identity, infrav1.CredentialsAvailableCondidtion)
172+
v1beta2conditions.Set(identity, metav1.Condition{
173+
Type: infrav1.VSphereClusterIdentityAvailableV1Beta2Condition,
174+
Status: metav1.ConditionTrue,
175+
Reason: infrav1.VSphereClusterIdentityAvailableV1Beta2Reason,
176+
})
177+
152178
identity.Status.Ready = true
153179
return reconcile.Result{}, nil
154180
}
@@ -160,6 +186,13 @@ func (r clusterIdentityReconciler) reconcileDelete(ctx context.Context, identity
160186
Namespace: r.ControllerManagerCtx.Namespace,
161187
Name: identity.Spec.SecretName,
162188
}
189+
190+
v1beta2conditions.Set(identity, metav1.Condition{
191+
Type: infrav1.VSphereClusterIdentityAvailableV1Beta2Condition,
192+
Status: metav1.ConditionFalse,
193+
Reason: infrav1.VSphereClusterIdentityDeletingV1Beta2Reason,
194+
})
195+
163196
err := r.Client.Get(ctx, secretKey, secret)
164197
if err != nil {
165198
if apierrors.IsNotFound(err) {

0 commit comments

Comments
 (0)