Skip to content

Commit

Permalink
fix: Retry operation on conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
yiannistri committed Sep 20, 2024
1 parent 77c44f3 commit c1600bd
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions controller/aks-cluster-config-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/retry"

"github.com/rancher/aks-operator/pkg/aks"
"github.com/rancher/aks-operator/pkg/aks/services"
Expand Down Expand Up @@ -184,7 +185,25 @@ func (h *Handler) recordError(onChange func(key string, config *aksv1.AKSCluster
return func(key string, config *aksv1.AKSClusterConfig) (*aksv1.AKSClusterConfig, error) {
var err error
var message string
config, err = onChange(key, config)

err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
// AKS config is being deleted
if config == nil {
return nil
}

conf, err := h.aksCC.Get(config.Namespace, config.Name, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("AKSClusterConfig [%s (id: %s)] was not found: %w", config.Spec.ClusterName, config.Name, err)
}

conf, err = onChange(key, conf)
if err == nil {
config = conf
}
return err
})

if config == nil {
// AKS config is likely deleting
return config, err
Expand All @@ -207,7 +226,7 @@ func (h *Handler) recordError(onChange func(key string, config *aksv1.AKSCluster
var recordErr error
config, recordErr = h.aksCC.UpdateStatus(config)
if recordErr != nil {
logrus.Errorf("Error recording akscc [%s (id: %s)] failure message: %s", config.Spec.ClusterName, config.Name, recordErr.Error())
logrus.Errorf("Error updating status for AKSClusterConfig [%s (id: %s)] failure message: %s", config.Spec.ClusterName, config.Name, recordErr.Error())
}
return config, err
}
Expand Down

0 comments on commit c1600bd

Please sign in to comment.