Skip to content

Commit

Permalink
Merge pull request #4048 from nojnhuh/ammp-transient
Browse files Browse the repository at this point in the history
[release-1.10] add transient error handling to AMMP delete
  • Loading branch information
k8s-ci-robot authored Sep 28, 2023
2 parents d9c791d + a9cc1c6 commit 1862e18
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions controllers/azuremanagedmachinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controllers

import (
"context"
"fmt"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -311,6 +312,16 @@ func (ammpr *AzureManagedMachinePoolReconciler) reconcileDelete(ctx context.Cont
}

if err := svc.Delete(ctx); err != nil {
// Handle transient errors
var reconcileError azure.ReconcileError
if errors.As(err, &reconcileError) && reconcileError.IsTransient() {
if azure.IsOperationNotDoneError(reconcileError) {
log.V(2).Info(fmt.Sprintf("AzureManagedMachinePool delete not done: %s", reconcileError.Error()))
} else {
log.V(2).Info("transient failure to delete AzureManagedMachinePool, retrying")
}
return reconcile.Result{RequeueAfter: reconcileError.RequeueAfter()}, nil
}
return reconcile.Result{}, errors.Wrapf(err, "error deleting AzureManagedMachinePool %s/%s", scope.InfraMachinePool.Namespace, scope.InfraMachinePool.Name)
}
// Machine pool successfully deleted, remove the finalizer.
Expand Down
18 changes: 18 additions & 0 deletions controllers/azuremanagedmachinepool_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ import (
"github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/golang/mock/gomock"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/utils/pointer"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/azure/mock_azure"
"sigs.k8s.io/cluster-api-provider-azure/azure/scope"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/agentpools"
Expand Down Expand Up @@ -95,6 +97,22 @@ func TestAzureManagedMachinePoolReconcile(t *testing.T) {
g.Expect(err).NotTo(HaveOccurred())
},
},
{
name: "Reconcile delete transient error",
Setup: func(cb *fake.ClientBuilder, reconciler *mock_azure.MockReconcilerMockRecorder, agentpools *mock_agentpools.MockAgentPoolScopeMockRecorder, _ *MockNodeListerMockRecorder) {
cluster, azManagedCluster, azManagedControlPlane, ammp, mp := newReadyAzureManagedMachinePoolCluster()
reconciler.Delete(gomock2.AContext()).Return(azure.WithTransientError(errors.New("transient"), 76*time.Second))
agentpools.Name()
ammp.DeletionTimestamp = &metav1.Time{
Time: time.Now(),
}
cb.WithObjects(cluster, azManagedCluster, azManagedControlPlane, ammp, mp)
},
Verify: func(g *WithT, result ctrl.Result, err error) {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(result.RequeueAfter).To(Equal(76 * time.Second))
},
},
}

for _, c := range cases {
Expand Down

0 comments on commit 1862e18

Please sign in to comment.