Skip to content

Commit c95b5e8

Browse files
committed
Adopt v1beta2 conditions for IBM VPC cluster
1 parent fb8ec92 commit c95b5e8

11 files changed

+615
-232
lines changed

api/v1beta1/zz_generated.conversion.go

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

api/v1beta2/conditions_consts.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,23 @@ const (
198198
IBMPowerVSClusterReadyUnknownV1Beta2Reason = clusterv1beta1.ReadyUnknownV1Beta2Reason
199199
)
200200

201+
// IBMVPCCluster's Ready condition and corresponding reasons that will be used in v1Beta2 API version.
202+
const (
203+
// IBMVPCClusterReadyV1Beta2Condition is true if the IBMVPCCluster's deletionTimestamp is not set and IBMVPCCluster's
204+
// conditions are true.
205+
IBMVPCClusterReadyV1Beta2Condition = clusterv1beta1.ReadyV1Beta2Condition
206+
207+
// IBMVPCClusterReadyV1Beta2Reason surfaces when the IBMVPCCluster readiness criteria is met.
208+
IBMVPCClusterReadyV1Beta2Reason = clusterv1beta1.ReadyV1Beta2Reason
209+
210+
// IBMVPCClusterNotReadyV1Beta2Reason surfaces when the IBMVPCCluster readiness criteria is not met.
211+
IBMVPCClusterNotReadyV1Beta2Reason = clusterv1beta1.NotReadyV1Beta2Reason
212+
213+
// IBMVPCClusterReadyUnknownV1Beta2Reason surfaces when at least one of the IBMVPCCluster readiness criteria is unknown
214+
// and none of the IBMVPCCluster readiness criteria is met.
215+
IBMVPCClusterReadyUnknownV1Beta2Reason = clusterv1beta1.ReadyUnknownV1Beta2Reason
216+
)
217+
201218
const (
202219
// WorkspaceReadyV1Beta2Condition reports on the successful reconciliation of a PowerVS workspace.
203220
WorkspaceReadyV1Beta2Condition = "WorkspaceReady"
@@ -283,6 +300,15 @@ const (
283300
// VPCLoadBalancerDeletingV1Beta2Reason surfaces when the VPC LoadBalancer is being deleted.
284301
VPCLoadBalancerDeletingV1Beta2Reason = clusterv1beta1.DeletingV1Beta2Reason
285302

303+
// VPCImageReadyV1Beta2Condition reports on the successful reconciliation of a VPC custom image.
304+
VPCImageReadyV1Beta2Condition = "VPCImageReady"
305+
306+
// VPCImageReadyV1Beta2Reason surfaces when the VPC custom image is ready.
307+
VPCImageReadyV1Beta2Reason = clusterv1beta1.ReadyV1Beta2Reason
308+
309+
// VPCImageReadyV1Beta2Reason surfaces when the VPC custom image is not ready.
310+
VPCImageNotReadyV1Beta2Reason = clusterv1beta1.NotReadyV1Beta2Reason
311+
286312
// COSInstanceReadyV1Beta2Condition reports on the successful reconciliation of a COS instance.
287313
COSInstanceReadyV1Beta2Condition = "COSInstanceReady"
288314

api/v1beta2/ibmvpccluster_types.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,21 @@ type IBMVPCClusterStatus struct {
320320
// Conditions defines current service state of the load balancer.
321321
// +optional
322322
Conditions clusterv1beta1.Conditions `json:"conditions,omitempty"`
323+
324+
// V1beta2 groups all the fields that will be added or modified in IBMVPCCluster's status with the V1Beta2 version.
325+
// +optional
326+
V1Beta2 *IBMVPCClusterV1Beta2Status `json:"v1beta2,omitempty"`
327+
}
328+
329+
// IBMVPCClusterV1Beta2Status groups all the fields that will be added or modified in IBMVPCClusterStatus with the V1Beta2 version.
330+
// See https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more context.
331+
type IBMVPCClusterV1Beta2Status struct {
332+
// Conditions represents the observations of a IBMVPCCluster's current state.
333+
// +optional
334+
// +listType=map
335+
// +listMapKey=type
336+
// +kubebuilder:validation:MaxItems=32
337+
Conditions []metav1.Condition `json:"conditions,omitempty"`
323338
}
324339

325340
// VPCNetworkStatus provides details on the status of VPC network resources for extended VPC Infrastructure support.
@@ -400,6 +415,22 @@ func (r *IBMVPCCluster) SetConditions(conditions clusterv1beta1.Conditions) {
400415
r.Status.Conditions = conditions
401416
}
402417

418+
// GetV1Beta2Conditions returns the set of conditions for IBMVPCCluster object.
419+
func (r *IBMVPCCluster) GetV1Beta2Conditions() []metav1.Condition {
420+
if r.Status.V1Beta2 == nil {
421+
return nil
422+
}
423+
return r.Status.V1Beta2.Conditions
424+
}
425+
426+
// SetV1Beta2Conditions sets conditions for IBMVPCCluster object.
427+
func (r *IBMVPCCluster) SetV1Beta2Conditions(conditions []metav1.Condition) {
428+
if r.Status.V1Beta2 == nil {
429+
r.Status.V1Beta2 = &IBMVPCClusterV1Beta2Status{}
430+
}
431+
r.Status.V1Beta2.Conditions = conditions
432+
}
433+
403434
func init() {
404435
objectTypes = append(objectTypes, &IBMVPCCluster{}, &IBMVPCClusterList{})
405436
}

api/v1beta2/zz_generated.deepcopy.go

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

cloud/scope/cluster.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"k8s.io/klog/v2"
3030

31+
ctrl "sigs.k8s.io/controller-runtime"
3132
"sigs.k8s.io/controller-runtime/pkg/client"
3233

3334
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
@@ -105,7 +106,7 @@ func NewClusterScope(params ClusterScopeParams) (*ClusterScope, error) {
105106
}
106107

107108
// CreateVPC creates a new IBM VPC in specified resource group.
108-
func (s *ClusterScope) CreateVPC() (*vpcv1.VPC, error) {
109+
func (s *ClusterScope) CreateVPC(ctx context.Context) (*vpcv1.VPC, error) {
109110
vpcReply, err := s.ensureVPCUnique(s.IBMVPCCluster.Spec.VPC)
110111
if err != nil {
111112
return nil, err
@@ -132,7 +133,7 @@ func (s *ClusterScope) CreateVPC() (*vpcv1.VPC, error) {
132133
}
133134

134135
// DeleteVPC deletes IBM VPC associated with a VPC id.
135-
func (s *ClusterScope) DeleteVPC() error {
136+
func (s *ClusterScope) DeleteVPC(ctx context.Context) error {
136137
if s.IBMVPCCluster.Status.VPC.ID == "" {
137138
return nil
138139
}
@@ -205,7 +206,7 @@ func (s *ClusterScope) updateDefaultSG(sgID string) error {
205206
}
206207

207208
// CreateSubnet creates a subnet within provided vpc and zone.
208-
func (s *ClusterScope) CreateSubnet() (*vpcv1.Subnet, error) {
209+
func (s *ClusterScope) CreateSubnet(ctx context.Context) (*vpcv1.Subnet, error) {
209210
subnetName := s.IBMVPCCluster.Name + subnetSuffix
210211
subnetReply, err := s.ensureSubnetUnique(subnetName)
211212
if err != nil {
@@ -334,7 +335,8 @@ func (s *ClusterScope) ensureSubnetUnique(subnetName string) (*vpcv1.Subnet, err
334335
}
335336

336337
// DeleteSubnet deletes a subnet associated with subnet id.
337-
func (s *ClusterScope) DeleteSubnet() error {
338+
func (s *ClusterScope) DeleteSubnet(ctx context.Context) error {
339+
log := ctrl.LoggerFrom(ctx)
338340
if s.IBMVPCCluster.Status.Subnet.ID == nil {
339341
return nil
340342
}
@@ -377,7 +379,7 @@ func (s *ClusterScope) DeleteSubnet() error {
377379
}
378380

379381
if !found {
380-
s.Logger.V(3).Info("No subnets found with ID", "Subnet ID", subnetID)
382+
log.V(3).Info("No subnets found with ID", "Subnet ID", subnetID)
381383
return nil
382384
}
383385

@@ -460,7 +462,7 @@ func (s *ClusterScope) detachPublicGateway(subnetID string, pgwID string) error
460462
}
461463

462464
// CreateLoadBalancer creates a new IBM VPC load balancer in specified resource group.
463-
func (s *ClusterScope) CreateLoadBalancer() (*vpcv1.LoadBalancer, error) {
465+
func (s *ClusterScope) CreateLoadBalancer(ctx context.Context) (*vpcv1.LoadBalancer, error) {
464466
loadBalancerReply, err := s.ensureLoadBalancerUnique(s.IBMVPCCluster.Spec.ControlPlaneLoadBalancer.Name)
465467
if err != nil {
466468
return nil, err
@@ -600,7 +602,7 @@ func (s *ClusterScope) ensureLoadBalancerUnique(loadBalancerName string) (*vpcv1
600602
}
601603

602604
// DeleteLoadBalancer deletes IBM VPC load balancer associated with a VPC id.
603-
func (s *ClusterScope) DeleteLoadBalancer() (bool, error) {
605+
func (s *ClusterScope) DeleteLoadBalancer(ctx context.Context) (bool, error) {
604606
deleted := false
605607
if lbipID := s.GetLoadBalancerID(); lbipID != "" {
606608
f := func(start string) (bool, string, error) {

0 commit comments

Comments
 (0)