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

ScaledObject.Status update should handle stale resource #582

Merged
merged 1 commit into from
Jan 30, 2020
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
19 changes: 19 additions & 0 deletions pkg/handler/scale_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/go-logr/logr"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -44,9 +45,27 @@ func NewScaleHandler(client client.Client, reconcilerScheme *runtime.Scheme) *Sc
func (h *ScaleHandler) updateScaledObjectStatus(scaledObject *kedav1alpha1.ScaledObject) error {
err := h.client.Status().Update(context.TODO(), scaledObject)
if err != nil {
if errors.IsConflict(err) {
// ScaledObject's metadata that are not necessary to restart the ScaleLoop were updated (eg. labels)
// we should try to fetch the scaledObject again and process the update once again
h.logger.V(1).Info("Trying to fetch updated version of ScaledObject to properly update it's Status")
updatedScaledObject := &kedav1alpha1.ScaledObject{}
err2 := h.client.Get(context.TODO(), types.NamespacedName{Name: scaledObject.Name, Namespace: scaledObject.Namespace}, updatedScaledObject)
if err2 != nil {
h.logger.Error(err2, "Error getting updated version of ScaledObject before updating it's Status")
} else {
scaledObject = updatedScaledObject
if h.client.Status().Update(context.TODO(), scaledObject) == nil {
h.logger.V(1).Info("ScaledObject's Status was properly updated on re-fetched ScaledObject")
return nil
}
}
}
// we got another type of error
h.logger.Error(err, "Error updating scaledObject status")
return err
}
h.logger.V(1).Info("ScaledObject's Status was properly updated")
return nil
}

Expand Down