From 49f0057a1983b6b184ab0c0e3cdffbf1860c30d2 Mon Sep 17 00:00:00 2001 From: trafalgarzzz Date: Fri, 13 Jun 2025 16:48:03 +0800 Subject: [PATCH 1/2] bugfix: fix juicefsruntime stucks with "worker not ready" and no worker pod created Signed-off-by: trafalgarzzz --- pkg/ddc/juicefs/master.go | 26 +++++++------------------ pkg/ddc/juicefs/master_internal.go | 3 +-- pkg/ddc/juicefs/master_internal_test.go | 8 ++++---- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/pkg/ddc/juicefs/master.go b/pkg/ddc/juicefs/master.go index f62ef9dc7b5..954e33dcd11 100644 --- a/pkg/ddc/juicefs/master.go +++ b/pkg/ddc/juicefs/master.go @@ -22,12 +22,10 @@ import ( "github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient" - corev1 "k8s.io/api/core/v1" apierrs "k8s.io/apimachinery/pkg/api/errors" "k8s.io/client-go/util/retry" datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" - "github.com/fluid-cloudnative/fluid/pkg/utils" ) func (j JuiceFSEngine) CheckMasterReady() (ready bool, err error) { @@ -35,6 +33,9 @@ func (j JuiceFSEngine) CheckMasterReady() (ready bool, err error) { return true, nil } +// ShouldSetupMaster checks if a further call of func `SetupMaster` is needed. +// JuiceFS Runtime has no master role, so the function check runtime.status.WorkerPhase +// to know if juicefs is installed and set up. func (j JuiceFSEngine) ShouldSetupMaster() (should bool, err error) { runtime, err := j.getRuntime() if err != nil { @@ -50,6 +51,9 @@ func (j JuiceFSEngine) ShouldSetupMaster() (should bool, err error) { return } +// SetupMaster installs juicefs components into the cluster. +// JuiceFS Runtime has no master role, implementing func `SetupMaster` here +// is just for a same lifecycle as other runtimes (other runtimes may have master component) func (j JuiceFSEngine) SetupMaster() (err error) { workerName := j.getWorkerName() @@ -58,7 +62,7 @@ func (j JuiceFSEngine) SetupMaster() (err error) { if err != nil && apierrs.IsNotFound(err) { //1. Is not found error j.Log.V(1).Info("SetupMaster", "worker", workerName) - return j.setupMasterInternal() + return j.installJuiceFS() } else if err != nil { //2. Other errors return @@ -75,26 +79,10 @@ func (j JuiceFSEngine) SetupMaster() (err error) { } runtimeToUpdate := runtime.DeepCopy() - runtimeToUpdate.Status.WorkerPhase = datav1alpha1.RuntimePhaseNotReady - replicas := runtimeToUpdate.Spec.Worker.Replicas - if replicas == 0 { - replicas = 1 - } - // Init selector for worker runtimeToUpdate.Status.Selector = j.getWorkerSelectors() - runtimeToUpdate.Status.DesiredWorkerNumberScheduled = replicas runtimeToUpdate.Status.ValueFileConfigmap = j.getHelmValuesConfigMapName() - if len(runtimeToUpdate.Status.Conditions) == 0 { - runtimeToUpdate.Status.Conditions = []datav1alpha1.RuntimeCondition{} - } - cond := utils.NewRuntimeCondition(datav1alpha1.RuntimeWorkersInitialized, datav1alpha1.RuntimeWorkersInitializedReason, - "The worker is initialized.", corev1.ConditionTrue) - runtimeToUpdate.Status.Conditions = - utils.UpdateRuntimeCondition(runtimeToUpdate.Status.Conditions, - cond) - if !reflect.DeepEqual(runtime.Status, runtimeToUpdate.Status) { return j.Client.Status().Update(context.TODO(), runtimeToUpdate) } diff --git a/pkg/ddc/juicefs/master_internal.go b/pkg/ddc/juicefs/master_internal.go index 8bc0a958310..4cbf7703c0c 100644 --- a/pkg/ddc/juicefs/master_internal.go +++ b/pkg/ddc/juicefs/master_internal.go @@ -29,8 +29,7 @@ import ( "github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient" ) -// setup fuse -func (j *JuiceFSEngine) setupMasterInternal() (err error) { +func (j *JuiceFSEngine) installJuiceFS() (err error) { var ( chartName = utils.GetChartsDirectory() + "/" + common.JuiceFSChart ) diff --git a/pkg/ddc/juicefs/master_internal_test.go b/pkg/ddc/juicefs/master_internal_test.go index 6ac34526ced..b26b3455e27 100644 --- a/pkg/ddc/juicefs/master_internal_test.go +++ b/pkg/ddc/juicefs/master_internal_test.go @@ -153,7 +153,7 @@ func TestSetupMasterInternal(t *testing.T) { if err != nil { t.Fatal(err.Error()) } - err = engine.setupMasterInternal() + err = engine.installJuiceFS() if err != nil { t.Errorf("fail to exec check helm release: %v", err) } @@ -164,7 +164,7 @@ func TestSetupMasterInternal(t *testing.T) { if err != nil { t.Fatal(err.Error()) } - err = engine.setupMasterInternal() + err = engine.installJuiceFS() if err == nil { t.Errorf("fail to catch the error: %v", err) } @@ -181,7 +181,7 @@ func TestSetupMasterInternal(t *testing.T) { if err != nil { t.Fatal(err.Error()) } - err = engine.setupMasterInternal() + err = engine.installJuiceFS() if err == nil { t.Errorf("fail to catch the error") } @@ -192,7 +192,7 @@ func TestSetupMasterInternal(t *testing.T) { if err != nil { t.Fatal(err.Error()) } - err = engine.setupMasterInternal() + err = engine.installJuiceFS() fmt.Println(err) if err != nil { t.Errorf("fail to install release") From 93904439fb6f439e88c441cfd5f32ee54004097a Mon Sep 17 00:00:00 2001 From: trafalgarzzz Date: Fri, 13 Jun 2025 17:08:34 +0800 Subject: [PATCH 2/2] fix unit tests Signed-off-by: trafalgarzzz --- pkg/ddc/alluxio/deprecated_label_test.go | 2 +- pkg/ddc/juicefs/master_test.go | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/pkg/ddc/alluxio/deprecated_label_test.go b/pkg/ddc/alluxio/deprecated_label_test.go index 4dbd17d227c..ea0e04ae92d 100644 --- a/pkg/ddc/alluxio/deprecated_label_test.go +++ b/pkg/ddc/alluxio/deprecated_label_test.go @@ -53,7 +53,7 @@ func getTestAlluxioEngine(client client.Client, name string, namespace string) * // - name (string): The name of the resource. // - suffix (string): The suffix of the label, which is not used in this test case. // -// This test checks various combinations of `namespace` and `name`, +// This test checks various combinations of `namespace` and `name`, // and validates whether the generated label name matches the expected output, ensuring the function logic is correct. func TestAlluxioEngine_GetDeprecatedCommonLabelname(t *testing.T) { testCases := []struct { diff --git a/pkg/ddc/juicefs/master_test.go b/pkg/ddc/juicefs/master_test.go index 11272d77a0d..806f1604373 100644 --- a/pkg/ddc/juicefs/master_test.go +++ b/pkg/ddc/juicefs/master_test.go @@ -147,15 +147,6 @@ func TestJuiceFSEngine_SetupMaster(t *testing.T) { t.Errorf("fail to exec the func with error %v", err) return } - juicefsruntime, err := test.engine.getRuntime() - if err != nil { - t.Errorf("fail to get the runtime") - return - } - if juicefsruntime.Status.WorkerPhase == datav1alpha1.RuntimePhaseNone { - t.Errorf("fail to update the runtime") - return - } } }