-
Notifications
You must be signed in to change notification settings - Fork 533
Feature: support DeleteOptions when deleting resources in member clusters #1355
Feature: support DeleteOptions when deleting resources in member clusters #1355
Conversation
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Welcome @RolandMa1986! |
99c3f4e
to
992cbfc
Compare
992cbfc
to
dae1472
Compare
@RolandMa1986: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
967ce5b
to
fe0376a
Compare
I will review this PR during this week. |
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.
This might come in as a handy feature in general. Just some minor change requests. I will also comment on the associated issue with a question that came up while reviewing.
@@ -0,0 +1,67 @@ | |||
/* | |||
Copyright 2019 The Kubernetes Authors. |
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.
Copyright 2019 The Kubernetes Authors. | |
Copyright 2021 The Kubernetes Authors. |
) | ||
|
||
// GetDeleteOptions return delete options from the annotation | ||
func GetDeleteOptions(obj *unstructured.Unstructured) []client.DeleteOption { |
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.
func GetDeleteOptions(obj *unstructured.Unstructured) []client.DeleteOption { | |
func GetDeleteOptions(obj *unstructured.Unstructured) ([]client.DeleteOption, error) { |
if err := json.Unmarshal([]byte(optStr), opt); err == nil { | ||
clientOpt := &client.DeleteOptions{} | ||
clientOpt.GracePeriodSeconds = opt.GracePeriodSeconds | ||
clientOpt.PropagationPolicy = opt.PropagationPolicy | ||
clientOpt.Preconditions = opt.Preconditions | ||
options = append(options, clientOpt) | ||
} |
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.
As this is a user-supplied value, we should expect the unmarshalling to fail, e.g. because the user failed to supply valid JSON in the annotation:
if err := json.Unmarshal([]byte(optStr), opt); err == nil { | |
clientOpt := &client.DeleteOptions{} | |
clientOpt.GracePeriodSeconds = opt.GracePeriodSeconds | |
clientOpt.PropagationPolicy = opt.PropagationPolicy | |
clientOpt.Preconditions = opt.Preconditions | |
options = append(options, clientOpt) | |
} | |
if err := json.Unmarshal([]byte(optStr), opt); err != nil { | |
return fmt.Errorf("could not deserialize delete options from annotation value '%s': %w", optStr, err) | |
} | |
clientOpt := &client.DeleteOptions{} | |
clientOpt.GracePeriodSeconds = opt.GracePeriodSeconds | |
clientOpt.PropagationPolicy = opt.PropagationPolicy | |
clientOpt.Preconditions = opt.Preconditions | |
options = append(options, clientOpt) |
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 agree. Changes have been committed as you suggested.
options := make([]client.DeleteOption, 0) | ||
annotations := obj.GetAnnotations() | ||
if annotations == nil { | ||
return options |
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.
return options | |
return options, nil |
test/e2e/deleteoptions.go
Outdated
|
||
fixture := typeConfigFixtures[typeConfigName] | ||
|
||
It(`Deployment should be created and deleted successfully, but ReplicaSet that created by Deployment won't be deleted`, func() { |
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.
It(`Deployment should be created and deleted successfully, but ReplicaSet that created by Deployment won't be deleted`, func() { | |
It("Deployment should be created and deleted successfully, but ReplicaSet that created by Deployment won't be deleted", func() { |
just a nit
/ok-to-test |
fe0376a
to
71bd13a
Compare
if optStr, ok := annotations[DeleteOptionAnnotation]; ok { | ||
opt := &metav1.DeleteOptions{} | ||
if err := json.Unmarshal([]byte(optStr), opt); err != nil { | ||
return nil, fmt.Errorf("could not deserialize delete options from annotation value '%s': %w", optStr, err) |
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.
Sorry, my suggestion actually made CI complain:
return nil, fmt.Errorf("could not deserialize delete options from annotation value '%s': %w", optStr, err) | |
return nil, errors.Wrapf(err, "could not deserialize delete options from annotation value '%s'", optStr) |
|
||
kubeClient := kubeclientset.NewForConfigOrDie(clusterConfig) | ||
WaitForNamespaceOrDie(c.tl, kubeClient, clusterName, fedObject.GetNamespace(), | ||
c.waitInterval, 30*time.Second) |
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.
please use framework.PollInterval, framework.TestContext.SingleCallTimeout
instead of c.waitInterval, 30*time.Second
.
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 guess the framework
package depends on common
, so it doesn't allow me to import framework
in crudtester.go.
Any idea to resolve this? I'm pretty new to Golang.
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 believe you faced some cycle go deps here. It is alright, I'll move those common attributes to a different package. Not a blocker.
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.
@RolandMa1986 Great work! Overall looks good to me, I just left some comments in addition to those from @makkes.
The PR build failed due to:
|
Signed-off-by: RolandMa1986 <[email protected]>
71bd13a
to
7e48784
Compare
/retest |
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.
lgtm now, but somehow I missed an ignored possible error. If that's addressed, I'm all ✅
@RolandMa1986 lgtm too, let's just address these minor comments from @makkes |
Signed-off-by: RolandMa1986 <[email protected]>
7e48784
to
b7061be
Compare
/lgtm |
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.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hectorj2f, makkes, RolandMa1986 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Good job @RolandMa1986! Thanks for your contribution 👍🏻 ! |
/lgtm |
Thanks for your help @hectorj2f and @makkes. |
What this PR does / why we need it:
This PR implements PR #1348 to support DeleteOptions when deleting resources in member clusters. When deleting a federated resource with
kubefed.io/deleteoptions
annotation, it will be deserialized as a DeleteOptons object and apply to the delete operation.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #1348