Skip to content

Commit

Permalink
operator: fix ManagedOSVersionChannel sync (#769)
Browse files Browse the repository at this point in the history
* operator: fix ManagedOSVersionChannel sync
After the very fist initial sync, all subsequently channel syncs fail.
Fixed.
fixes: #766

* operator: don't assume ManagedOSVersion resources have annotations
Older resources may not have annotations yet: initialize the field.
Fixes: #767

---------

Signed-off-by: Francesco Giudici <[email protected]>
(cherry picked from commit 5ccde14)
  • Loading branch information
fgiudici committed Jun 20, 2024
1 parent 9f52a67 commit 80471bc
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions controllers/managedosversionchannel_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ func (r *ManagedOSVersionChannelReconciler) createManagedOSVersions(ctx context.
if lastSyncTime, found := version.Annotations[elementalv1.ElementalManagedOSVersionChannelLastSyncAnnotation]; !found || (lastSyncTime != syncTimestamp) {
logger.Info("ManagedOSVersion no longer synced through this channel", "name", version.Name)
patchBase := client.MergeFrom(version.DeepCopy())
if version.ObjectMeta.Annotations == nil {
version.ObjectMeta.Annotations = map[string]string{}
}
version.ObjectMeta.Annotations[elementalv1.ElementalManagedOSVersionNoLongerSyncedAnnotation] = elementalv1.ElementalManagedOSVersionNoLongerSyncedValue
if err := r.Patch(ctx, version, patchBase); err != nil {
logger.Error(err, "Could not patch ManagedOSVersion as no longer in sync", "name", version.Name)
Expand Down Expand Up @@ -460,6 +463,12 @@ func (r *ManagedOSVersionChannelReconciler) createSyncerPod(ctx context.Context,
return err
}

// If we don't update the LastSyncedTime on Pod creation, we will loop
// creating/deleting the Pod after the ManagedOSVersionChannel.spec.syncInterval
// see https://github.com/rancher/elemental-operator/issues/766
now := metav1.Now()
ch.Status.LastSyncedTime = &now

meta.SetStatusCondition(&ch.Status.Conditions, metav1.Condition{
Type: elementalv1.ReadyCondition,
Reason: elementalv1.SyncingReason,
Expand Down

0 comments on commit 80471bc

Please sign in to comment.