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

refactor: remove deprecated data operation interface #4130

Merged
merged 3 commits into from
May 29, 2024
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
29 changes: 0 additions & 29 deletions pkg/ddc/alluxio/data_migrate.go

This file was deleted.

35 changes: 0 additions & 35 deletions pkg/ddc/alluxio/load_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,43 +34,8 @@ import (
cruntime "github.com/fluid-cloudnative/fluid/pkg/runtime"
"github.com/fluid-cloudnative/fluid/pkg/utils"
"github.com/fluid-cloudnative/fluid/pkg/utils/docker"
"github.com/fluid-cloudnative/fluid/pkg/utils/helm"
)

// CreateDataLoadJob creates the job to load data
func (e *AlluxioEngine) CreateDataLoadJob(ctx cruntime.ReconcileRequestContext, targetDataload datav1alpha1.DataLoad) (err error) {
log := ctx.Log.WithName("createDataLoadJob")

// 1. Check if the helm release already exists
releaseName := utils.GetDataLoadReleaseName(targetDataload.Name)
jobName := utils.GetDataLoadJobName(releaseName)
var existed bool
existed, err = helm.CheckRelease(releaseName, targetDataload.Namespace)
if err != nil {
log.Error(err, "failed to check if release exists", "releaseName", releaseName, "namespace", targetDataload.Namespace)
return err
}

// 2. install the helm chart if not exists
if !existed {
log.Info("DataLoad job helm chart not installed yet, will install")
valueFileName, err := e.generateDataLoadValueFile(ctx, &targetDataload)
if err != nil {
log.Error(err, "failed to generate dataload chart's value file")
return err
}
chartName := utils.GetChartsDirectory() + "/" + cdataload.DataloadChart + "/" + common.AlluxioRuntime
err = helm.InstallRelease(releaseName, targetDataload.Namespace, valueFileName, chartName)
if err != nil {
log.Error(err, "failed to install dataload chart")
return err
}
log.Info("DataLoad job helm chart successfully installed", "namespace", targetDataload.Namespace, "releaseName", releaseName)
ctx.Recorder.Eventf(&targetDataload, v1.EventTypeNormal, common.DataLoadJobStarted, "The DataLoad job %s started", jobName)
}
return err
}

// generateDataLoadValueFile builds a DataLoadValue by extracted specifications from the given DataLoad, and
// marshals the DataLoadValue to a temporary yaml file where stores values that'll be used by fluid dataloader helm chart
func (e *AlluxioEngine) generateDataLoadValueFile(r cruntime.ReconcileRequestContext, object client.Object) (valueFileName string, err error) {
Expand Down
106 changes: 3 additions & 103 deletions pkg/ddc/alluxio/load_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,116 +26,16 @@ import (
"testing"

"github.com/brahma-adshonor/gohook"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
cdataload "github.com/fluid-cloudnative/fluid/pkg/dataload"
cruntime "github.com/fluid-cloudnative/fluid/pkg/runtime"
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
"github.com/fluid-cloudnative/fluid/pkg/utils/helm"
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

func TestCreateDataLoadJob(t *testing.T) {
mockExecCheckReleaseCommon := func(name string, namespace string) (exist bool, err error) {
return false, nil
}
mockExecCheckReleaseErr := func(name string, namespace string) (exist bool, err error) {
return false, errors.New("fail to check release")
}
mockExecInstallReleaseCommon := func(name string, namespace string, valueFile string, chartName string) error {
return nil
}
mockExecInstallReleaseErr := func(name string, namespace string, valueFile string, chartName string) error {
return errors.New("fail to install dataload chart")
}

wrappedUnhookCheckRelease := func() {
err := gohook.UnHook(helm.CheckRelease)
if err != nil {
t.Fatal(err.Error())
}
}
wrappedUnhookInstallRelease := func() {
err := gohook.UnHook(helm.InstallRelease)
if err != nil {
t.Fatal(err.Error())
}
}

targetDataLoad := datav1alpha1.DataLoad{
ObjectMeta: metav1.ObjectMeta{
Name: "hbase",
Namespace: "fluid",
},
Spec: datav1alpha1.DataLoadSpec{
Dataset: datav1alpha1.TargetDataset{
Name: "test-dataset",
Namespace: "fluid",
},
},
}
datasetInputs := []datav1alpha1.Dataset{
{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dataset",
Namespace: "fluid",
},
},
}
testObjs := []runtime.Object{}
for _, datasetInput := range datasetInputs {
testObjs = append(testObjs, datasetInput.DeepCopy())
}
client := fake.NewFakeClientWithScheme(testScheme, testObjs...)

engine := AlluxioEngine{
name: "hbase",
}
ctx := cruntime.ReconcileRequestContext{
Log: fake.NullLogger(),
Client: client,
Recorder: record.NewFakeRecorder(1),
}

err := gohook.Hook(helm.CheckRelease, mockExecCheckReleaseErr, nil)
if err != nil {
t.Fatal(err.Error())
}
err = engine.CreateDataLoadJob(ctx, targetDataLoad)
if err == nil {
t.Errorf("fail to catch the error")
}
wrappedUnhookCheckRelease()

err = gohook.Hook(helm.CheckRelease, mockExecCheckReleaseCommon, nil)
if err != nil {
t.Fatal(err.Error())
}
err = gohook.Hook(helm.InstallRelease, mockExecInstallReleaseErr, nil)
if err != nil {
t.Fatal(err.Error())
}
err = engine.CreateDataLoadJob(ctx, targetDataLoad)
if err == nil {
t.Errorf("fail to catch the error")
}
wrappedUnhookInstallRelease()

err = gohook.Hook(helm.InstallRelease, mockExecInstallReleaseCommon, nil)
if err != nil {
t.Fatal(err.Error())
}
err = engine.CreateDataLoadJob(ctx, targetDataLoad)
if err != nil {
t.Errorf("fail to exec the function")
}
wrappedUnhookCheckRelease()
}

func TestGenerateDataLoadValueFile(t *testing.T) {
datasetInputs := []datav1alpha1.Dataset{
{
Expand Down
42 changes: 4 additions & 38 deletions pkg/ddc/base/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ type Engine interface {
// Sync syncs the alluxio runtime
Sync(ctx cruntime.ReconcileRequestContext) error

// Dataloader
// @Deprecated use DataOperator instead.
Dataloader

// Datamigrater
// @Deprecated use DataOperator instead.
Datamigrater

// DataOperator is a common interface for Data Operations like DataBackup/DataLoad/DataMigrate etc.
DataOperator
}
Expand All @@ -63,36 +55,18 @@ type DataOperator interface {
Operate(ctx cruntime.ReconcileRequestContext, opStatus *datav1alpha1.OperationStatus, operation dataoperation.OperationInterface) (ctrl.Result, error)
}

// DataOperatorYamlGenerator is the implementation of DataOperator interface for runtime engine
// DataOperatorYamlGenerator is the implementation of DataOperator interface for runtime engine using TemplateEngine.
type DataOperatorYamlGenerator interface {
GetDataOperationValueFile(ctx cruntime.ReconcileRequestContext, operation dataoperation.OperationInterface) (valueFileName string, err error)
}

type Dataloader interface {
// LoadData generate dataload values and install helm chart
LoadData(ctx cruntime.ReconcileRequestContext, targetDataload datav1alpha1.DataLoad) (err error)

// CheckRuntimeReady Check if runtime is ready
// @Deprecated because it's common for all engine
CheckRuntimeReady() (ready bool)
}

type Databackuper interface {
BackupData(ctx cruntime.ReconcileRequestContext, targetDataBackup datav1alpha1.DataBackup) (ctrl.Result, error)
}

type Datamigrater interface {
// MigrateData generate datamigrate values and install helm chart
MigrateData(ctx cruntime.ReconcileRequestContext, targetDataMigrate datav1alpha1.DataMigrate) (err error)
}

// Implement is what the real engine should implement if it use the TemplateEngine
type Implement interface {
UnderFileSystemService

DataOperatorYamlGenerator

// ShouldSetupMaster checks if the master ready
// CheckMasterReady checks if the master ready
CheckMasterReady() (ready bool, err error)

// CheckWorkersReady checks if the workers ready
Expand Down Expand Up @@ -155,21 +129,13 @@ type Implement interface {
// BindToDataset binds the engine to dataset
BindToDataset() (err error)

// CreateDataLoadJob creates the job to load data
// @Deprecated TODO: remove when DataOperator ready
CreateDataLoadJob(ctx cruntime.ReconcileRequestContext, targetDataload datav1alpha1.DataLoad) error

// CreateDataMigrateJob creates the job to load data
// @Deprecated TODO: remove when DataOperator ready
CreateDataMigrateJob(ctx cruntime.ReconcileRequestContext, targetDataMigrate datav1alpha1.DataMigrate) error

// checks if the runtime is ready
// CheckRuntimeReady checks if the runtime is ready
CheckRuntimeReady() (ready bool)

// SyncRuntime syncs the runtime spec
SyncRuntime(ctx cruntime.ReconcileRequestContext) (changed bool, err error)

// Sync the scheduleInfo to cacheNodes
// SyncScheduleInfoToCacheNodes Sync the scheduleInfo to cacheNodes
SyncScheduleInfoToCacheNodes() (err error)
}

Expand Down
33 changes: 0 additions & 33 deletions pkg/ddc/base/load_data.go

This file was deleted.

30 changes: 0 additions & 30 deletions pkg/ddc/base/migrate_data.go

This file was deleted.

Loading
Loading