From 1055eab16fd0a3aeddb5737ff2a5d4c9476fdf60 Mon Sep 17 00:00:00 2001 From: Abhradeep Chakraborty Date: Thu, 15 Aug 2024 20:49:48 +0530 Subject: [PATCH] debug Signed-off-by: Abhradeep Chakraborty --- e2e/dragonfly_controller_test.go | 23 +++-- internal/controller/dragonfly_controller.go | 93 +++++++++------------ 2 files changed, 57 insertions(+), 59 deletions(-) diff --git a/e2e/dragonfly_controller_test.go b/e2e/dragonfly_controller_test.go index fb91842..70589e7 100644 --- a/e2e/dragonfly_controller_test.go +++ b/e2e/dragonfly_controller_test.go @@ -478,10 +478,19 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, FlakeAttempts(3), func() // check for affinity Expect(pod.Spec.Affinity.NodeAffinity.PreferredDuringSchedulingIgnoredDuringExecution).To(Equal(newAffinity.NodeAffinity.PreferredDuringSchedulingIgnoredDuringExecution)) } + // Update df to the latest + err = k8sClient.Get(ctx, types.NamespacedName{ + Name: name, + Namespace: namespace, + }, &df) + Expect(err).To(BeNil()) + GinkgoLogr.Info("df arg propagate phase", "phase", df.Status.Phase, "rolling-update", df.Status.IsRollingUpdate) + }) It("Check for data", func() { stopChan := make(chan struct{}, 1) + defer close(stopChan) rc, err := checkAndK8sPortForwardRedis(ctx, clientset, cfg, stopChan, name, namespace, password, 6395) Expect(err).To(BeNil()) @@ -489,7 +498,6 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, FlakeAttempts(3), func() data, err := rc.Get(ctx, "foo").Result() Expect(err).To(BeNil()) Expect(data).To(Equal("bar")) - defer close(stopChan) }) It("Change Service specification to LoadBalancer", func() { @@ -512,14 +520,15 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, FlakeAttempts(3), func() Labels: newLabels, } + GinkgoLogr.Info("df phase", "phase", df.Status.Phase, "rolling-update", df.Status.IsRollingUpdate) err = k8sClient.Update(ctx, &df) Expect(err).To(BeNil()) - // Wait until Dragonfly object is marked ready - err = waitForDragonflyPhase(ctx, k8sClient, name, namespace, controller.PhaseReady, 3*time.Minute) - Expect(err).To(BeNil()) - err = waitForStatefulSetReady(ctx, k8sClient, name, namespace, 3*time.Minute) - Expect(err).To(BeNil()) + // // Wait until Dragonfly object is marked ready + // err = waitForDragonflyPhase(ctx, k8sClient, name, namespace, controller.PhaseReady, 1*time.Minute) + // Expect(err).To(BeNil()) + // err = waitForStatefulSetReady(ctx, k8sClient, name, namespace, 3*time.Minute) + // Expect(err).To(BeNil()) var svc corev1.Service err = k8sClient.Get(ctx, types.NamespacedName{ @@ -919,6 +928,8 @@ func isDragonflyInphase(ctx context.Context, c client.Client, name, namespace, p return false, nil } + GinkgoLogr.Info("dragonfly phase", "phase", df.Status.Phase, "update", df.Status.IsRollingUpdate) + // Ready means we also want rolling update to be false if phase == controller.PhaseReady { // check for replicas diff --git a/internal/controller/dragonfly_controller.go b/internal/controller/dragonfly_controller.go index 1cb2688..519a642 100644 --- a/internal/controller/dragonfly_controller.go +++ b/internal/controller/dragonfly_controller.go @@ -19,16 +19,13 @@ package controller import ( "context" "fmt" - "slices" "time" dfv1alpha1 "github.com/dragonflydb/dragonfly-operator/api/v1alpha1" "github.com/dragonflydb/dragonfly-operator/internal/resources" - "github.com/samber/lo" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/tools/record" ctrl "sigs.k8s.io/controller-runtime" @@ -117,16 +114,6 @@ func (r *DragonflyReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( return ctrl.Result{}, err } - // If df updates an immutable field, delete the statefulset with Orphan propagation policy - // and recreate the statefulset in the next loop. - if r.cantUpdateStatefulSet(&df, &statefulSet) { - var err error - if err = r.Delete(ctx, &statefulSet, client.PropagationPolicy(v1.DeletePropagationOrphan)); err != nil { - log.Error(err, fmt.Sprintf("could not delete statefulset %s/%s", statefulSet.GetNamespace(), statefulSet.GetName())) - } - return ctrl.Result{Requeue: true}, err - } - // Update all resources even if the df is in rollout state to ensure // that newer updates don't get blocked by failed update attempts. log.Info("updating existing resources") @@ -361,46 +348,46 @@ func (r *DragonflyReconciler) getMissingResources(ctx context.Context, df *dfv1a return missingResources, nil } -func (r *DragonflyReconciler) isPVCSpecChanged(df *dfv1alpha1.Dragonfly, sts *appsv1.StatefulSet) bool { - dfPVCSpec := getPVCSpecFromDragonfly(df) - stsPVCSpec := getPVCSpecFromStatefulSet(sts) - - return !isPVCSpecEqual(dfPVCSpec, stsPVCSpec) -} - -func getPVCSpecFromDragonfly(df *dfv1alpha1.Dragonfly) *corev1.PersistentVolumeClaimSpec { - if df.Spec.Snapshot != nil { - return df.Spec.Snapshot.PersistentVolumeClaimSpec - } - return nil -} - -func getPVCSpecFromStatefulSet(sts *appsv1.StatefulSet) *corev1.PersistentVolumeClaimSpec { - for i := range sts.Spec.VolumeClaimTemplates { - if sts.Spec.VolumeClaimTemplates[i].Name == "df" { - return &sts.Spec.VolumeClaimTemplates[i].Spec - } - } - return nil -} - -func isPVCSpecEqual(spec1, spec2 *corev1.PersistentVolumeClaimSpec) bool { - if spec1 == nil && spec2 == nil { - return true - } - if spec1 == nil || spec2 == nil { - return false - } - - // Compare essential fields - return slices.Equal(spec1.AccessModes, spec2.AccessModes) && - lo.FromPtr(spec1.StorageClassName) == lo.FromPtr(spec2.StorageClassName) && - spec1.Resources.Requests.Storage().Equal(*spec2.Resources.Requests.Storage()) -} - -func (r *DragonflyReconciler) cantUpdateStatefulSet(df *dfv1alpha1.Dragonfly, sts *appsv1.StatefulSet) bool { - return r.isPVCSpecChanged(df, sts) -} +// func (r *DragonflyReconciler) isPVCSpecChanged(df *dfv1alpha1.Dragonfly, sts *appsv1.StatefulSet) bool { +// dfPVCSpec := getPVCSpecFromDragonfly(df) +// stsPVCSpec := getPVCSpecFromStatefulSet(sts) + +// return !isPVCSpecEqual(dfPVCSpec, stsPVCSpec) +// } + +// func getPVCSpecFromDragonfly(df *dfv1alpha1.Dragonfly) *corev1.PersistentVolumeClaimSpec { +// if df.Spec.Snapshot != nil { +// return df.Spec.Snapshot.PersistentVolumeClaimSpec +// } +// return nil +// } + +// func getPVCSpecFromStatefulSet(sts *appsv1.StatefulSet) *corev1.PersistentVolumeClaimSpec { +// for i := range sts.Spec.VolumeClaimTemplates { +// if sts.Spec.VolumeClaimTemplates[i].Name == "df" { +// return &sts.Spec.VolumeClaimTemplates[i].Spec +// } +// } +// return nil +// } + +// func isPVCSpecEqual(spec1, spec2 *corev1.PersistentVolumeClaimSpec) bool { +// if spec1 == nil && spec2 == nil { +// return true +// } +// if spec1 == nil || spec2 == nil { +// return false +// } + +// // Compare essential fields +// return slices.Equal(spec1.AccessModes, spec2.AccessModes) && +// lo.FromPtr(spec1.StorageClassName) == lo.FromPtr(spec2.StorageClassName) && +// spec1.Resources.Requests.Storage().Equal(*spec2.Resources.Requests.Storage()) +// } + +// func (r *DragonflyReconciler) cantUpdateStatefulSet(df *dfv1alpha1.Dragonfly, sts *appsv1.StatefulSet) bool { +// return r.isPVCSpecChanged(df, sts) +// } // SetupWithManager sets up the controller with the Manager. func (r *DragonflyReconciler) SetupWithManager(mgr ctrl.Manager) error {