From fbd7dc5386c9e56f1960be08b2767ae8205adfa5 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Tue, 19 Nov 2024 20:11:53 -0500 Subject: [PATCH] Import deprecated but needed errors constants from CAPI Context: https://github.com/kubernetes-sigs/cluster-api/issues/10784 We'll maintain them here for the time being, until we have conditions replacing these errors. --- api/v1alpha6/openstackcluster_types.go | 5 ++-- api/v1alpha6/openstackmachine_types.go | 7 +++--- api/v1alpha6/zz_generated.conversion.go | 10 ++++---- api/v1alpha6/zz_generated.deepcopy.go | 6 ++--- api/v1alpha7/openstackcluster_types.go | 5 ++-- api/v1alpha7/openstackmachine_types.go | 7 +++--- api/v1alpha7/zz_generated.conversion.go | 10 ++++---- api/v1alpha7/zz_generated.deepcopy.go | 6 ++--- api/v1beta1/openstackcluster_types.go | 4 +-- api/v1beta1/openstackmachine_types.go | 6 ++--- api/v1beta1/zz_generated.deepcopy.go | 6 ++--- ...re.cluster.x-k8s.io_openstackmachines.yaml | 12 ++++----- controllers/openstackcluster_controller.go | 3 +-- controllers/openstackmachine_controller.go | 6 ++--- docs/book/src/api/v1alpha6/api.md | 8 ++---- docs/book/src/api/v1alpha7/api.md | 8 ++---- docs/book/src/api/v1beta1/api.md | 8 ++---- .../api/v1alpha6/openstackclusterstatus.go | 24 +++++++++--------- .../api/v1alpha6/openstackmachinestatus.go | 16 ++++++------ .../api/v1alpha7/openstackclusterstatus.go | 6 ++--- .../api/v1alpha7/openstackmachinestatus.go | 16 ++++++------ .../api/v1beta1/openstackclusterstatus.go | 6 ++--- .../api/v1beta1/openstackmachinestatus.go | 22 ++++++++-------- pkg/utils/errors/errors.go | 25 +++++++++++++++++++ 24 files changed, 124 insertions(+), 108 deletions(-) diff --git a/api/v1alpha6/openstackcluster_types.go b/api/v1alpha6/openstackcluster_types.go index 4991f68126..f0603ac67d 100644 --- a/api/v1alpha6/openstackcluster_types.go +++ b/api/v1alpha6/openstackcluster_types.go @@ -19,7 +19,8 @@ package v1alpha6 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - capierrors "sigs.k8s.io/cluster-api/errors" + + capoerrors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" ) const ( @@ -190,7 +191,7 @@ type OpenStackClusterStatus struct { // OpenStackClusters can be added as events to the OpenStackCluster object // and/or logged in the controller's output. // +optional - FailureReason *capierrors.ClusterStatusError `json:"failureReason,omitempty"` + FailureReason *capoerrors.DeprecatedCAPIClusterStatusError `json:"failureReason,omitempty"` // FailureMessage will be set in the event that there is a terminal problem // reconciling the OpenStackCluster and will contain a more verbose string suitable diff --git a/api/v1alpha6/openstackmachine_types.go b/api/v1alpha6/openstackmachine_types.go index 11d3d95c5a..aa1e4f829a 100644 --- a/api/v1alpha6/openstackmachine_types.go +++ b/api/v1alpha6/openstackmachine_types.go @@ -21,7 +21,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/errors" + + capoerrors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" ) const ( @@ -118,7 +119,7 @@ type OpenStackMachineStatus struct { // +optional InstanceState *InstanceState `json:"instanceState,omitempty"` - FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"` + FailureReason *capoerrors.DeprecatedCAPIMachineStatusError `json:"failureReason,omitempty"` // FailureMessage will be set in the event that there is a terminal problem // reconciling the Machine and will contain a more verbose string suitable @@ -189,7 +190,7 @@ func (r *OpenStackMachine) SetConditions(conditions clusterv1.Conditions) { } // SetFailure sets the OpenStackMachine status failure reason and failure message. -func (r *OpenStackMachine) SetFailure(failureReason errors.MachineStatusError, failureMessage error) { +func (r *OpenStackMachine) SetFailure(failureReason capoerrors.DeprecatedCAPIMachineStatusError, failureMessage error) { r.Status.FailureReason = &failureReason r.Status.FailureMessage = ptr.To(failureMessage.Error()) } diff --git a/api/v1alpha6/zz_generated.conversion.go b/api/v1alpha6/zz_generated.conversion.go index 6ef92045b5..f2d66decde 100644 --- a/api/v1alpha6/zz_generated.conversion.go +++ b/api/v1alpha6/zz_generated.conversion.go @@ -29,9 +29,9 @@ import ( conversion "k8s.io/apimachinery/pkg/conversion" runtime "k8s.io/apimachinery/pkg/runtime" v1beta1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1" + errors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" optional "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional" apiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" - errors "sigs.k8s.io/cluster-api/errors" ) func init() { @@ -891,7 +891,7 @@ func autoConvert_v1alpha6_OpenStackClusterStatus_To_v1beta1_OpenStackClusterStat } else { out.Bastion = nil } - out.FailureReason = (*errors.ClusterStatusError)(unsafe.Pointer(in.FailureReason)) + out.FailureReason = (*errors.DeprecatedCAPIClusterStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) return nil } @@ -955,7 +955,7 @@ func autoConvert_v1beta1_OpenStackClusterStatus_To_v1alpha6_OpenStackClusterStat } else { out.Bastion = nil } - out.FailureReason = (*errors.ClusterStatusError)(unsafe.Pointer(in.FailureReason)) + out.FailureReason = (*errors.DeprecatedCAPIClusterStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) return nil } @@ -1274,7 +1274,7 @@ func autoConvert_v1alpha6_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStat out.Ready = in.Ready out.Addresses = *(*[]corev1.NodeAddress)(unsafe.Pointer(&in.Addresses)) out.InstanceState = (*v1beta1.InstanceState)(unsafe.Pointer(in.InstanceState)) - out.FailureReason = (*errors.MachineStatusError)(unsafe.Pointer(in.FailureReason)) + out.FailureReason = (*errors.DeprecatedCAPIMachineStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) out.Conditions = *(*apiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) return nil @@ -1292,7 +1292,7 @@ func autoConvert_v1beta1_OpenStackMachineStatus_To_v1alpha6_OpenStackMachineStat out.InstanceState = (*InstanceState)(unsafe.Pointer(in.InstanceState)) // WARNING: in.Resolved requires manual conversion: does not exist in peer-type // WARNING: in.Resources requires manual conversion: does not exist in peer-type - out.FailureReason = (*errors.MachineStatusError)(unsafe.Pointer(in.FailureReason)) + out.FailureReason = (*errors.DeprecatedCAPIMachineStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) out.Conditions = *(*apiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) return nil diff --git a/api/v1alpha6/zz_generated.deepcopy.go b/api/v1alpha6/zz_generated.deepcopy.go index cecfb87371..2b50f5eae3 100644 --- a/api/v1alpha6/zz_generated.deepcopy.go +++ b/api/v1alpha6/zz_generated.deepcopy.go @@ -23,8 +23,8 @@ package v1alpha6 import ( "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" + "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/errors" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -419,7 +419,7 @@ func (in *OpenStackClusterStatus) DeepCopyInto(out *OpenStackClusterStatus) { } if in.FailureReason != nil { in, out := &in.FailureReason, &out.FailureReason - *out = new(errors.ClusterStatusError) + *out = new(errors.DeprecatedCAPIClusterStatusError) **out = **in } if in.FailureMessage != nil { @@ -699,7 +699,7 @@ func (in *OpenStackMachineStatus) DeepCopyInto(out *OpenStackMachineStatus) { } if in.FailureReason != nil { in, out := &in.FailureReason, &out.FailureReason - *out = new(errors.MachineStatusError) + *out = new(errors.DeprecatedCAPIMachineStatusError) **out = **in } if in.FailureMessage != nil { diff --git a/api/v1alpha7/openstackcluster_types.go b/api/v1alpha7/openstackcluster_types.go index ccaaaef16e..baf0b75a4f 100644 --- a/api/v1alpha7/openstackcluster_types.go +++ b/api/v1alpha7/openstackcluster_types.go @@ -19,7 +19,8 @@ package v1alpha7 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - capierrors "sigs.k8s.io/cluster-api/errors" + + capoerrors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" ) const ( @@ -207,7 +208,7 @@ type OpenStackClusterStatus struct { // OpenStackClusters can be added as events to the OpenStackCluster object // and/or logged in the controller's output. // +optional - FailureReason *capierrors.ClusterStatusError `json:"failureReason,omitempty"` + FailureReason *capoerrors.DeprecatedCAPIClusterStatusError `json:"failureReason,omitempty"` // FailureMessage will be set in the event that there is a terminal problem // reconciling the OpenStackCluster and will contain a more verbose string suitable diff --git a/api/v1alpha7/openstackmachine_types.go b/api/v1alpha7/openstackmachine_types.go index 591440199c..afb52e8be0 100644 --- a/api/v1alpha7/openstackmachine_types.go +++ b/api/v1alpha7/openstackmachine_types.go @@ -21,7 +21,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/errors" + + capoerrors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" ) const ( @@ -118,7 +119,7 @@ type OpenStackMachineStatus struct { // +optional InstanceState *InstanceState `json:"instanceState,omitempty"` - FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"` + FailureReason *capoerrors.DeprecatedCAPIMachineStatusError `json:"failureReason,omitempty"` // FailureMessage will be set in the event that there is a terminal problem // reconciling the Machine and will contain a more verbose string suitable @@ -187,7 +188,7 @@ func (r *OpenStackMachine) SetConditions(conditions clusterv1.Conditions) { } // SetFailure sets the OpenStackMachine status failure reason and failure message. -func (r *OpenStackMachine) SetFailure(failureReason errors.MachineStatusError, failureMessage error) { +func (r *OpenStackMachine) SetFailure(failureReason capoerrors.DeprecatedCAPIMachineStatusError, failureMessage error) { r.Status.FailureReason = &failureReason r.Status.FailureMessage = ptr.To(failureMessage.Error()) } diff --git a/api/v1alpha7/zz_generated.conversion.go b/api/v1alpha7/zz_generated.conversion.go index 80e35376c0..109f11a158 100644 --- a/api/v1alpha7/zz_generated.conversion.go +++ b/api/v1alpha7/zz_generated.conversion.go @@ -30,9 +30,9 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" v1beta1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1" conversioncommon "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/conversioncommon" + errors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" optional "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional" apiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" - errors "sigs.k8s.io/cluster-api/errors" ) func init() { @@ -1128,7 +1128,7 @@ func autoConvert_v1alpha7_OpenStackClusterStatus_To_v1beta1_OpenStackClusterStat } else { out.Bastion = nil } - out.FailureReason = (*errors.ClusterStatusError)(unsafe.Pointer(in.FailureReason)) + out.FailureReason = (*errors.DeprecatedCAPIClusterStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) return nil } @@ -1189,7 +1189,7 @@ func autoConvert_v1beta1_OpenStackClusterStatus_To_v1alpha7_OpenStackClusterStat } else { out.Bastion = nil } - out.FailureReason = (*errors.ClusterStatusError)(unsafe.Pointer(in.FailureReason)) + out.FailureReason = (*errors.DeprecatedCAPIClusterStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) return nil } @@ -1527,7 +1527,7 @@ func autoConvert_v1alpha7_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStat out.Ready = in.Ready out.Addresses = *(*[]corev1.NodeAddress)(unsafe.Pointer(&in.Addresses)) out.InstanceState = (*v1beta1.InstanceState)(unsafe.Pointer(in.InstanceState)) - out.FailureReason = (*errors.MachineStatusError)(unsafe.Pointer(in.FailureReason)) + out.FailureReason = (*errors.DeprecatedCAPIMachineStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) out.Conditions = *(*apiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) return nil @@ -1545,7 +1545,7 @@ func autoConvert_v1beta1_OpenStackMachineStatus_To_v1alpha7_OpenStackMachineStat out.InstanceState = (*InstanceState)(unsafe.Pointer(in.InstanceState)) // WARNING: in.Resolved requires manual conversion: does not exist in peer-type // WARNING: in.Resources requires manual conversion: does not exist in peer-type - out.FailureReason = (*errors.MachineStatusError)(unsafe.Pointer(in.FailureReason)) + out.FailureReason = (*errors.DeprecatedCAPIMachineStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) out.Conditions = *(*apiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) return nil diff --git a/api/v1alpha7/zz_generated.deepcopy.go b/api/v1alpha7/zz_generated.deepcopy.go index 7ca76d0fca..0d8c9d4107 100644 --- a/api/v1alpha7/zz_generated.deepcopy.go +++ b/api/v1alpha7/zz_generated.deepcopy.go @@ -23,8 +23,8 @@ package v1alpha7 import ( "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" + "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/errors" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -448,7 +448,7 @@ func (in *OpenStackClusterStatus) DeepCopyInto(out *OpenStackClusterStatus) { } if in.FailureReason != nil { in, out := &in.FailureReason, &out.FailureReason - *out = new(errors.ClusterStatusError) + *out = new(errors.DeprecatedCAPIClusterStatusError) **out = **in } if in.FailureMessage != nil { @@ -728,7 +728,7 @@ func (in *OpenStackMachineStatus) DeepCopyInto(out *OpenStackMachineStatus) { } if in.FailureReason != nil { in, out := &in.FailureReason, &out.FailureReason - *out = new(errors.MachineStatusError) + *out = new(errors.DeprecatedCAPIMachineStatusError) **out = **in } if in.FailureMessage != nil { diff --git a/api/v1beta1/openstackcluster_types.go b/api/v1beta1/openstackcluster_types.go index 5fe609e544..1d3addbb03 100644 --- a/api/v1beta1/openstackcluster_types.go +++ b/api/v1beta1/openstackcluster_types.go @@ -19,8 +19,8 @@ package v1beta1 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - capierrors "sigs.k8s.io/cluster-api/errors" + capoerrors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional" ) @@ -258,7 +258,7 @@ type OpenStackClusterStatus struct { // OpenStackClusters can be added as events to the OpenStackCluster object // and/or logged in the controller's output. // +optional - FailureReason *capierrors.ClusterStatusError `json:"failureReason,omitempty"` + FailureReason *capoerrors.DeprecatedCAPIClusterStatusError `json:"failureReason,omitempty"` // FailureMessage will be set in the event that there is a terminal problem // reconciling the OpenStackCluster and will contain a more verbose string suitable diff --git a/api/v1beta1/openstackmachine_types.go b/api/v1beta1/openstackmachine_types.go index 71ed6f0fe8..00025db7b6 100644 --- a/api/v1beta1/openstackmachine_types.go +++ b/api/v1beta1/openstackmachine_types.go @@ -21,8 +21,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/errors" + capoerrors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional" ) @@ -211,7 +211,7 @@ type OpenStackMachineStatus struct { // +optional Resources *MachineResources `json:"resources,omitempty"` - FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"` + FailureReason *capoerrors.DeprecatedCAPIMachineStatusError `json:"failureReason,omitempty"` // FailureMessage will be set in the event that there is a terminal problem // reconciling the Machine and will contain a more verbose string suitable @@ -276,7 +276,7 @@ func (r *OpenStackMachine) SetConditions(conditions clusterv1.Conditions) { } // SetFailure sets the OpenStackMachine status failure reason and failure message. -func (r *OpenStackMachine) SetFailure(failureReason errors.MachineStatusError, failureMessage error) { +func (r *OpenStackMachine) SetFailure(failureReason capoerrors.DeprecatedCAPIMachineStatusError, failureMessage error) { r.Status.FailureReason = &failureReason r.Status.FailureMessage = ptr.To(failureMessage.Error()) } diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index c0bc2760f3..0ea578a137 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -23,8 +23,8 @@ package v1beta1 import ( "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" + "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" apiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/errors" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -780,7 +780,7 @@ func (in *OpenStackClusterStatus) DeepCopyInto(out *OpenStackClusterStatus) { } if in.FailureReason != nil { in, out := &in.FailureReason, &out.FailureReason - *out = new(errors.ClusterStatusError) + *out = new(errors.DeprecatedCAPIClusterStatusError) **out = **in } if in.FailureMessage != nil { @@ -1088,7 +1088,7 @@ func (in *OpenStackMachineStatus) DeepCopyInto(out *OpenStackMachineStatus) { } if in.FailureReason != nil { in, out := &in.FailureReason, &out.FailureReason - *out = new(errors.MachineStatusError) + *out = new(errors.DeprecatedCAPIMachineStatusError) **out = **in } if in.FailureMessage != nil { diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml index 5b09d3d55f..4bdf247569 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml @@ -587,8 +587,8 @@ spec: controller's output. type: string failureReason: - description: MachineStatusError defines errors states for Machine - objects. + description: DeprecatedCAPIMachineStatusError defines errors states + for Machine objects. type: string instanceState: description: InstanceState is the state of the OpenStack instance @@ -1111,8 +1111,8 @@ spec: controller's output. type: string failureReason: - description: MachineStatusError defines errors states for Machine - objects. + description: DeprecatedCAPIMachineStatusError defines errors states + for Machine objects. type: string instanceState: description: InstanceState is the state of the OpenStack instance @@ -2133,8 +2133,8 @@ spec: controller's output. type: string failureReason: - description: MachineStatusError defines errors states for Machine - objects. + description: DeprecatedCAPIMachineStatusError defines errors states + for Machine objects. type: string instanceID: description: InstanceID is the OpenStack instance ID for this machine. diff --git a/controllers/openstackcluster_controller.go b/controllers/openstackcluster_controller.go index 2a2cacd51d..676fffb2d3 100644 --- a/controllers/openstackcluster_controller.go +++ b/controllers/openstackcluster_controller.go @@ -33,7 +33,6 @@ import ( "k8s.io/client-go/tools/record" "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - capierrors "sigs.k8s.io/cluster-api/errors" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/annotations" "sigs.k8s.io/cluster-api/util/collections" @@ -886,7 +885,7 @@ func (r *OpenStackClusterReconciler) SetupWithManager(ctx context.Context, mgr c func handleUpdateOSCError(openstackCluster *infrav1.OpenStackCluster, message error, isFatal bool) { if isFatal { - err := capierrors.UpdateClusterError + err := capoerrors.DeprecatedCAPOUpdateClusterError openstackCluster.Status.FailureReason = &err openstackCluster.Status.FailureMessage = ptr.To(message.Error()) } diff --git a/controllers/openstackmachine_controller.go b/controllers/openstackmachine_controller.go index b87d71a460..6a7318911a 100644 --- a/controllers/openstackmachine_controller.go +++ b/controllers/openstackmachine_controller.go @@ -30,7 +30,6 @@ import ( "k8s.io/client-go/tools/record" "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - capierrors "sigs.k8s.io/cluster-api/errors" ipamv1 "sigs.k8s.io/cluster-api/exp/ipam/api/v1beta1" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/annotations" @@ -51,6 +50,7 @@ import ( "sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/services/loadbalancer" "sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/services/networking" "sigs.k8s.io/cluster-api-provider-openstack/pkg/scope" + capoerrors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" ) // OpenStackMachineReconciler reconciles a OpenStackMachine object. @@ -298,7 +298,7 @@ func removeAPIServerEndpoint(scope *scope.WithLogger, openStackCluster *infrav1. instanceNS, err := instanceStatus.NetworkStatus() if err != nil { openStackMachine.SetFailure( - capierrors.UpdateMachineError, + capoerrors.DeprecatedCAPIUpdateMachineError, fmt.Errorf("get network status for OpenStack instance %s with ID %s: %v", instanceStatus.Name(), instanceStatus.ID(), err), ) return nil @@ -437,7 +437,7 @@ func (r *OpenStackMachineReconciler) reconcileMachineState(scope *scope.WithLogg scope.Logger().Info("Machine instance state is ERROR", "id", openStackServer.Status.InstanceID) if machine.Status.NodeRef == nil { err := fmt.Errorf("instance state %v is unexpected", openStackServer.Status.InstanceState) - openStackMachine.SetFailure(capierrors.UpdateMachineError, err) + openStackMachine.SetFailure(capoerrors.DeprecatedCAPIUpdateMachineError, err) } conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceStateErrorReason, clusterv1.ConditionSeverityError, "") return &ctrl.Result{} diff --git a/docs/book/src/api/v1alpha6/api.md b/docs/book/src/api/v1alpha6/api.md index 80ca80e8a4..00fdbb4eb3 100644 --- a/docs/book/src/api/v1alpha6/api.md +++ b/docs/book/src/api/v1alpha6/api.md @@ -2099,9 +2099,7 @@ Instance failureReason
- -sigs.k8s.io/cluster-api/errors.ClusterStatusError - +sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors.DeprecatedCAPIClusterStatusError @@ -2874,9 +2872,7 @@ InstanceState failureReason
- -sigs.k8s.io/cluster-api/errors.MachineStatusError - +sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors.DeprecatedCAPIMachineStatusError diff --git a/docs/book/src/api/v1alpha7/api.md b/docs/book/src/api/v1alpha7/api.md index 0025fa45bd..dc964f9872 100644 --- a/docs/book/src/api/v1alpha7/api.md +++ b/docs/book/src/api/v1alpha7/api.md @@ -2179,9 +2179,7 @@ BastionStatus failureReason
- -sigs.k8s.io/cluster-api/errors.ClusterStatusError - +sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors.DeprecatedCAPIClusterStatusError @@ -2974,9 +2972,7 @@ InstanceState failureReason
- -sigs.k8s.io/cluster-api/errors.MachineStatusError - +sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors.DeprecatedCAPIMachineStatusError diff --git a/docs/book/src/api/v1beta1/api.md b/docs/book/src/api/v1beta1/api.md index 47adae3e4f..29fe803852 100644 --- a/docs/book/src/api/v1beta1/api.md +++ b/docs/book/src/api/v1beta1/api.md @@ -2702,9 +2702,7 @@ BastionStatus failureReason
- -sigs.k8s.io/cluster-api/errors.ClusterStatusError - +sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors.DeprecatedCAPIClusterStatusError @@ -3558,9 +3556,7 @@ MachineResources failureReason
- -sigs.k8s.io/cluster-api/errors.MachineStatusError - +sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors.DeprecatedCAPIMachineStatusError diff --git a/pkg/generated/applyconfiguration/api/v1alpha6/openstackclusterstatus.go b/pkg/generated/applyconfiguration/api/v1alpha6/openstackclusterstatus.go index bc1271c2d8..0eef83c1a9 100644 --- a/pkg/generated/applyconfiguration/api/v1alpha6/openstackclusterstatus.go +++ b/pkg/generated/applyconfiguration/api/v1alpha6/openstackclusterstatus.go @@ -19,23 +19,23 @@ limitations under the License. package v1alpha6 import ( + errors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" v1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" - errors "sigs.k8s.io/cluster-api/errors" ) // OpenStackClusterStatusApplyConfiguration represents a declarative configuration of the OpenStackClusterStatus type for use // with apply. type OpenStackClusterStatusApplyConfiguration struct { - Ready *bool `json:"ready,omitempty"` - Network *NetworkApplyConfiguration `json:"network,omitempty"` - ExternalNetwork *NetworkApplyConfiguration `json:"externalNetwork,omitempty"` - FailureDomains *v1beta1.FailureDomains `json:"failureDomains,omitempty"` - ControlPlaneSecurityGroup *SecurityGroupApplyConfiguration `json:"controlPlaneSecurityGroup,omitempty"` - WorkerSecurityGroup *SecurityGroupApplyConfiguration `json:"workerSecurityGroup,omitempty"` - BastionSecurityGroup *SecurityGroupApplyConfiguration `json:"bastionSecurityGroup,omitempty"` - Bastion *InstanceApplyConfiguration `json:"bastion,omitempty"` - FailureReason *errors.ClusterStatusError `json:"failureReason,omitempty"` - FailureMessage *string `json:"failureMessage,omitempty"` + Ready *bool `json:"ready,omitempty"` + Network *NetworkApplyConfiguration `json:"network,omitempty"` + ExternalNetwork *NetworkApplyConfiguration `json:"externalNetwork,omitempty"` + FailureDomains *v1beta1.FailureDomains `json:"failureDomains,omitempty"` + ControlPlaneSecurityGroup *SecurityGroupApplyConfiguration `json:"controlPlaneSecurityGroup,omitempty"` + WorkerSecurityGroup *SecurityGroupApplyConfiguration `json:"workerSecurityGroup,omitempty"` + BastionSecurityGroup *SecurityGroupApplyConfiguration `json:"bastionSecurityGroup,omitempty"` + Bastion *InstanceApplyConfiguration `json:"bastion,omitempty"` + FailureReason *errors.DeprecatedCAPIClusterStatusError `json:"failureReason,omitempty"` + FailureMessage *string `json:"failureMessage,omitempty"` } // OpenStackClusterStatusApplyConfiguration constructs a declarative configuration of the OpenStackClusterStatus type for use with @@ -111,7 +111,7 @@ func (b *OpenStackClusterStatusApplyConfiguration) WithBastion(value *InstanceAp // WithFailureReason sets the FailureReason field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the FailureReason field is set to the value of the last call. -func (b *OpenStackClusterStatusApplyConfiguration) WithFailureReason(value errors.ClusterStatusError) *OpenStackClusterStatusApplyConfiguration { +func (b *OpenStackClusterStatusApplyConfiguration) WithFailureReason(value errors.DeprecatedCAPIClusterStatusError) *OpenStackClusterStatusApplyConfiguration { b.FailureReason = &value return b } diff --git a/pkg/generated/applyconfiguration/api/v1alpha6/openstackmachinestatus.go b/pkg/generated/applyconfiguration/api/v1alpha6/openstackmachinestatus.go index b93d2fb105..d68e51a3a7 100644 --- a/pkg/generated/applyconfiguration/api/v1alpha6/openstackmachinestatus.go +++ b/pkg/generated/applyconfiguration/api/v1alpha6/openstackmachinestatus.go @@ -21,19 +21,19 @@ package v1alpha6 import ( v1 "k8s.io/api/core/v1" v1alpha6 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha6" + errors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" v1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" - errors "sigs.k8s.io/cluster-api/errors" ) // OpenStackMachineStatusApplyConfiguration represents a declarative configuration of the OpenStackMachineStatus type for use // with apply. type OpenStackMachineStatusApplyConfiguration struct { - Ready *bool `json:"ready,omitempty"` - Addresses []v1.NodeAddress `json:"addresses,omitempty"` - InstanceState *v1alpha6.InstanceState `json:"instanceState,omitempty"` - FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"` - FailureMessage *string `json:"failureMessage,omitempty"` - Conditions *v1beta1.Conditions `json:"conditions,omitempty"` + Ready *bool `json:"ready,omitempty"` + Addresses []v1.NodeAddress `json:"addresses,omitempty"` + InstanceState *v1alpha6.InstanceState `json:"instanceState,omitempty"` + FailureReason *errors.DeprecatedCAPIMachineStatusError `json:"failureReason,omitempty"` + FailureMessage *string `json:"failureMessage,omitempty"` + Conditions *v1beta1.Conditions `json:"conditions,omitempty"` } // OpenStackMachineStatusApplyConfiguration constructs a declarative configuration of the OpenStackMachineStatus type for use with @@ -71,7 +71,7 @@ func (b *OpenStackMachineStatusApplyConfiguration) WithInstanceState(value v1alp // WithFailureReason sets the FailureReason field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the FailureReason field is set to the value of the last call. -func (b *OpenStackMachineStatusApplyConfiguration) WithFailureReason(value errors.MachineStatusError) *OpenStackMachineStatusApplyConfiguration { +func (b *OpenStackMachineStatusApplyConfiguration) WithFailureReason(value errors.DeprecatedCAPIMachineStatusError) *OpenStackMachineStatusApplyConfiguration { b.FailureReason = &value return b } diff --git a/pkg/generated/applyconfiguration/api/v1alpha7/openstackclusterstatus.go b/pkg/generated/applyconfiguration/api/v1alpha7/openstackclusterstatus.go index 2793288c94..a478e77e7d 100644 --- a/pkg/generated/applyconfiguration/api/v1alpha7/openstackclusterstatus.go +++ b/pkg/generated/applyconfiguration/api/v1alpha7/openstackclusterstatus.go @@ -19,8 +19,8 @@ limitations under the License. package v1alpha7 import ( + errors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" v1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" - errors "sigs.k8s.io/cluster-api/errors" ) // OpenStackClusterStatusApplyConfiguration represents a declarative configuration of the OpenStackClusterStatus type for use @@ -36,7 +36,7 @@ type OpenStackClusterStatusApplyConfiguration struct { WorkerSecurityGroup *SecurityGroupApplyConfiguration `json:"workerSecurityGroup,omitempty"` BastionSecurityGroup *SecurityGroupApplyConfiguration `json:"bastionSecurityGroup,omitempty"` Bastion *BastionStatusApplyConfiguration `json:"bastion,omitempty"` - FailureReason *errors.ClusterStatusError `json:"failureReason,omitempty"` + FailureReason *errors.DeprecatedCAPIClusterStatusError `json:"failureReason,omitempty"` FailureMessage *string `json:"failureMessage,omitempty"` } @@ -129,7 +129,7 @@ func (b *OpenStackClusterStatusApplyConfiguration) WithBastion(value *BastionSta // WithFailureReason sets the FailureReason field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the FailureReason field is set to the value of the last call. -func (b *OpenStackClusterStatusApplyConfiguration) WithFailureReason(value errors.ClusterStatusError) *OpenStackClusterStatusApplyConfiguration { +func (b *OpenStackClusterStatusApplyConfiguration) WithFailureReason(value errors.DeprecatedCAPIClusterStatusError) *OpenStackClusterStatusApplyConfiguration { b.FailureReason = &value return b } diff --git a/pkg/generated/applyconfiguration/api/v1alpha7/openstackmachinestatus.go b/pkg/generated/applyconfiguration/api/v1alpha7/openstackmachinestatus.go index 4381ced88c..3c6ee4aff5 100644 --- a/pkg/generated/applyconfiguration/api/v1alpha7/openstackmachinestatus.go +++ b/pkg/generated/applyconfiguration/api/v1alpha7/openstackmachinestatus.go @@ -21,19 +21,19 @@ package v1alpha7 import ( v1 "k8s.io/api/core/v1" v1alpha7 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7" + errors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" v1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" - errors "sigs.k8s.io/cluster-api/errors" ) // OpenStackMachineStatusApplyConfiguration represents a declarative configuration of the OpenStackMachineStatus type for use // with apply. type OpenStackMachineStatusApplyConfiguration struct { - Ready *bool `json:"ready,omitempty"` - Addresses []v1.NodeAddress `json:"addresses,omitempty"` - InstanceState *v1alpha7.InstanceState `json:"instanceState,omitempty"` - FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"` - FailureMessage *string `json:"failureMessage,omitempty"` - Conditions *v1beta1.Conditions `json:"conditions,omitempty"` + Ready *bool `json:"ready,omitempty"` + Addresses []v1.NodeAddress `json:"addresses,omitempty"` + InstanceState *v1alpha7.InstanceState `json:"instanceState,omitempty"` + FailureReason *errors.DeprecatedCAPIMachineStatusError `json:"failureReason,omitempty"` + FailureMessage *string `json:"failureMessage,omitempty"` + Conditions *v1beta1.Conditions `json:"conditions,omitempty"` } // OpenStackMachineStatusApplyConfiguration constructs a declarative configuration of the OpenStackMachineStatus type for use with @@ -71,7 +71,7 @@ func (b *OpenStackMachineStatusApplyConfiguration) WithInstanceState(value v1alp // WithFailureReason sets the FailureReason field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the FailureReason field is set to the value of the last call. -func (b *OpenStackMachineStatusApplyConfiguration) WithFailureReason(value errors.MachineStatusError) *OpenStackMachineStatusApplyConfiguration { +func (b *OpenStackMachineStatusApplyConfiguration) WithFailureReason(value errors.DeprecatedCAPIMachineStatusError) *OpenStackMachineStatusApplyConfiguration { b.FailureReason = &value return b } diff --git a/pkg/generated/applyconfiguration/api/v1beta1/openstackclusterstatus.go b/pkg/generated/applyconfiguration/api/v1beta1/openstackclusterstatus.go index c38e309107..910fc2cfcb 100644 --- a/pkg/generated/applyconfiguration/api/v1beta1/openstackclusterstatus.go +++ b/pkg/generated/applyconfiguration/api/v1beta1/openstackclusterstatus.go @@ -19,8 +19,8 @@ limitations under the License. package v1beta1 import ( + errors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" apiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" - errors "sigs.k8s.io/cluster-api/errors" ) // OpenStackClusterStatusApplyConfiguration represents a declarative configuration of the OpenStackClusterStatus type for use @@ -36,7 +36,7 @@ type OpenStackClusterStatusApplyConfiguration struct { WorkerSecurityGroup *SecurityGroupStatusApplyConfiguration `json:"workerSecurityGroup,omitempty"` BastionSecurityGroup *SecurityGroupStatusApplyConfiguration `json:"bastionSecurityGroup,omitempty"` Bastion *BastionStatusApplyConfiguration `json:"bastion,omitempty"` - FailureReason *errors.ClusterStatusError `json:"failureReason,omitempty"` + FailureReason *errors.DeprecatedCAPIClusterStatusError `json:"failureReason,omitempty"` FailureMessage *string `json:"failureMessage,omitempty"` } @@ -129,7 +129,7 @@ func (b *OpenStackClusterStatusApplyConfiguration) WithBastion(value *BastionSta // WithFailureReason sets the FailureReason field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the FailureReason field is set to the value of the last call. -func (b *OpenStackClusterStatusApplyConfiguration) WithFailureReason(value errors.ClusterStatusError) *OpenStackClusterStatusApplyConfiguration { +func (b *OpenStackClusterStatusApplyConfiguration) WithFailureReason(value errors.DeprecatedCAPIClusterStatusError) *OpenStackClusterStatusApplyConfiguration { b.FailureReason = &value return b } diff --git a/pkg/generated/applyconfiguration/api/v1beta1/openstackmachinestatus.go b/pkg/generated/applyconfiguration/api/v1beta1/openstackmachinestatus.go index f64988de5c..95292266cc 100644 --- a/pkg/generated/applyconfiguration/api/v1beta1/openstackmachinestatus.go +++ b/pkg/generated/applyconfiguration/api/v1beta1/openstackmachinestatus.go @@ -21,22 +21,22 @@ package v1beta1 import ( v1 "k8s.io/api/core/v1" v1beta1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1" + errors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors" clusterapiapiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" - errors "sigs.k8s.io/cluster-api/errors" ) // OpenStackMachineStatusApplyConfiguration represents a declarative configuration of the OpenStackMachineStatus type for use // with apply. type OpenStackMachineStatusApplyConfiguration struct { - Ready *bool `json:"ready,omitempty"` - InstanceID *string `json:"instanceID,omitempty"` - Addresses []v1.NodeAddress `json:"addresses,omitempty"` - InstanceState *v1beta1.InstanceState `json:"instanceState,omitempty"` - Resolved *ResolvedMachineSpecApplyConfiguration `json:"resolved,omitempty"` - Resources *MachineResourcesApplyConfiguration `json:"resources,omitempty"` - FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"` - FailureMessage *string `json:"failureMessage,omitempty"` - Conditions *clusterapiapiv1beta1.Conditions `json:"conditions,omitempty"` + Ready *bool `json:"ready,omitempty"` + InstanceID *string `json:"instanceID,omitempty"` + Addresses []v1.NodeAddress `json:"addresses,omitempty"` + InstanceState *v1beta1.InstanceState `json:"instanceState,omitempty"` + Resolved *ResolvedMachineSpecApplyConfiguration `json:"resolved,omitempty"` + Resources *MachineResourcesApplyConfiguration `json:"resources,omitempty"` + FailureReason *errors.DeprecatedCAPIMachineStatusError `json:"failureReason,omitempty"` + FailureMessage *string `json:"failureMessage,omitempty"` + Conditions *clusterapiapiv1beta1.Conditions `json:"conditions,omitempty"` } // OpenStackMachineStatusApplyConfiguration constructs a declarative configuration of the OpenStackMachineStatus type for use with @@ -98,7 +98,7 @@ func (b *OpenStackMachineStatusApplyConfiguration) WithResources(value *MachineR // WithFailureReason sets the FailureReason field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the FailureReason field is set to the value of the last call. -func (b *OpenStackMachineStatusApplyConfiguration) WithFailureReason(value errors.MachineStatusError) *OpenStackMachineStatusApplyConfiguration { +func (b *OpenStackMachineStatusApplyConfiguration) WithFailureReason(value errors.DeprecatedCAPIMachineStatusError) *OpenStackMachineStatusApplyConfiguration { b.FailureReason = &value return b } diff --git a/pkg/utils/errors/errors.go b/pkg/utils/errors/errors.go index 2ee3eaf9c6..5c7b18d0cb 100644 --- a/pkg/utils/errors/errors.go +++ b/pkg/utils/errors/errors.go @@ -89,3 +89,28 @@ func IsConflict(err error) bool { func IsNotImplementedError(err error) bool { return gophercloud.ResponseCodeIs(err, http.StatusNotImplemented) } + +// The following types and constants are imported from CAPI and will be removed at some point once we +// implement the conditions that will be required in CAPI v1beta2 +// See https://github.com/kubernetes-sigs/cluster-api/issues/10784 + +// DeprecatedCAPIMachineStatusError defines errors states for Machine objects. +type DeprecatedCAPIMachineStatusError string + +const ( + // DeprecatedCAPIUpdateMachineError indicates an error while trying to update a Node that this + // Machine represents. This may indicate a transient problem that will be + // fixed automatically with time, such as a service outage, + // + // Example: error updating load balancers. + DeprecatedCAPIUpdateMachineError DeprecatedCAPIMachineStatusError = "UpdateError" +) + +// DeprecatedCAPIClusterStatusError defines errors states for Cluster objects. +type DeprecatedCAPIClusterStatusError string + +const ( + // DeprecatedCAPOUpdateClusterError indicates that an error was encountered + // when trying to update the cluster. + DeprecatedCAPOUpdateClusterError DeprecatedCAPIClusterStatusError = "UpdateError" +)