-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix delete dataupload datadownload failure when Velero uninstall #6689
Conversation
Codecov Report
@@ Coverage Diff @@
## main #6689 +/- ##
=======================================
Coverage 60.36% 60.36%
=======================================
Files 242 242
Lines 25982 25982
=======================================
Hits 15683 15683
Misses 9196 9196
Partials 1103 1103
|
78332fd
to
5b1aa19
Compare
pkg/cmd/cli/uninstall/uninstall.go
Outdated
@@ -293,10 +343,53 @@ func gracefullyDeleteRestore(ctx context.Context, kbClient kbclient.Client, name | |||
return err | |||
} | |||
|
|||
func forcedlyDeleteRestore(ctx context.Context, kbClient kbclient.Client, namespace string) error { | |||
func gracefullyWaitDataUpload(ctx context.Context, kbClient kbclient.Client, namespace string) error { |
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.
Creating each function for Restore, DataUpload, and DataDownload seems a bit redundant.
Could we use a unified function for all three resources?
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.
I've used the reflect
mechanism in Golang to restructure it.
9688d69
to
b3609e5
Compare
pkg/cmd/cli/uninstall/uninstall.go
Outdated
return removeResourceFinalizer(ctx, kbClient, namespace) | ||
} | ||
|
||
func removeResourceFinalizer(ctx context.Context, kbClient kbclient.Client, namespace string) error { |
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.
For this function, I try to use reflect
in Golang, It always panics with panic: interface conversion: v2alpha1.DataUpload is not client.Object: missing method DeepCopyObject
. I could not figure it out in a short time. so I keep it with redundancy codes
func removeFinalizer(ctx context.Context, kbClient kbclient.Client, namespace string, resourceList kbclient.ObjectList, finalizer string) error {
listOptions := &kbclient.ListOptions{Namespace: namespace}
if err := kbClient.List(ctx, resourceList, listOptions); err != nil {
return errors.Wrap(err, fmt.Sprintf("Error getting resources of type %T during force deletion", resourceList))
}
itemsValue := reflect.ValueOf(resourceList).Elem().FieldByName("Items")
for i := 0; i < itemsValue.Len(); i++ {
item := itemsValue.Index(i).Interface().(kbclient.Object)
if controllerutil.ContainsFinalizer(item, finalizer) {
update := item.DeepCopyObject().(kbclient.Object)
original := item.DeepCopyObject().(kbclient.Object)
controllerutil.RemoveFinalizer(update, finalizer)
if err := kubeutil.PatchResource(original, update, kbClient); err != nil {
return errors.Wrap(err, fmt.Sprintf("Error removing finalizer %q during force deletion", finalizer))
}
}
}
return nil
}
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.
If our type does not conform to that interface, I think this could be a larger problem for anyone working with these API's. I think to fix, you have to run the controller-tools tool to generate these methods for the API.
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.
Thanks for your comment @shawn-hurley, I've fixed it.
I should not covert interface into kbclient.Object
type in item := itemsValue.Index(i).Interface().(kbclient.Object)
As here is the definition of DatauploadList
type DataUploadList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []DataUpload `json:"items"`
}
And we have the DeepCopyObject function for *DataUpload type not DataUpload:
func (in *DataUpload) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
The Item in DataUploadList is DataUpload
but not *DataUpload
, so it panic with v2alpha1.DataUpload is not client.Object: missing method DeepCopyObject
1a9e644
to
49b9638
Compare
Signed-off-by: Ming <mqiu@vmware.com>
49b9638
to
7f3b7fe
Compare
Thank you for contributing to Velero!
Please add a summary of your change
Does your change fix a particular issue?
Fixes #(issue)
#6687
Please indicate you've done the following:
/kind changelog-not-required
as a comment on this pull request.site/content/docs/main
.