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

Revert "[v2.9] fix: Retry operation on conflict" #684

Merged
merged 1 commit into from
Oct 9, 2024
Merged
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
52 changes: 21 additions & 31 deletions controller/aks-cluster-config-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ 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 @@ -183,43 +182,34 @@ func (h *Handler) OnAksConfigRemoved(_ string, config *aksv1.AKSClusterConfig) (
// empty string will be written to status
func (h *Handler) recordError(onChange func(key string, config *aksv1.AKSClusterConfig) (*aksv1.AKSClusterConfig, error)) func(key string, config *aksv1.AKSClusterConfig) (*aksv1.AKSClusterConfig, error) {
return func(key string, config *aksv1.AKSClusterConfig) (*aksv1.AKSClusterConfig, error) {
var err error
var message string
config, onChangeErr := onChange(key, config)
config, err = onChange(key, config)
if config == nil {
// AKS config is likely deleting
return config, onChangeErr
return config, err
}
if err != nil {
message = err.Error()
}

if config.Status.FailureMessage == message {
return config, onChangeErr
return config, err
}
statusUpdateErr := retry.RetryOnConflict(retry.DefaultRetry, func() error {
// Fetch the latest version of the config
conf, err := h.aksCC.Get(config.Namespace, config.Name, metav1.GetOptions{})
if err != nil {
return err
}
// Ensure we're working on a deep copy
conf = conf.DeepCopy()
// Update status with the new failure message
if message != "" && conf.Status.Phase == aksConfigActivePhase {
// Can assume an update is failing
conf.Status.Phase = aksConfigUpdatingPhase
}
conf.Status.FailureMessage = message
// Try to update status
updatedConfig, err := h.aksCC.UpdateStatus(conf)
if err == nil {
config = updatedConfig
}
return err
})
if statusUpdateErr != nil {
logrus.Errorf(
"Error updating status for AKSClusterConfig [%s/%s]: %v. Original error from onChange: %v",
config.Spec.ClusterName, config.Name, statusUpdateErr, onChangeErr,
)

config = config.DeepCopy()
if message != "" && config.Status.Phase == aksConfigActivePhase {
// can assume an update is failing
config.Status.Phase = aksConfigUpdatingPhase
}
config.Status.FailureMessage = message

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())
}
return config, onChangeErr
return config, err
}
}

Expand Down
Loading