diff --git a/api/v1alpha1/databackup_types.go b/api/v1alpha1/databackup_types.go
index 01c6c4d5804..71e4df407dd 100644
--- a/api/v1alpha1/databackup_types.go
+++ b/api/v1alpha1/databackup_types.go
@@ -31,7 +31,10 @@ type DataBackupSpec struct {
BackupPath string `json:"backupPath,omitempty"`
// Manage the user to run Alluxio DataBackup
RunAs *User `json:"runAs,omitempty"`
- // Specifies that the preceding operation in a workflow
+ // Specifies that the preceding operation in a workflow.
+ // The operation waits for the preceding operation only if runAfter is set when the operation is created.
+ // Removing runAfter while the operation is waiting ends the wait.
+ // Adding runAfter later does not make the operation wait.
// +optional
RunAfter *OperationRef `json:"runAfter,omitempty"`
// TTLSecondsAfterFinished is the time second to clean up data operations after finished or failed
diff --git a/api/v1alpha1/dataload_types.go b/api/v1alpha1/dataload_types.go
index afae1cc5335..bb527f4d097 100644
--- a/api/v1alpha1/dataload_types.go
+++ b/api/v1alpha1/dataload_types.go
@@ -87,7 +87,10 @@ type DataLoadSpec struct {
// +optional
Schedule string `json:"schedule,omitempty"`
- // Specifies that the preceding operation in a workflow
+ // Specifies that the preceding operation in a workflow.
+ // The operation waits for the preceding operation only if runAfter is set when the operation is created.
+ // Removing runAfter while the operation is waiting ends the wait.
+ // Adding runAfter later does not make the operation wait.
// +optional
RunAfter *OperationRef `json:"runAfter,omitempty"`
diff --git a/api/v1alpha1/datamigrate_types.go b/api/v1alpha1/datamigrate_types.go
index 51a3dda48ef..92ed1a87292 100644
--- a/api/v1alpha1/datamigrate_types.go
+++ b/api/v1alpha1/datamigrate_types.go
@@ -77,7 +77,10 @@ type DataMigrateSpec struct {
// SchedulerName sets the scheduler to be used for DataMigrate pod
SchedulerName string `json:"schedulerName,omitempty"`
- // Specifies that the preceding operation in a workflow
+ // Specifies that the preceding operation in a workflow.
+ // The operation waits for the preceding operation only if runAfter is set when the operation is created.
+ // Removing runAfter while the operation is waiting ends the wait.
+ // Adding runAfter later does not make the operation wait.
// +optional
RunAfter *OperationRef `json:"runAfter,omitempty"`
diff --git a/api/v1alpha1/dataprocess_types.go b/api/v1alpha1/dataprocess_types.go
index b4a146bd9f6..6250948ddd8 100644
--- a/api/v1alpha1/dataprocess_types.go
+++ b/api/v1alpha1/dataprocess_types.go
@@ -104,7 +104,10 @@ type DataProcessSpec struct {
// +required
Processor Processor `json:"processor"`
- // Specifies that the preceding operation in a workflow
+ // Specifies that the preceding operation in a workflow.
+ // The operation waits for the preceding operation only if runAfter is set when the operation is created.
+ // Removing runAfter while the operation is waiting ends the wait.
+ // Adding runAfter later does not make the operation wait.
// +optional
RunAfter *OperationRef `json:"runAfter,omitempty"`
diff --git a/api/v1alpha1/openapi_generated.go b/api/v1alpha1/openapi_generated.go
index ee620782445..83fd3197215 100644
--- a/api/v1alpha1/openapi_generated.go
+++ b/api/v1alpha1/openapi_generated.go
@@ -2207,7 +2207,7 @@ func schema_fluid_cloudnative_fluid_api_v1alpha1_DataBackupSpec(ref common.Refer
},
"runAfter": {
SchemaProps: spec.SchemaProps{
- Description: "Specifies that the preceding operation in a workflow",
+ Description: "Specifies that the preceding operation in a workflow. The operation waits for the preceding operation only if runAfter is set when the operation is created. Removing runAfter while the operation is waiting ends the wait. Adding runAfter later does not make the operation wait.",
Ref: ref("github.com/fluid-cloudnative/fluid/api/v1alpha1.OperationRef"),
},
},
@@ -2439,7 +2439,7 @@ func schema_fluid_cloudnative_fluid_api_v1alpha1_DataLoadSpec(ref common.Referen
},
"runAfter": {
SchemaProps: spec.SchemaProps{
- Description: "Specifies that the preceding operation in a workflow",
+ Description: "Specifies that the preceding operation in a workflow. The operation waits for the preceding operation only if runAfter is set when the operation is created. Removing runAfter while the operation is waiting ends the wait. Adding runAfter later does not make the operation wait.",
Ref: ref("github.com/fluid-cloudnative/fluid/api/v1alpha1.OperationRef"),
},
},
@@ -2699,7 +2699,7 @@ func schema_fluid_cloudnative_fluid_api_v1alpha1_DataMigrateSpec(ref common.Refe
},
"runAfter": {
SchemaProps: spec.SchemaProps{
- Description: "Specifies that the preceding operation in a workflow",
+ Description: "Specifies that the preceding operation in a workflow. The operation waits for the preceding operation only if runAfter is set when the operation is created. Removing runAfter while the operation is waiting ends the wait. Adding runAfter later does not make the operation wait.",
Ref: ref("github.com/fluid-cloudnative/fluid/api/v1alpha1.OperationRef"),
},
},
@@ -2926,7 +2926,7 @@ func schema_fluid_cloudnative_fluid_api_v1alpha1_DataProcessSpec(ref common.Refe
},
"runAfter": {
SchemaProps: spec.SchemaProps{
- Description: "Specifies that the preceding operation in a workflow",
+ Description: "Specifies that the preceding operation in a workflow. The operation waits for the preceding operation only if runAfter is set when the operation is created. Removing runAfter while the operation is waiting ends the wait. Adding runAfter later does not make the operation wait.",
Ref: ref("github.com/fluid-cloudnative/fluid/api/v1alpha1.OperationRef"),
},
},
diff --git a/docs/en/dev/api_doc.md b/docs/en/dev/api_doc.md
index a6e2d70b153..4e5310bda56 100644
--- a/docs/en/dev/api_doc.md
+++ b/docs/en/dev/api_doc.md
@@ -518,7 +518,7 @@ _Appears in:_
| `dataset` _string_ | Dataset defines the target dataset of the DataBackup | | |
| `backupPath` _string_ | BackupPath defines the target path to save data of the DataBackup | | |
| `runAs` _[User](#user)_ | Manage the user to run Alluxio DataBackup | | |
-| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow | | Optional: \{\}
|
+| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow.
The operation waits for the preceding operation only if runAfter is set when the operation is created.
Removing runAfter while the operation is waiting ends the wait.
Adding runAfter later does not make the operation wait. | | Optional: \{\}
|
| `ttlSecondsAfterFinished` _integer_ | TTLSecondsAfterFinished is the time second to clean up data operations after finished or failed | | Optional: \{\}
|
@@ -564,7 +564,7 @@ _Appears in:_
| `schedulerName` _string_ | SchedulerName sets the scheduler to be used for DataLoad pod | | Optional: \{\}
|
| `policy` _[Policy](#policy)_ | including Once, Cron, OnEvent | Once | Enum: [Once Cron OnEvent]
Optional: \{\}
|
| `schedule` _string_ | The schedule in Cron format, only set when policy is cron, see https://en.wikipedia.org/wiki/Cron. | | Optional: \{\}
|
-| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow | | Optional: \{\}
|
+| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow.
The operation waits for the preceding operation only if runAfter is set when the operation is created.
Removing runAfter while the operation is waiting ends the wait.
Adding runAfter later does not make the operation wait. | | Optional: \{\}
|
| `ttlSecondsAfterFinished` _integer_ | TTLSecondsAfterFinished is the time second to clean up data operations after finished or failed | | Optional: \{\}
|
| `resources` _[ResourceRequirements](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#resourcerequirements-v1-core)_ | Resources that will be requested by the DataLoad job.
| | Optional: \{\}
|
@@ -615,7 +615,7 @@ _Appears in:_
| `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#toleration-v1-core) array_ | Tolerations defines tolerations for DataMigrate pod | | Optional: \{\}
|
| `nodeSelector` _object (keys:string, values:string)_ | NodeSelector defiens node selector for DataMigrate pod | | Optional: \{\}
|
| `schedulerName` _string_ | SchedulerName sets the scheduler to be used for DataMigrate pod | | Optional: \{\}
|
-| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow | | Optional: \{\}
|
+| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow.
The operation waits for the preceding operation only if runAfter is set when the operation is created.
Removing runAfter while the operation is waiting ends the wait.
Adding runAfter later does not make the operation wait. | | Optional: \{\}
|
| `ttlSecondsAfterFinished` _integer_ | TTLSecondsAfterFinished is the time second to clean up data operations after finished or failed | | Optional: \{\}
|
| `resources` _[ResourceRequirements](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#resourcerequirements-v1-core)_ | Resources that will be requested by the DataMigrate job.
| | Optional: \{\}
|
| `parallelism` _integer_ | Parallelism defines the parallelism tasks numbers for DataMigrate. If the value is greater than 1, the job acts
as a launcher, and users should define the WorkerSpec. | 1 | Minimum: 1
Optional: \{\}
|
@@ -674,7 +674,7 @@ _Appears in:_
| --- | --- | --- | --- |
| `dataset` _[TargetDatasetWithMountPath](#targetdatasetwithmountpath)_ | Dataset specifies the target dataset and its mount path. | | Required: \{\}
|
| `processor` _[Processor](#processor)_ | Processor specify how to process data. | | Required: \{\}
|
-| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow | | Optional: \{\}
|
+| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow.
The operation waits for the preceding operation only if runAfter is set when the operation is created.
Removing runAfter while the operation is waiting ends the wait.
Adding runAfter later does not make the operation wait. | | Optional: \{\}
|
| `ttlSecondsAfterFinished` _integer_ | TTLSecondsAfterFinished is the time second to clean up data operations after finished or failed | | Optional: \{\}
|
diff --git a/docs/zh/dev/api_doc.md b/docs/zh/dev/api_doc.md
index a6e2d70b153..4e5310bda56 100644
--- a/docs/zh/dev/api_doc.md
+++ b/docs/zh/dev/api_doc.md
@@ -518,7 +518,7 @@ _Appears in:_
| `dataset` _string_ | Dataset defines the target dataset of the DataBackup | | |
| `backupPath` _string_ | BackupPath defines the target path to save data of the DataBackup | | |
| `runAs` _[User](#user)_ | Manage the user to run Alluxio DataBackup | | |
-| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow | | Optional: \{\}
|
+| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow.
The operation waits for the preceding operation only if runAfter is set when the operation is created.
Removing runAfter while the operation is waiting ends the wait.
Adding runAfter later does not make the operation wait. | | Optional: \{\}
|
| `ttlSecondsAfterFinished` _integer_ | TTLSecondsAfterFinished is the time second to clean up data operations after finished or failed | | Optional: \{\}
|
@@ -564,7 +564,7 @@ _Appears in:_
| `schedulerName` _string_ | SchedulerName sets the scheduler to be used for DataLoad pod | | Optional: \{\}
|
| `policy` _[Policy](#policy)_ | including Once, Cron, OnEvent | Once | Enum: [Once Cron OnEvent]
Optional: \{\}
|
| `schedule` _string_ | The schedule in Cron format, only set when policy is cron, see https://en.wikipedia.org/wiki/Cron. | | Optional: \{\}
|
-| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow | | Optional: \{\}
|
+| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow.
The operation waits for the preceding operation only if runAfter is set when the operation is created.
Removing runAfter while the operation is waiting ends the wait.
Adding runAfter later does not make the operation wait. | | Optional: \{\}
|
| `ttlSecondsAfterFinished` _integer_ | TTLSecondsAfterFinished is the time second to clean up data operations after finished or failed | | Optional: \{\}
|
| `resources` _[ResourceRequirements](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#resourcerequirements-v1-core)_ | Resources that will be requested by the DataLoad job.
| | Optional: \{\}
|
@@ -615,7 +615,7 @@ _Appears in:_
| `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#toleration-v1-core) array_ | Tolerations defines tolerations for DataMigrate pod | | Optional: \{\}
|
| `nodeSelector` _object (keys:string, values:string)_ | NodeSelector defiens node selector for DataMigrate pod | | Optional: \{\}
|
| `schedulerName` _string_ | SchedulerName sets the scheduler to be used for DataMigrate pod | | Optional: \{\}
|
-| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow | | Optional: \{\}
|
+| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow.
The operation waits for the preceding operation only if runAfter is set when the operation is created.
Removing runAfter while the operation is waiting ends the wait.
Adding runAfter later does not make the operation wait. | | Optional: \{\}
|
| `ttlSecondsAfterFinished` _integer_ | TTLSecondsAfterFinished is the time second to clean up data operations after finished or failed | | Optional: \{\}
|
| `resources` _[ResourceRequirements](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#resourcerequirements-v1-core)_ | Resources that will be requested by the DataMigrate job.
| | Optional: \{\}
|
| `parallelism` _integer_ | Parallelism defines the parallelism tasks numbers for DataMigrate. If the value is greater than 1, the job acts
as a launcher, and users should define the WorkerSpec. | 1 | Minimum: 1
Optional: \{\}
|
@@ -674,7 +674,7 @@ _Appears in:_
| --- | --- | --- | --- |
| `dataset` _[TargetDatasetWithMountPath](#targetdatasetwithmountpath)_ | Dataset specifies the target dataset and its mount path. | | Required: \{\}
|
| `processor` _[Processor](#processor)_ | Processor specify how to process data. | | Required: \{\}
|
-| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow | | Optional: \{\}
|
+| `runAfter` _[OperationRef](#operationref)_ | Specifies that the preceding operation in a workflow.
The operation waits for the preceding operation only if runAfter is set when the operation is created.
Removing runAfter while the operation is waiting ends the wait.
Adding runAfter later does not make the operation wait. | | Optional: \{\}
|
| `ttlSecondsAfterFinished` _integer_ | TTLSecondsAfterFinished is the time second to clean up data operations after finished or failed | | Optional: \{\}
|
diff --git a/pkg/common/constants.go b/pkg/common/constants.go
index 066a78857a6..f30b69be541 100644
--- a/pkg/common/constants.go
+++ b/pkg/common/constants.go
@@ -78,6 +78,8 @@ const (
DataOperationNotFound = "DataOperationNotFound"
DataOperationWaiting = "DataOperationWaiting"
+
+ DataOperationWaitingEnded = "DataOperationWaitingEnded"
)
// Events related to DataLoad
diff --git a/pkg/controllers/v1alpha1/dataflow/dataflow_controller_test.go b/pkg/controllers/v1alpha1/dataflow/dataflow_controller_test.go
index 19fcffbacbc..04b8b70dcc8 100644
--- a/pkg/controllers/v1alpha1/dataflow/dataflow_controller_test.go
+++ b/pkg/controllers/v1alpha1/dataflow/dataflow_controller_test.go
@@ -156,6 +156,104 @@ var _ = Describe("DataFlowReconciler", func() {
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(ctrl.Result{}))
})
+
+ It("should not panic and should release a DataLoad whose RunAfter was removed while it was waiting", func() {
+ s := runtime.NewScheme()
+ _ = datav1alpha1.AddToScheme(s)
+
+ waitingLoad := &datav1alpha1.DataLoad{
+ ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "default"},
+ Status: datav1alpha1.OperationStatus{
+ Phase: common.PhasePending,
+ WaitingFor: datav1alpha1.WaitingStatus{
+ OperationComplete: ptr.To(true),
+ },
+ },
+ }
+
+ r := newTestDataFlowReconciler(s, waitingLoad)
+ req := ctrl.Request{
+ NamespacedName: types.NamespacedName{Name: "test", Namespace: "default"},
+ }
+
+ var (
+ result ctrl.Result
+ err error
+ )
+ Expect(func() { result, err = r.Reconcile(context.TODO(), req) }).NotTo(Panic())
+ Expect(err).NotTo(HaveOccurred())
+ Expect(result).To(Equal(ctrl.Result{}))
+
+ updated := &datav1alpha1.DataLoad{}
+ Expect(r.Get(context.TODO(), req.NamespacedName, updated)).To(Succeed())
+ Expect(updated.Status.WaitingFor.OperationComplete).To(HaveValue(BeFalse()))
+ })
+
+ // Reconcile runs every data operation kind for the request name, so a waiting DataLoad
+ // also makes it fetch a same-name DataBackup that has no runAfter and is not waiting.
+ It("should leave a same-name operation of another kind that is not waiting untouched", func() {
+ s := runtime.NewScheme()
+ _ = datav1alpha1.AddToScheme(s)
+
+ precedingLoad := &datav1alpha1.DataLoad{
+ ObjectMeta: metav1.ObjectMeta{Name: "preceding", Namespace: "default"},
+ Status: datav1alpha1.OperationStatus{
+ Phase: common.PhaseComplete,
+ },
+ }
+ waitingLoad := &datav1alpha1.DataLoad{
+ ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "default"},
+ Spec: datav1alpha1.DataLoadSpec{
+ RunAfter: &datav1alpha1.OperationRef{
+ ObjectRef: datav1alpha1.ObjectRef{
+ Kind: "DataLoad",
+ Name: "preceding",
+ },
+ },
+ },
+ Status: datav1alpha1.OperationStatus{
+ Phase: common.PhasePending,
+ WaitingFor: datav1alpha1.WaitingStatus{
+ OperationComplete: ptr.To(true),
+ },
+ },
+ }
+ completedBackup := &datav1alpha1.DataBackup{
+ ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "default"},
+ Status: datav1alpha1.OperationStatus{
+ Phase: common.PhaseComplete,
+ },
+ }
+
+ r := newTestDataFlowReconciler(s, precedingLoad, waitingLoad, completedBackup)
+ req := ctrl.Request{
+ NamespacedName: types.NamespacedName{Name: "test", Namespace: "default"},
+ }
+ backupBefore := &datav1alpha1.DataBackup{}
+ Expect(r.Get(context.TODO(), req.NamespacedName, backupBefore)).To(Succeed())
+
+ var (
+ result ctrl.Result
+ err error
+ )
+ Expect(func() { result, err = r.Reconcile(context.TODO(), req) }).NotTo(Panic())
+ Expect(err).NotTo(HaveOccurred())
+ Expect(result).To(Equal(ctrl.Result{}))
+
+ releasedLoad := &datav1alpha1.DataLoad{}
+ Expect(r.Get(context.TODO(), req.NamespacedName, releasedLoad)).To(Succeed())
+ Expect(releasedLoad.Status.WaitingFor.OperationComplete).To(HaveValue(BeFalse()))
+
+ backupAfter := &datav1alpha1.DataBackup{}
+ Expect(r.Get(context.TODO(), req.NamespacedName, backupAfter)).To(Succeed())
+ Expect(backupAfter.ResourceVersion).To(Equal(backupBefore.ResourceVersion))
+ Expect(backupAfter.Status).To(Equal(backupBefore.Status))
+
+ // Only the DataLoad stopped waiting.
+ events := r.Recorder.(*record.FakeRecorder).Events
+ Expect(events).To(Receive(ContainSubstring(common.DataOperationWaitingEnded)))
+ Expect(events).To(BeEmpty())
+ })
})
})
diff --git a/pkg/controllers/v1alpha1/dataflow/operations.go b/pkg/controllers/v1alpha1/dataflow/operations.go
index 47eadbc578e..00d57ea9ea9 100644
--- a/pkg/controllers/v1alpha1/dataflow/operations.go
+++ b/pkg/controllers/v1alpha1/dataflow/operations.go
@@ -18,6 +18,7 @@ package dataflow
import (
"context"
+ "fmt"
"reflect"
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
@@ -160,6 +161,19 @@ func reconcileOperationDataFlow(ctx reconcileRequestContext,
opStatus datav1alpha1.OperationStatus,
updateStatusFn func() error) (needRequeue bool, err error) {
+ // spec.runAfter can be removed while the operation is still waiting for it. There is
+ // nothing left to wait for, so release the operation instead of dereferencing nil.
+ // Reconcile also fetches the same-name operations of the other kinds, which may have no
+ // runAfter and not be waiting at all; leave those untouched.
+ if runAfter == nil {
+ if !isWaitingForPrecedingOperation(opStatus) {
+ return false, nil
+ }
+ ctx.Log.Info("spec.runAfter is no longer set, stop waiting for the preceding operation")
+ return releaseWaitingOperation(ctx, object, opStatus, updateStatusFn,
+ "spec.runAfter was removed, stop waiting for the preceding operation")
+ }
+
opRefNamespace := ctx.Namespace
if len(runAfter.Namespace) != 0 {
opRefNamespace = runAfter.Namespace
@@ -186,12 +200,27 @@ func reconcileOperationDataFlow(ctx reconcileRequestContext,
return true, nil
}
- // set opStatus.waitingFor.operationComplete back to false
- err = retry.RetryOnConflict(retry.DefaultBackoff, updateStatusFn)
+ return releaseWaitingOperation(ctx, object, opStatus, updateStatusFn,
+ fmt.Sprintf("Preceding operation %s \"%s/%s\" completed, stop waiting", runAfter.Kind, opRefNamespace, runAfter.Name))
+}
+
+func isWaitingForPrecedingOperation(opStatus datav1alpha1.OperationStatus) bool {
+ return opStatus.WaitingFor.OperationComplete != nil && *opStatus.WaitingFor.OperationComplete
+}
- if err != nil {
+// releaseWaitingOperation sets opStatus.waitingFor.operationComplete back to false so that
+// the operation's own controller moves on from Pending, and records why it stopped waiting.
+func releaseWaitingOperation(ctx reconcileRequestContext, object client.Object, opStatus datav1alpha1.OperationStatus,
+ updateStatusFn func() error, message string) (needRequeue bool, err error) {
+ if err = retry.RetryOnConflict(retry.DefaultBackoff, updateStatusFn); err != nil {
return true, errors.Wrapf(err, "failed to update operation status waitingFor.OperationComplete=false")
}
+ // A same-name operation of another kind can reach this point without having been waiting,
+ // so only record the event for an operation that actually stopped waiting.
+ if isWaitingForPrecedingOperation(opStatus) {
+ ctx.Recorder.Event(object, corev1.EventTypeNormal, common.DataOperationWaitingEnded, message)
+ }
+
return false, nil
}
diff --git a/pkg/controllers/v1alpha1/dataflow/operations_test.go b/pkg/controllers/v1alpha1/dataflow/operations_test.go
index e55d70c11db..8b47baa209e 100644
--- a/pkg/controllers/v1alpha1/dataflow/operations_test.go
+++ b/pkg/controllers/v1alpha1/dataflow/operations_test.go
@@ -18,18 +18,21 @@ package dataflow
import (
"context"
+ "errors"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
"github.com/fluid-cloudnative/fluid/pkg/common"
+ "github.com/fluid-cloudnative/fluid/pkg/utils"
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/utils/ptr"
+ "sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)
@@ -861,3 +864,174 @@ var _ = Describe("reconcileDataMigrate and reconcileDataProcess not-found events
})
})
})
+
+// A user may remove spec.runAfter while the operation is still waiting for the preceding one,
+// which leaves status.waitingFor.operationComplete=true without a reference to wait on.
+var _ = Describe("reconcile a data operation whose spec.runAfter was removed while waiting", func() {
+
+ const namespace = "default"
+
+ var s *runtime.Scheme
+
+ BeforeEach(func() {
+ s = runtime.NewScheme()
+ _ = datav1alpha1.AddToScheme(s)
+ })
+
+ staleWaitingStatus := func() datav1alpha1.OperationStatus {
+ return datav1alpha1.OperationStatus{
+ Phase: common.PhasePending,
+ WaitingFor: datav1alpha1.WaitingStatus{
+ OperationComplete: ptr.To(true),
+ },
+ }
+ }
+
+ DescribeTable("should release the operation without panicking",
+ func(newObj func() client.Object, reconcileFn func(reconcileRequestContext) (bool, error)) {
+ obj := newObj()
+ ctx := makeTestCtx(s, obj.GetName(), namespace, obj)
+
+ var (
+ needRequeue bool
+ err error
+ )
+ Expect(func() { needRequeue, err = reconcileFn(ctx) }).NotTo(Panic())
+ Expect(err).NotTo(HaveOccurred())
+ Expect(needRequeue).To(BeFalse())
+
+ updated := newObj()
+ Expect(ctx.Client.Get(context.TODO(), client.ObjectKeyFromObject(obj), updated)).To(Succeed())
+ opStatus, err := utils.GetOperationStatus(updated)
+ Expect(err).NotTo(HaveOccurred())
+ Expect(opStatus.WaitingFor.OperationComplete).To(HaveValue(BeFalse()))
+ Expect(opStatus.Phase).To(Equal(common.PhasePending))
+ Expect(ctx.Recorder.(*record.FakeRecorder).Events).To(Receive(And(
+ ContainSubstring(common.DataOperationWaitingEnded),
+ ContainSubstring("spec.runAfter was removed"))))
+ },
+ Entry("DataLoad", func() client.Object {
+ return &datav1alpha1.DataLoad{ObjectMeta: metav1.ObjectMeta{Name: loadName, Namespace: namespace}, Status: staleWaitingStatus()}
+ }, reconcileDataLoad),
+ Entry("DataBackup", func() client.Object {
+ return &datav1alpha1.DataBackup{ObjectMeta: metav1.ObjectMeta{Name: backupName, Namespace: namespace}, Status: staleWaitingStatus()}
+ }, reconcileDataBackup),
+ Entry("DataMigrate", func() client.Object {
+ return &datav1alpha1.DataMigrate{ObjectMeta: metav1.ObjectMeta{Name: migrateName, Namespace: namespace}, Status: staleWaitingStatus()}
+ }, reconcileDataMigrate),
+ Entry("DataProcess", func() client.Object {
+ return &datav1alpha1.DataProcess{ObjectMeta: metav1.ObjectMeta{Name: processName, Namespace: namespace}, Status: staleWaitingStatus()}
+ }, reconcileDataProcess),
+ )
+
+ It("should request requeue and return the error when releasing the operation fails", func() {
+ waitingLoad := &datav1alpha1.DataLoad{ObjectMeta: metav1.ObjectMeta{Name: loadName, Namespace: namespace}, Status: staleWaitingStatus()}
+ ctx := makeTestCtx(s, loadName, namespace, waitingLoad)
+ updateErr := errors.New("status update failed")
+
+ var (
+ needRequeue bool
+ err error
+ )
+ Expect(func() {
+ needRequeue, err = reconcileOperationDataFlow(ctx, waitingLoad, nil, waitingLoad.Status, func() error { return updateErr })
+ }).NotTo(Panic())
+ Expect(err).To(MatchError(ContainSubstring(updateErr.Error())))
+ Expect(needRequeue).To(BeTrue())
+ Expect(ctx.Recorder.(*record.FakeRecorder).Events).To(BeEmpty())
+ })
+
+ // Reconcile fetches every data operation kind for the request name, so it also reaches
+ // same-name operations of other kinds that are not waiting for anything.
+ DescribeTable("should leave an operation that is not waiting untouched",
+ func(newObj func() client.Object, reconcileFn func(reconcileRequestContext) (bool, error)) {
+ obj := newObj()
+ ctx := makeTestCtx(s, obj.GetName(), namespace, obj)
+
+ before := newObj()
+ Expect(ctx.Client.Get(context.TODO(), client.ObjectKeyFromObject(obj), before)).To(Succeed())
+
+ needRequeue, err := reconcileFn(ctx)
+ Expect(err).NotTo(HaveOccurred())
+ Expect(needRequeue).To(BeFalse())
+
+ after := newObj()
+ Expect(ctx.Client.Get(context.TODO(), client.ObjectKeyFromObject(obj), after)).To(Succeed())
+ Expect(after.GetResourceVersion()).To(Equal(before.GetResourceVersion()))
+ beforeStatus, err := utils.GetOperationStatus(before)
+ Expect(err).NotTo(HaveOccurred())
+ afterStatus, err := utils.GetOperationStatus(after)
+ Expect(err).NotTo(HaveOccurred())
+ Expect(afterStatus).To(Equal(beforeStatus))
+ Expect(ctx.Recorder.(*record.FakeRecorder).Events).To(BeEmpty())
+ },
+ Entry("DataLoad that never waited", func() client.Object {
+ return &datav1alpha1.DataLoad{ObjectMeta: metav1.ObjectMeta{Name: loadName, Namespace: namespace},
+ Status: datav1alpha1.OperationStatus{Phase: common.PhaseComplete}}
+ }, reconcileDataLoad),
+ Entry("DataBackup that already stopped waiting", func() client.Object {
+ return &datav1alpha1.DataBackup{ObjectMeta: metav1.ObjectMeta{Name: backupName, Namespace: namespace},
+ Status: datav1alpha1.OperationStatus{Phase: common.PhaseExecuting, WaitingFor: datav1alpha1.WaitingStatus{OperationComplete: ptr.To(false)}}}
+ }, reconcileDataBackup),
+ Entry("DataMigrate that never waited", func() client.Object {
+ return &datav1alpha1.DataMigrate{ObjectMeta: metav1.ObjectMeta{Name: migrateName, Namespace: namespace},
+ Status: datav1alpha1.OperationStatus{Phase: common.PhaseExecuting}}
+ }, reconcileDataMigrate),
+ Entry("DataProcess that already stopped waiting", func() client.Object {
+ return &datav1alpha1.DataProcess{ObjectMeta: metav1.ObjectMeta{Name: processName, Namespace: namespace},
+ Status: datav1alpha1.OperationStatus{Phase: common.PhaseComplete, WaitingFor: datav1alpha1.WaitingStatus{OperationComplete: ptr.To(false)}}}
+ }, reconcileDataProcess),
+ )
+})
+
+var _ = Describe("record why a data operation stopped waiting for its preceding operation", func() {
+
+ const namespace = "default"
+
+ var s *runtime.Scheme
+
+ BeforeEach(func() {
+ s = runtime.NewScheme()
+ _ = datav1alpha1.AddToScheme(s)
+ })
+
+ newDataLoadAfterCompletedPreceding := func(operationComplete bool) []runtime.Object {
+ precedingLoad := &datav1alpha1.DataLoad{
+ ObjectMeta: metav1.ObjectMeta{Name: "preceding", Namespace: namespace},
+ Status: datav1alpha1.OperationStatus{Phase: common.PhaseComplete},
+ }
+ load := &datav1alpha1.DataLoad{
+ ObjectMeta: metav1.ObjectMeta{Name: loadName, Namespace: namespace},
+ Spec: datav1alpha1.DataLoadSpec{
+ RunAfter: &datav1alpha1.OperationRef{
+ ObjectRef: datav1alpha1.ObjectRef{Kind: "DataLoad", Name: "preceding"},
+ },
+ },
+ Status: datav1alpha1.OperationStatus{
+ Phase: common.PhasePending,
+ WaitingFor: datav1alpha1.WaitingStatus{OperationComplete: ptr.To(operationComplete)},
+ },
+ }
+ return []runtime.Object{precedingLoad, load}
+ }
+
+ It("should record an event when the preceding operation completed", func() {
+ ctx := makeTestCtx(s, loadName, namespace, newDataLoadAfterCompletedPreceding(true)...)
+
+ needRequeue, err := reconcileDataLoad(ctx)
+ Expect(err).NotTo(HaveOccurred())
+ Expect(needRequeue).To(BeFalse())
+ Expect(ctx.Recorder.(*record.FakeRecorder).Events).To(Receive(And(
+ ContainSubstring(common.DataOperationWaitingEnded),
+ ContainSubstring(`DataLoad "default/preceding" completed`))))
+ })
+
+ It("should not record an event for an operation that is not waiting", func() {
+ ctx := makeTestCtx(s, loadName, namespace, newDataLoadAfterCompletedPreceding(false)...)
+
+ needRequeue, err := reconcileDataLoad(ctx)
+ Expect(err).NotTo(HaveOccurred())
+ Expect(needRequeue).To(BeFalse())
+ Expect(ctx.Recorder.(*record.FakeRecorder).Events).To(BeEmpty())
+ })
+})
diff --git a/test/gha-e2e/curvine/dataload_runafter_removed.yaml b/test/gha-e2e/curvine/dataload_runafter_removed.yaml
new file mode 100644
index 00000000000..108d935bfd4
--- /dev/null
+++ b/test/gha-e2e/curvine/dataload_runafter_removed.yaml
@@ -0,0 +1,15 @@
+apiVersion: data.fluid.io/v1alpha1
+kind: DataLoad
+metadata:
+ name: curvine-dataload-runafter-removed
+spec:
+ dataset:
+ name: curvine-demo
+ namespace: default
+ # The preceding DataLoad is never created, so this DataLoad stays Pending and waits for it
+ # until the test removes spec.runAfter.
+ runAfter:
+ kind: DataLoad
+ name: curvine-dataload-never-created
+ target:
+ - path: /minio
diff --git a/test/gha-e2e/curvine/test.sh b/test/gha-e2e/curvine/test.sh
index f83b56d56ac..39efa993f03 100644
--- a/test/gha-e2e/curvine/test.sh
+++ b/test/gha-e2e/curvine/test.sh
@@ -257,6 +257,7 @@ function dump_env_and_clean_up() {
kubectl delete --ignore-not-found -f test/gha-e2e/curvine/read_job.yaml
kubectl delete --ignore-not-found -f test/gha-e2e/curvine/write_job.yaml
kubectl delete --ignore-not-found -f test/gha-e2e/curvine/dataload.yaml
+ kubectl delete --ignore-not-found -f test/gha-e2e/curvine/dataload_runafter_removed.yaml
kubectl delete --ignore-not-found -f test/gha-e2e/curvine/ref-dataset.yaml
# ThinRuntime will be automatically deleted when reference dataset is deleted
kubectl delete --ignore-not-found -f test/gha-e2e/curvine/dataset.yaml
@@ -289,6 +290,107 @@ function wait_dataload_completed() {
done
syslog "Found succeeded dataload_name $dataload_name"
}
+
+# dataset_controller_restarts prints "=" for every dataset-controller pod, so a
+# crash shows up either as a higher restart count or as a replaced pod.
+function dataset_controller_restarts() {
+ kubectl get pods -n fluid-system -l control-plane=dataset-controller \
+ -ojsonpath='{range .items[*]}{.metadata.name}={.status.containerStatuses[?(@.name=="manager")].restartCount}{" "}{end}'
+}
+
+function fail_dataload_runafter_removed() {
+ local dataload_name=$1
+ local manifest=$2
+ local err_msg=$3
+ local pod
+
+ syslog "--- DataLoad $dataload_name ---"
+ kubectl get dataload "$dataload_name" -oyaml 2>&1 || true
+ syslog "--- Events of DataLoad $dataload_name ---"
+ kubectl get events --field-selector "involvedObject.kind=DataLoad,involvedObject.name=$dataload_name" 2>&1 || true
+ syslog "--- dataset-controller pods ---"
+ kubectl get pods -n fluid-system -l control-plane=dataset-controller -owide 2>&1 || true
+ for pod in $(kubectl get pods -n fluid-system -l control-plane=dataset-controller -oname); do
+ syslog "--- previous dataset-controller container logs of $pod (if it restarted) ---"
+ kubectl logs -n fluid-system "$pod" -c manager --previous --tail=60 2>&1 || true
+ done
+ # Marking the DataLoad for deletion stops a crash-looping dataset-controller from picking it up
+ # again, since the DataFlow reconciler skips objects that are being deleted.
+ kubectl delete --ignore-not-found --wait=false -f "$manifest" || true
+ panic "$err_msg"
+}
+
+# A data operation keeps status.waitingFor.operationComplete=true while it waits for the operation
+# in spec.runAfter. Removing spec.runAfter at that point must release it like a normal DataLoad;
+# the DataFlow reconciler used to dereference the missing runAfter and crash-loop dataset-controller.
+function verify_dataload_runafter_removed() {
+ local dataload_name="curvine-dataload-runafter-removed"
+ local manifest="test/gha-e2e/curvine/dataload_runafter_removed.yaml"
+ local phase=""
+ local waiting=""
+ local not_found_event=""
+ local restarts_before=""
+ local restarts_now=""
+ local i
+
+ kubectl create -f "$manifest"
+
+ # Precondition: the DataLoad waits for its preceding operation and the DataFlow reconciler has
+ # handled it (it reports the preceding DataLoad as not found), so the check below cannot pass
+ # without exercising the DataFlow reconciler.
+ for ((i = 0; i < 24; i++)); do
+ phase=$(kubectl get dataload "$dataload_name" -ojsonpath='{.status.phase}')
+ waiting=$(kubectl get dataload "$dataload_name" -ojsonpath='{.status.waitingFor.operationComplete}')
+ not_found_event=$(kubectl get events -oname \
+ --field-selector "involvedObject.kind=DataLoad,involvedObject.name=$dataload_name,reason=DataOperationNotFound")
+ if [[ "$phase" == "Pending" && "$waiting" == "true" && -n "$not_found_event" ]]; then
+ break
+ fi
+ sleep 5
+ done
+ if [[ "$phase" != "Pending" || "$waiting" != "true" || -z "$not_found_event" ]]; then
+ fail_dataload_runafter_removed "$dataload_name" "$manifest" \
+ "DataLoad $dataload_name never waited for its preceding operation (phase: ${phase:-}, waitingFor.operationComplete: ${waiting:-}, DataOperationNotFound event: ${not_found_event:-})"
+ fi
+ syslog "DataLoad $dataload_name is Pending and waiting for its preceding operation"
+
+ restarts_before=$(dataset_controller_restarts)
+ # With no dataset-controller pod to compare against, the restart checks below would pass vacuously.
+ if [[ ! "$restarts_before" =~ =[0-9]+ ]]; then
+ fail_dataload_runafter_removed "$dataload_name" "$manifest" \
+ "found no dataset-controller pod restart count to compare against (got: ${restarts_before:-})"
+ fi
+ kubectl patch dataload "$dataload_name" --type=json -p '[{"op":"remove","path":"/spec/runAfter"}]'
+ syslog "removed spec.runAfter from DataLoad $dataload_name, dataset-controller restarts: $restarts_before"
+
+ # wait at most 180 seconds for the DataLoad to complete
+ for ((i = 0; i < 36; i++)); do
+ restarts_now=$(dataset_controller_restarts)
+ if [[ "$restarts_now" != "$restarts_before" ]]; then
+ fail_dataload_runafter_removed "$dataload_name" "$manifest" \
+ "dataset-controller restarted after spec.runAfter was removed from DataLoad $dataload_name (before: $restarts_before, now: $restarts_now)"
+ fi
+ phase=$(kubectl get dataload "$dataload_name" -ojsonpath='{.status.phase}')
+ if [[ "$phase" == "Complete" ]]; then
+ break
+ fi
+ sleep 5
+ done
+ if [[ "$phase" != "Complete" ]]; then
+ waiting=$(kubectl get dataload "$dataload_name" -ojsonpath='{.status.waitingFor.operationComplete}')
+ fail_dataload_runafter_removed "$dataload_name" "$manifest" \
+ "DataLoad $dataload_name did not complete within 180s after spec.runAfter was removed (phase: ${phase:-}, waitingFor.operationComplete: ${waiting:-})"
+ fi
+
+ restarts_now=$(dataset_controller_restarts)
+ if [[ "$restarts_now" != "$restarts_before" ]]; then
+ fail_dataload_runafter_removed "$dataload_name" "$manifest" \
+ "dataset-controller restarted after spec.runAfter was removed from DataLoad $dataload_name (before: $restarts_before, now: $restarts_now)"
+ fi
+ syslog "DataLoad $dataload_name completed after spec.runAfter was removed, dataset-controller did not restart"
+ kubectl delete -f "$manifest"
+}
+
function scale_worker_and_verify() {
local target_replicas=$1
local method=${2:-patch}
@@ -561,6 +663,8 @@ function main() {
wait_job_completed $write_job_name
create_dataload
wait_dataload_completed "curvine-dataload"
+ # verify removing spec.runAfter from a waiting DataLoad releases it without crashing dataset-controller
+ verify_dataload_runafter_removed
wait_cache_client_ready
create_job test/gha-e2e/curvine/read_job.yaml $read_job_name
wait_job_completed $read_job_name