Skip to content

Commit

Permalink
fix: for rollouts getting stuck due to bad rs informer updates
Browse files Browse the repository at this point in the history
  • Loading branch information
zachaller committed Nov 30, 2023
1 parent 8cae284 commit 63bddcc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
11 changes: 9 additions & 2 deletions rollout/replicaset.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ func (c *rolloutContext) removeScaleDownDelay(rs *appsv1.ReplicaSet) error {
_, err := c.kubeclientset.AppsV1().ReplicaSets(rs.Namespace).Patch(ctx, rs.Name, patchtypes.JSONPatchType, []byte(patch), metav1.PatchOptions{})
if err == nil {
c.log.Infof("Removed '%s' annotation from RS '%s'", v1alpha1.DefaultReplicaSetScaleDownDeadlineAnnotationKey, rs.Name)
c.replicaSetInformer.GetIndexer().Update(rs)
err = c.replicaSetInformer.GetIndexer().Update(rs)
if err != nil {
return fmt.Errorf("error updating replicaset informer in removeScaleDownDelay", err)

Check failure on line 42 in rollout/replicaset.go

View workflow job for this annotation

GitHub Actions / Lint Go code

printf: fmt.Errorf call has arguments but no formatting directives (govet)
}

}
return err
}
Expand All @@ -62,7 +66,10 @@ func (c *rolloutContext) addScaleDownDelay(rs *appsv1.ReplicaSet, scaleDownDelay
rs, err := c.kubeclientset.AppsV1().ReplicaSets(rs.Namespace).Patch(ctx, rs.Name, patchtypes.JSONPatchType, []byte(patch), metav1.PatchOptions{})
if err == nil {
c.log.Infof("Set '%s' annotation on '%s' to %s (%s)", v1alpha1.DefaultReplicaSetScaleDownDeadlineAnnotationKey, rs.Name, deadline, scaleDownDelaySeconds)
c.replicaSetInformer.GetIndexer().Update(rs)
err = c.replicaSetInformer.GetIndexer().Update(rs)
if err != nil {
return fmt.Errorf("error updating replicaset informer in addScaleDownDelay", err)

Check failure on line 71 in rollout/replicaset.go

View workflow job for this annotation

GitHub Actions / Lint Go code

printf: fmt.Errorf call has arguments but no formatting directives (govet)
}
}
return err
}
Expand Down
21 changes: 15 additions & 6 deletions rollout/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ func (c *rolloutContext) syncReplicaSetRevision() (*appsv1.ReplicaSet, error) {
return nil, fmt.Errorf("error updating replicaset revision: %v", err)
}
c.log.Infof("Synced revision on ReplicaSet '%s' to '%s'", rs.Name, newRevision)
c.replicaSetInformer.GetIndexer().Update(rs)
err = c.replicaSetInformer.GetIndexer().Update(rs)
if err != nil {
return nil, fmt.Errorf("error updating replicaset informer in syncReplicaSetRevision: %v", err)
}
return rs, nil
}

Expand Down Expand Up @@ -373,11 +376,17 @@ func (c *rolloutContext) scaleReplicaSet(rs *appsv1.ReplicaSet, newScale int32,
delete(rsCopy.Annotations, v1alpha1.DefaultReplicaSetScaleDownDeadlineAnnotationKey)
}
rs, err = c.kubeclientset.AppsV1().ReplicaSets(rsCopy.Namespace).Update(ctx, rsCopy, metav1.UpdateOptions{})
if err == nil && sizeNeedsUpdate {
scaled = true
revision, _ := replicasetutil.Revision(rs)
c.recorder.Eventf(rollout, record.EventOptions{EventReason: conditions.ScalingReplicaSetReason}, conditions.ScalingReplicaSetMessage, scalingOperation, rs.Name, revision, oldScale, newScale)
c.replicaSetInformer.GetIndexer().Update(rs)
if err == nil {
err = c.replicaSetInformer.GetIndexer().Update(rs)
if err != nil {
err = fmt.Errorf("error updating replicaset informer in scaleReplicaSet", c.replicaSetInformer.GetIndexer().Update(rs))

Check failure on line 382 in rollout/sync.go

View workflow job for this annotation

GitHub Actions / Lint Go code

printf: fmt.Errorf call has arguments but no formatting directives (govet)
return scaled, rs, err
}
if sizeNeedsUpdate {
scaled = true
revision, _ := replicasetutil.Revision(rs)
c.recorder.Eventf(rollout, record.EventOptions{EventReason: conditions.ScalingReplicaSetReason}, conditions.ScalingReplicaSetMessage, scalingOperation, rs.Name, revision, oldScale, newScale)
}
}
}
return scaled, rs, err
Expand Down

0 comments on commit 63bddcc

Please sign in to comment.