Skip to content

Commit

Permalink
Fix channel sync bug
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
frelon committed Dec 11, 2023
1 parent 80eb846 commit cfdcb4a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions controllers/managedosversionchannel_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit cfdcb4a

Please sign in to comment.