Skip to content

Commit

Permalink
fix: don't miss updates by using revision version
Browse files Browse the repository at this point in the history
  • Loading branch information
Pothulapati committed Oct 2, 2023
1 parent 0fbc4a9 commit 28b25da
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions internal/controller/dragonfly_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,32 +216,15 @@ func (r *DragonflyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (

return ctrl.Result{}, nil
} else {
// This is an Update
log.Info("updating existing resources")
newResources, err := resources.GetDragonflyResources(ctx, &df)
if err != nil {
log.Error(err, "could not get resources")
return ctrl.Result{}, err
}

// update all resources
for _, resource := range newResources {
if err := r.Update(ctx, resource); err != nil {
log.Error(err, fmt.Sprintf("could not update resource %s/%s/%s", resource.GetObjectKind(), resource.GetNamespace(), resource.GetName()))
return ctrl.Result{}, err
}
}

log.Info("Updated resources for object")

// perform a rollout only if the pod spec has changed
var statefulSet appsv1.StatefulSet
if err := r.Get(ctx, client.ObjectKey{Namespace: df.Namespace, Name: df.Name}, &statefulSet); err != nil {
log.Error(err, "could not get statefulset")
return ctrl.Result{}, err
}

if statefulSet.Status.UpdatedReplicas != statefulSet.Status.Replicas {
// Check if the pod spec has changed
log.Info("Checking if pod spec has changed", "currentRevision", statefulSet.Status.CurrentRevision, "updateRevision", statefulSet.Status.UpdateRevision)
if statefulSet.Status.UpdatedReplicas != statefulSet.Status.Replicas || statefulSet.Status.CurrentRevision != statefulSet.Status.UpdateRevision {
log.Info("Pod spec has changed, performing a rollout")
r.EventRecorder.Event(&df, corev1.EventTypeNormal, "Rollout", "Starting a rollout")

Expand All @@ -257,8 +240,27 @@ func (r *DragonflyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
}
r.EventRecorder.Event(&df, corev1.EventTypeNormal, "Resources", "Updated resources")

// This is an Update
log.Info("updating existing resources")
newResources, err := resources.GetDragonflyResources(ctx, &df)
if err != nil {
log.Error(err, "could not get resources")
return ctrl.Result{}, err
}

// update all resources
for _, resource := range newResources {
if err := r.Update(ctx, resource); err != nil {
log.Error(err, fmt.Sprintf("could not update resource %s/%s/%s", resource.GetObjectKind(), resource.GetNamespace(), resource.GetName()))
return ctrl.Result{}, err
}
}

log.Info("Updated resources for object. Requeing")
r.EventRecorder.Event(&df, corev1.EventTypeNormal, "Resources", "Updated resources")
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
}
return ctrl.Result{}, nil
}

// SetupWithManager sets up the controller with the Manager.
Expand Down

0 comments on commit 28b25da

Please sign in to comment.