Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Properly check errors.Cause when checking with apierrors #3967

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bootstrap/kubeadm/controllers/kubeadmconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques

// Look up the owner of this KubeConfig if there is one
configOwner, err := bsutil.GetConfigOwner(ctx, r.Client, config)
if apierrors.IsNotFound(err) {
if apierrors.IsNotFound(errors.Cause(err)) {
vincepri marked this conversation as resolved.
Show resolved Hide resolved
// Could not find the owner yet, this is not an error and will rereconcile when the owner gets set.
return ctrl.Result{}, nil
}
Expand All @@ -158,7 +158,7 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{}, nil
}

if apierrors.IsNotFound(err) {
if apierrors.IsNotFound(errors.Cause(err)) {
log.Info("Cluster does not exist yet, waiting until it is created")
return ctrl.Result{}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/clusterctl/client/cluster/cert_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (cm *certManagerClient) deleteObjs(objs []unstructured.Unstructured) error
if err := retryWithExponentialBackoff(deleteCertManagerBackoff, func() error {
if err := cm.deleteObj(obj); err != nil {
// tolerate NotFound errors when deleting the test resources
if apierrors.IsNotFound(err) {
if apierrors.IsNotFound(errors.Cause(err)) {
return nil
}
return err
Expand Down Expand Up @@ -523,7 +523,7 @@ func (cm *certManagerClient) waitForAPIReady(ctx context.Context, retry bool) er
if err := retryWithExponentialBackoff(deleteCertManagerBackoff, func() error {
if err := cm.deleteObj(obj); err != nil {
// tolerate NotFound errors when deleting the test resources
if apierrors.IsNotFound(err) {
if apierrors.IsNotFound(errors.Cause(err)) {
return nil
}
return err
Expand Down
2 changes: 1 addition & 1 deletion controllers/cluster_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (r *ClusterReconciler) reconcileKubeconfig(ctx context.Context, cluster *cl

_, err := secret.Get(ctx, r.Client, util.ObjectKey(cluster), secret.Kubeconfig)
switch {
case apierrors.IsNotFound(err):
case apierrors.IsNotFound(errors.Cause(err)):
if err := kubeconfig.CreateSecret(ctx, r.Client, cluster); err != nil {
if err == kubeconfig.ErrDependentCertificateNotFound {
log.Info("could not find secret for cluster, requeuing", "secret", secret.ClusterCA)
Expand Down
2 changes: 1 addition & 1 deletion controllers/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func (r *MachineReconciler) isDeleteNodeAllowed(ctx context.Context, cluster *cl
// managed control plane check if it is nil
if cluster.Spec.ControlPlaneRef != nil {
controlPlane, err := external.Get(ctx, r.Client, cluster.Spec.ControlPlaneRef, cluster.Spec.ControlPlaneRef.Namespace)
if apierrors.IsNotFound(err) {
if apierrors.IsNotFound(errors.Cause(err)) {
// If control plane object in the reference does not exist, log and skip check for
// external managed control plane
log.Error(err, "control plane object specified in cluster spec.controlPlaneRef does not exist", "kind", cluster.Spec.ControlPlaneRef.Kind, "name", cluster.Spec.ControlPlaneRef.Name)
Expand Down
2 changes: 1 addition & 1 deletion controllers/machinehealthcheck_targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (r *MachineHealthCheckReconciler) getTargetsFromMHC(ctx context.Context, cl
}
node, err := r.getNodeFromMachine(ctx, clusterClient, target.Machine)
if err != nil {
if !apierrors.IsNotFound(err) {
if !apierrors.IsNotFound(errors.Cause(err)) {
return nil, errors.Wrap(err, "error getting node")
}

Expand Down
2 changes: 1 addition & 1 deletion controlplane/kubeadm/controllers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r *KubeadmControlPlaneReconciler) reconcileKubeconfig(ctx context.Context,
controllerOwnerRef := *metav1.NewControllerRef(kcp, controlplanev1.GroupVersion.WithKind("KubeadmControlPlane"))
configSecret, err := secret.GetFromNamespacedName(ctx, r.Client, clusterName, secret.Kubeconfig)
switch {
case apierrors.IsNotFound(err):
case apierrors.IsNotFound(errors.Cause(err)):
createErr := kubeconfig.CreateSecretWithOwner(
ctx,
r.Client,
Expand Down
2 changes: 1 addition & 1 deletion exp/addons/controllers/clusterresourceset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (r *ClusterResourceSetReconciler) ApplyClusterResourceSet(ctx context.Conte
conditions.MarkFalse(clusterResourceSet, addonsv1.ResourcesAppliedCondition, addonsv1.RetrievingResourceFailedReason, clusterv1.ConditionSeverityWarning, err.Error())

// Continue without adding the error to the aggregate if we can't find the resource.
if apierrors.IsNotFound(err) {
if apierrors.IsNotFound(errors.Cause(err)) {
continue
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ func (r *ClusterResourceSetBindingReconciler) Reconcile(ctx context.Context, req
}

cluster, err := util.GetOwnerCluster(ctx, r.Client, binding.ObjectMeta)
if err != nil && !apierrors.IsNotFound(err) {
if err != nil && !apierrors.IsNotFound(errors.Cause(err)) {
return ctrl.Result{}, err
}

// If the owner cluster is already deleted or in deletion process, delete its ClusterResourceSetBinding
if apierrors.IsNotFound(err) || !cluster.DeletionTimestamp.IsZero() {
if apierrors.IsNotFound(errors.Cause(err)) || !cluster.DeletionTimestamp.IsZero() {
log.Info("deleting ClusterResourceSetBinding because the owner Cluster no longer exists")
err := r.Client.Delete(ctx, binding)
return ctrl.Result{}, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func (r *DockerMachineReconciler) DockerClusterToDockerMachines(o client.Object)

cluster, err := util.GetOwnerCluster(context.TODO(), r.Client, c.ObjectMeta)
switch {
case apierrors.IsNotFound(err) || cluster == nil:
case apierrors.IsNotFound(errors.Cause(err)) || cluster == nil:
return result
case err != nil:
return result
Expand Down
2 changes: 1 addition & 1 deletion util/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func RegenerateSecret(ctx context.Context, c client.Client, configSecret *corev1
func generateKubeconfig(ctx context.Context, c client.Client, clusterName client.ObjectKey, endpoint string) ([]byte, error) {
clusterCA, err := secret.GetFromNamespacedName(ctx, c, clusterName, secret.ClusterCA)
if err != nil {
if apierrors.IsNotFound(err) {
if apierrors.IsNotFound(errors.Cause(err)) {
return nil, ErrDependentCertificateNotFound
}
return nil, err
Expand Down