From a2a8c62b08edfadfbf551c8bbfea0b89fcfe2320 Mon Sep 17 00:00:00 2001 From: Francesco Giudici Date: Thu, 20 Jun 2024 18:05:12 +0200 Subject: [PATCH] [v1.6.x][BACKPORT] operator: fix ManagedOSVersionChannel sync (#771) * operator: fix ManagedOSVersionChannel sync (#769) * operator: fix ManagedOSVersionChannel sync After the very fist initial sync, all subsequently channel syncs fail. Fixed. fixes: https://github.com/rancher/elemental-operator/issues/766 * operator: don't assume ManagedOSVersion resources have annotations Older resources may not have annotations yet: initialize the field. Fixes: https://github.com/rancher/elemental-operator/issues/767 (cherry picked from commit 5ccde141e687e20788acb62542660369b9e47861) * operator: always update managedosversionchannel last sync time (#772) ...also if we have an error on Pod creation. Fixes commit 5ccde141e687e20788acb62542660369b9e47861 (cherry picked from commit 7227947d5026a8e0e943578e691ec8099b45d53e) Signed-off-by: Francesco Giudici --- controllers/managedosversionchannel_controller.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/controllers/managedosversionchannel_controller.go b/controllers/managedosversionchannel_controller.go index 16518223..b32b527c 100644 --- a/controllers/managedosversionchannel_controller.go +++ b/controllers/managedosversionchannel_controller.go @@ -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) @@ -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)