-
Notifications
You must be signed in to change notification settings - Fork 949
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
bugfix: reconcile thinruntime failed when dataset is deleted #3300
Changes from 2 commits
d8803fd
7c17839
b1502eb
bab8073
d8b9502
be22993
23cfbbb
bab35e0
bfe7774
0d84355
21548bb
c3a4e09
a6a2f41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ func TestGetMountedDatasetNamespacedName(t *testing.T) { | |
}, | ||
} | ||
for _, tt := range tests { | ||
if got := GetMountedDatasetNamespacedName(tt.virtualDataset); len(got) != tt.want { | ||
if got := GetMountedDatasetNamespacedName(tt.virtualDataset.Spec.Mounts); len(got) != tt.want { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about renaming the function name to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
t.Errorf("GetMountedDatasetNamespacedName() len = %v, want %v", got, tt.want) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,10 +117,21 @@ func Precheck(client client.Client, key types.NamespacedName) (found bool, err e | |
func CheckReferenceDatasetRuntime(client client.Client, runtime *datav1alpha1.ThinRuntime) (bool, error) { | ||
dataset, err := utils.GetDataset(client, runtime.Name, runtime.Namespace) | ||
if err != nil { | ||
return false, err | ||
if utils.IgnoreNotFound(err) == nil && runtime.Status.Mounts != nil && len(runtime.Status.Mounts) != 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should make it work even the virtualDataset is already deleted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normally, the virtualDataset would not be deleted because its reference runtime has not been cleaned up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it may happen when deleting virtualDataset forcely. How to handle this then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
// dataset not found, but can GetMountedDatasetNamespacedName from runtime | ||
} else { | ||
return false, err | ||
} | ||
} | ||
|
||
mounted := base.GetMountedDatasetNamespacedName(dataset) | ||
var mounted []types.NamespacedName | ||
if dataset != nil { | ||
// getMountedDataset from dataset first | ||
mounted = base.GetMountedDatasetNamespacedName(dataset.Spec.Mounts) | ||
} else if runtime.Status.Mounts != nil && len(runtime.Status.Mounts) != 0 { | ||
// then try to getMountedDataset from runtime | ||
mounted = base.GetMountedDatasetNamespacedName(runtime.Status.Mounts) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will happen if dataset is not found and the length of runtime mounts is 0? How will the user handle this situation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The case will be protected by checking existence of reference datasets before removing any physical dataset. This can be done in the next PR. |
||
// not mount other datasets | ||
if len(mounted) == 0 { | ||
return false, nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,11 @@ func (e *ReferenceDatasetEngine) getMountedDatasetRuntimeStatus() (status *datav | |
return status, err | ||
} | ||
|
||
// if mountedRuntimeInfo is nil and no err, the runtime is deleting. | ||
if mountedRuntimeInfo == nil { | ||
return nil, nil | ||
} | ||
|
||
return base.GetRuntimeStatus(e.Client, mountedRuntimeInfo.GetRuntimeType(), | ||
mountedRuntimeInfo.GetName(), mountedRuntimeInfo.GetNamespace()) | ||
} | ||
|
@@ -91,20 +96,39 @@ func (e *ReferenceDatasetEngine) getRuntimeInfo() (base.RuntimeInfoInterface, er | |
e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) | ||
|
||
return e.runtimeInfo, nil | ||
|
||
} | ||
|
||
// getMountedRuntimeInfo get mountedRuntimeInfo from dataset. | ||
// If could not get dataset, getMountedRuntimeInfo try to get mountedRuntimeInfo from runtime status. | ||
// And if dataset is deleted and no status.mounts, it returns nil, nil to continue runtimeDeletion. | ||
func (e *ReferenceDatasetEngine) getMountedRuntimeInfo() (base.RuntimeInfoInterface, error) { | ||
if e.mountedRuntimeInfo != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add comment: // If already have mountedRuntimeInfo, return it directly |
||
return e.mountedRuntimeInfo, nil | ||
} | ||
|
||
dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) | ||
// if err is not found, try to get mountedRuntimeInfo from runtime status, don't return here. | ||
if err != nil && utils.IgnoreNotFound(err) != nil { | ||
return e.mountedRuntimeInfo, err | ||
} | ||
|
||
runtime, err := e.getRuntime() | ||
if err != nil { | ||
return e.mountedRuntimeInfo, err | ||
} | ||
|
||
mountedNameSpacedNames := base.GetMountedDatasetNamespacedName(dataset) | ||
var mountedNameSpacedNames []types.NamespacedName | ||
if dataset != nil { | ||
// get mountedRuntimeInfo from dataset first | ||
mountedNameSpacedNames = base.GetMountedDatasetNamespacedName(dataset.Spec.Mounts) | ||
} else if runtime.Status.Mounts != nil && len(runtime.Status.Mounts) != 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
// then try to get mountedRuntimeInfo from runtime status | ||
mountedNameSpacedNames = base.GetMountedDatasetNamespacedName(runtime.Status.Mounts) | ||
} else { | ||
// The dataset is not found and no status.mounts, in this case, the runtime is deleting, return nil, nil | ||
e.Log.Info("The dataset is deleted and no runtime.Status.Mounts, in this case, the runtime is deleting, return nil, nil") | ||
return nil, nil | ||
} | ||
if len(mountedNameSpacedNames) != 1 { | ||
return e.mountedRuntimeInfo, fmt.Errorf("ThinEngine with no profile name can only handle dataset only mounting one dataset") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add comments about the reason of changing the order of step 2 and 3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the order was used to judge GetOrCreateEngine failed reason which is runtime having deletionTimeStamp. In this case we should ignore the GetOrCreateEngine error and continue to reconcileruntimeDeletion, but it would cause engine is a nil pointer. And we have resolvd this problem inside GetOrCreateEngine so that it would return an engine although it could not get mounted dataset. So the order is no need to change now and i will fix it.