From cfdcb4a6f26e5a7a6b45ae96729da5815b3101e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20L=C3=B6nnegren?= Date: Mon, 11 Dec 2023 17:13:50 +0100 Subject: [PATCH] Fix channel sync bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During upgrades we have a race-condition for the ManagedOSVersionChannels. This commit checks to see if a ManagedOSVersionChannel syncer pod was created with another image than the provided elemental-operator and if true, will delete the old pod and recreate the syncer pod. Signed-off-by: Fredrik Lönnegren --- .../managedosversionchannel_controller.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/controllers/managedosversionchannel_controller.go b/controllers/managedosversionchannel_controller.go index 4f17677ac..c35f89755 100644 --- a/controllers/managedosversionchannel_controller.go +++ b/controllers/managedosversionchannel_controller.go @@ -22,10 +22,6 @@ import ( "fmt" "time" - elementalv1 "github.com/rancher/elemental-operator/api/v1beta1" - "github.com/rancher/elemental-operator/pkg/log" - "github.com/rancher/elemental-operator/pkg/syncer" - "github.com/rancher/elemental-operator/pkg/util" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" @@ -40,6 +36,11 @@ import ( "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/reconcile" + + elementalv1 "github.com/rancher/elemental-operator/api/v1beta1" + "github.com/rancher/elemental-operator/pkg/log" + "github.com/rancher/elemental-operator/pkg/syncer" + "github.com/rancher/elemental-operator/pkg/util" ) const ( @@ -204,6 +205,13 @@ func (r *ManagedOSVersionChannelReconciler) reconcile(ctx context.Context, manag return ctrl.Result{}, err } + // Sometimes during upgrade the new elemental-channel will be created using + // the old logic. This checks if this happened we recreate the syncer pod. + if pod.Spec.Containers[0].Image != r.OperatorImage { + _ = r.Delete(ctx, pod) + return ctrl.Result{}, r.createSyncerPod(ctx, managedOSVersionChannel, sync) + } + return r.handleSyncPod(ctx, pod, managedOSVersionChannel, interval), nil }