Skip to content

Commit

Permalink
[v1.6.x][BACKPORT] operator: fix ManagedOSVersionChannel sync (#771)
Browse files Browse the repository at this point in the history
* operator: fix ManagedOSVersionChannel sync (#769)

* 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

(cherry picked from commit 5ccde14)


* operator: always update managedosversionchannel last sync time (#772)

...also if we have an error on Pod creation.

Fixes commit 5ccde14

(cherry picked from commit 7227947)

Signed-off-by: Francesco Giudici <[email protected]>
  • Loading branch information
fgiudici authored Jun 20, 2024
1 parent 9f52a67 commit a2a8c62
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 @@ -445,6 +448,12 @@ func (r *ManagedOSVersionChannelReconciler) createSyncerPod(ctx context.Context,
},
}

// 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

err := r.Create(ctx, pod)
if err != nil {
logger.Error(err, "Failed creating pod", "pod", ch.Name)
Expand Down

0 comments on commit a2a8c62

Please sign in to comment.