From 80471bc34936213997c120b5217f06c3682e5ef0 Mon Sep 17 00:00:00 2001 From: Francesco Giudici Date: Wed, 19 Jun 2024 18:20:40 +0200 Subject: [PATCH] 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 --------- Signed-off-by: Francesco Giudici (cherry picked from commit 5ccde141e687e20788acb62542660369b9e47861) --- controllers/managedosversionchannel_controller.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/controllers/managedosversionchannel_controller.go b/controllers/managedosversionchannel_controller.go index 16518223..80569bf9 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) @@ -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,