Skip to content

Commit 410bce7

Browse files
committed
bugfix for goosefs engine
Signed-off-by: trafalgarzzz <trafalgarz@outlook.com>
1 parent b8ce053 commit 410bce7

2 files changed

Lines changed: 53 additions & 25 deletions

File tree

pkg/ddc/goosefs/runtime_info.go

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@ limitations under the License.
1717
package goosefs
1818

1919
import (
20+
"fmt"
21+
22+
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
2023
"github.com/fluid-cloudnative/fluid/pkg/ddc/base"
2124
"github.com/fluid-cloudnative/fluid/pkg/utils"
2225
"github.com/fluid-cloudnative/fluid/pkg/utils/dataset/volume"
26+
"k8s.io/apimachinery/pkg/util/validation/field"
2327
)
2428

2529
// getRuntimeInfo gets runtime info
2630
func (e *GooseFSEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) {
27-
if e.runtimeInfo == nil {
28-
runtime, err := e.getRuntime()
29-
if err != nil {
30-
return e.runtimeInfo, err
31-
}
31+
runtime, err := e.getRuntime()
32+
if err != nil {
33+
return e.runtimeInfo, err
34+
}
3235

36+
if e.runtimeInfo == nil {
3337
opts := []base.RuntimeInfoOption{
3438
base.WithTieredStore(runtime.Spec.TieredStore),
3539
base.WithMetadataList(base.GetMetadataListFromAnnotation(runtime)),
@@ -45,26 +49,6 @@ func (e *GooseFSEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) {
4549
e.runtimeInfo.SetFuseNodeSelector(runtime.Spec.Fuse.NodeSelector)
4650

4751
if !e.UnitTest {
48-
// Setup with Dataset Info
49-
dataset, err := utils.GetDataset(e.Client, e.name, e.namespace)
50-
if err != nil {
51-
if len(runtime.GetOwnerReferences()) > 0 {
52-
e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID)
53-
}
54-
if utils.IgnoreNotFound(err) == nil {
55-
e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace)
56-
return e.runtimeInfo, nil
57-
}
58-
59-
e.Log.Info("Failed to get dataset when getruntimeInfo")
60-
return e.runtimeInfo, err
61-
}
62-
63-
e.runtimeInfo.SetupWithDataset(dataset)
64-
e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive())
65-
66-
e.runtimeInfo.SetOwnerDatasetUID(dataset.UID)
67-
6852
// Check if the runtime is using deprecated labels
6953
isLabelDeprecated, err := e.HasDeprecatedCommonLabelname()
7054
if err != nil {
@@ -84,5 +68,36 @@ func (e *GooseFSEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) {
8468
}
8569
}
8670

71+
// Handling information of bound dataset. XXXEngine.getRuntimeInfo() might be called before the runtime is bound to a dataset,
72+
// so here we must lazily set dataset-related information once we found there's one bound dataset.
73+
if len(e.runtimeInfo.GetOwnerDatasetUID()) == 0 {
74+
owners := runtime.GetOwnerReferences()
75+
if len(owners) > 0 {
76+
firstOwner := owners[0]
77+
firstOwnerPath := field.NewPath("metadata").Child("ownerReferences").Index(0)
78+
if firstOwner.Kind != datav1alpha1.Datasetkind {
79+
return nil, fmt.Errorf("first owner of the runtime (%s) has invalid Kind \"%s\", expected to be %s ", firstOwnerPath.String(), firstOwner.Kind, datav1alpha1.Datasetkind)
80+
}
81+
82+
if firstOwner.Name != runtime.GetName() {
83+
return nil, fmt.Errorf("first owner of the runtime (%s) has different name with runtime, expected to be same", firstOwnerPath.String())
84+
}
85+
86+
e.runtimeInfo.SetOwnerDatasetUID(firstOwner.UID)
87+
}
88+
}
89+
90+
exclusiveModePtr := e.runtimeInfo.IsExclusive()
91+
if exclusiveModePtr == nil {
92+
dataset, err := utils.GetDataset(e.Client, e.name, e.namespace)
93+
if utils.IgnoreNotFound(err) != nil {
94+
return nil, err
95+
}
96+
97+
if dataset != nil {
98+
e.runtimeInfo.SetupWithDataset(dataset)
99+
}
100+
}
101+
87102
return e.runtimeInfo, nil
88103
}

pkg/ddc/goosefs/validate.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,23 @@ limitations under the License.
1717
package goosefs
1818

1919
import (
20+
"github.com/fluid-cloudnative/fluid/pkg/ddc/base"
2021
cruntime "github.com/fluid-cloudnative/fluid/pkg/runtime"
2122
)
2223

2324
func (e *GooseFSEngine) Validate(ctx cruntime.ReconcileRequestContext) (err error) {
25+
// XXXEngine.runtimeInfo must have full information about the bound dataset for further reconcilation.
26+
// getRuntimeInfo() here is a refresh to make sure the information is correctly set
27+
runtimeInfo, err := e.getRuntimeInfo()
28+
if err != nil {
29+
return err
30+
}
31+
32+
err = base.ValidateRuntimeInfo(runtimeInfo)
33+
if err != nil {
34+
return err
35+
}
36+
2437
// TODO: impl validation logic for GooseFSEngine
2538
return nil
2639
}

0 commit comments

Comments
 (0)