Skip to content

Commit

Permalink
fix: Reconcile SO's status.GVKR if there is any mismatch (#5300)
Browse files Browse the repository at this point in the history
* fix: Reconcille SO's status.GVKR if there is any mismatch

Signed-off-by: Jorge Turrado <[email protected]>

* fix nill reference

Signed-off-by: Jorge Turrado <[email protected]>

---------

Signed-off-by: Jorge Turrado <[email protected]>
  • Loading branch information
JorTurFer authored Dec 28, 2023
1 parent 9d9daa9 commit 4d9d3f2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions controllers/keda/scaledobject_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,20 @@ func (r *ScaledObjectReconciler) checkTargetResourceIsScalable(ctx context.Conte
gvkString := gvkr.GVKString()
logger.V(1).Info("Parsed Group, Version, Kind, Resource", "GVK", gvkString, "Resource", gvkr.Resource)

statusGvkString := ""
if scaledObject.Status.ScaleTargetGVKR != nil {
statusGvkr, _ := kedav1alpha1.ParseGVKR(r.restMapper, scaledObject.Status.ScaleTargetGVKR.Version, scaledObject.Status.ScaleTargetGVKR.Kind)
statusGvkString = statusGvkr.GVKString()
logger.V(1).Info("Status Group, Version, Kind, Resource", "GVK", statusGvkString, "Resource", statusGvkr.Resource)
}

// do we need the scale to update the status later?
present := scaledObject.HasPausedAnnotation()
removePausedStatus := scaledObject.Status.PausedReplicaCount != nil && !present
wantStatusUpdate := scaledObject.Status.ScaleTargetKind != gvkString || scaledObject.Status.OriginalReplicaCount == nil || removePausedStatus
wantStatusUpdate := scaledObject.Status.ScaleTargetKind != gvkString ||
statusGvkString != gvkString ||
scaledObject.Status.OriginalReplicaCount == nil ||
removePausedStatus

// check if we already know.
var scale *autoscalingv1.Scale
Expand Down Expand Up @@ -398,7 +408,7 @@ func (r *ScaledObjectReconciler) checkTargetResourceIsScalable(ctx context.Conte
// - store original scaleTarget's replica count (before scaling with KEDA)
if wantStatusUpdate {
status := scaledObject.Status.DeepCopy()
if scaledObject.Status.ScaleTargetKind != gvkString {
if scaledObject.Status.ScaleTargetKind != gvkString || gvkString != statusGvkString {
status.ScaleTargetKind = gvkString
status.ScaleTargetGVKR = &gvkr
}
Expand Down

0 comments on commit 4d9d3f2

Please sign in to comment.