Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable metadata auto-sync for ThinRuntime by default #4281

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion api/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ type CleanCachePolicy struct {
// MetadataSyncPolicy defines policies when syncing metadata
type MetadataSyncPolicy struct {
// AutoSync enables automatic metadata sync when setting up a runtime. If not set, it defaults to true.
// +kubebuilder:default=true
// +optional
AutoSync *bool `json:"autoSync,omitempty"`
}
Expand Down
1 change: 0 additions & 1 deletion charts/fluid/fluid/crds/data.fluid.io_alluxioruntimes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,6 @@ spec:
metadata when setting up the runtime. If not set,
properties:
autoSync:
default: true
description: AutoSync enables automatic metadata sync when
setting up a runtime. If not set, it defaults to true.
type: boolean
Expand Down
1 change: 0 additions & 1 deletion charts/fluid/fluid/crds/data.fluid.io_thinruntimes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,6 @@ spec:
metadata when setting up the runtime. If not set,
properties:
autoSync:
default: true
description: AutoSync enables automatic metadata sync when
setting up a runtime. If not set, it defaults to true.
type: boolean
Expand Down
1 change: 0 additions & 1 deletion config/crd/bases/data.fluid.io_alluxioruntimes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,6 @@ spec:
metadata when setting up the runtime. If not set,
properties:
autoSync:
default: true
description: AutoSync enables automatic metadata sync when
setting up a runtime. If not set, it defaults to true.
type: boolean
Expand Down
1 change: 0 additions & 1 deletion config/crd/bases/data.fluid.io_thinruntimes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,6 @@ spec:
metadata when setting up the runtime. If not set,
properties:
autoSync:
default: true
description: AutoSync enables automatic metadata sync when
setting up a runtime. If not set, it defaults to true.
type: boolean
Expand Down
61 changes: 56 additions & 5 deletions pkg/ddc/jindocache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@ limitations under the License.
package jindocache

import (
"context"
"fmt"
"reflect"
"testing"

"github.com/fluid-cloudnative/fluid/pkg/common"

"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

. "github.com/agiledragon/gomonkey/v2"
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
Expand Down Expand Up @@ -185,26 +190,67 @@ func TestInvokeCleanCache(t *testing.T) {
ReadyReplicas: 1,
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "hbase-no-pod-jindofs-master",
Namespace: "fluid",
},
Status: appsv1.StatefulSetStatus{
ReadyReplicas: 1,
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "hbase-exec-error-jindofs-master",
Namespace: "fluid",
},
Status: appsv1.StatefulSetStatus{
ReadyReplicas: 1,
},
},
}
objs := []runtime.Object{}
for _, masterInput := range masterInputs {
objs = append(objs, masterInput.DeepCopy())
}
fakeClient := fake.NewFakeClientWithScheme(testScheme, objs...)
testCases := []struct {
name string
namespace string
isErr bool
name string
namespace string
patchExecFn func(ctx context.Context, podName string, containerName string, namespace string, cmd []string) (stdout, stderr string, err error)
isErr bool
}{
{
name: "hadoop",
namespace: "fluid",
isErr: false,
patchExecFn: func(ctx context.Context, podName string, containerName string, namespace string, cmd []string) (stdout, stderr string, err error) {
return "", "", nil
},
isErr: false,
},
{
name: "hbase",
namespace: "fluid",
isErr: true,
patchExecFn: func(ctx context.Context, podName, containerName, namespace string, cmd []string) (stdout string, stderr string, err error) {
return "cache cleaned up", "", nil
},
isErr: false,
},
{
name: "hbase-no-pod",
namespace: "fluid",
patchExecFn: func(ctx context.Context, podName, containerName, namespace string, cmd []string) (stdout string, stderr string, err error) {
return "", "", errors.NewNotFound(schema.GroupResource{Group: "v1", Resource: "pods"}, "pod not found")
},
isErr: false,
},
{
name: "hbase-exec-error",
namespace: "fluid",
patchExecFn: func(ctx context.Context, podName, containerName, namespace string, cmd []string) (stdout string, stderr string, err error) {
return "", "", fmt.Errorf("expected exec error")
},
isErr: true,
},
{
name: "none",
Expand All @@ -219,11 +265,16 @@ func TestInvokeCleanCache(t *testing.T) {
name: testCase.name,
Log: fake.NullLogger(),
}

patch := ApplyFunc(kubeclient.ExecCommandInContainerWithFullOutput, testCase.patchExecFn)

err := engine.invokeCleanCache()
isErr := err != nil
if isErr != testCase.isErr {
t.Errorf("test-name:%s want %t, got %t", testCase.name, testCase.isErr, isErr)
}

patch.Reset()
}
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/ddc/thin/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ func (t *ThinEngine) shouldSyncMetadata() (should bool, err error) {
return should, err
}

if !runtime.Spec.RuntimeManagement.MetadataSyncPolicy.AutoSyncEnabled() {
t.Log.V(1).Info("Skip syncing metadta cause runtime.Spec.RuntimeManagement.MetadataSyncPolicy.AutoSync=false", "runtime name", runtime.Name, "runtime namespace", runtime.Namespace)
// Avoid using `!runtime.Spec.RuntimeManagement.MetadataSyncPolicy.AutoSyncEnabled()` because ThinRuntime disables auto-sync by default. The behavior is different
// from other runtimes.
if runtime.Spec.RuntimeManagement.MetadataSyncPolicy.AutoSync == nil || !*runtime.Spec.RuntimeManagement.MetadataSyncPolicy.AutoSync {
t.Log.V(1).Info("Skip syncing metadata because runtime.Spec.RuntimeManagement.MetaadataSyncPolicy.AutoSync==false(default to false if not set)", "runtime name", runtime.Name, "runtime namespace", runtime.Namespace)
should = false
return should, nil
}
Expand Down
31 changes: 30 additions & 1 deletion pkg/ddc/thin/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ func TestShouldSyncMetadata(t *testing.T) {
Namespace: "fluid",
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "autosync",
Namespace: "fluid",
},
},
}
runtimeInputs := []datav1alpha1.ThinRuntime{
{
Expand Down Expand Up @@ -83,6 +89,19 @@ func TestShouldSyncMetadata(t *testing.T) {
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "autosync",
Namespace: "fluid",
},
Spec: datav1alpha1.ThinRuntimeSpec{
RuntimeManagement: datav1alpha1.RuntimeManagement{
MetadataSyncPolicy: datav1alpha1.MetadataSyncPolicy{
AutoSync: ptr.To(true),
},
},
},
},
}
testObjs := []runtime.Object{}
for _, input := range datasetInputs {
Expand Down Expand Up @@ -112,6 +131,12 @@ func TestShouldSyncMetadata(t *testing.T) {
Client: client,
Log: fake.NullLogger(),
},
{
name: "autosync",
namespace: "fluid",
Client: client,
Log: fake.NullLogger(),
},
}

var testCases = []struct {
Expand All @@ -124,12 +149,16 @@ func TestShouldSyncMetadata(t *testing.T) {
},
{
engine: engines[1],
expectedShould: true,
expectedShould: false,
},
{
engine: engines[2],
expectedShould: false,
},
{
engine: engines[3],
expectedShould: true,
},
}

for _, test := range testCases {
Expand Down
Loading