Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Implement orphaning-deletion commands #1008

Merged
merged 1 commit into from
Jul 17, 2019

Conversation

roytman
Copy link
Contributor

@roytman roytman commented Jun 20, 2019

Fix for #690

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 20, 2019
@roytman roytman force-pushed the orphaning branch 2 times, most recently from dcd6f8d to 7884655 Compare June 20, 2019 05:55
@marun marun self-requested a review June 26, 2019 14:23
@marun
Copy link
Contributor

marun commented Jun 26, 2019

Thank you for doing this! I am reviewing.

Copy link
Contributor

@xunpan xunpan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your code. The function is fine to me. Please see my comments below.

By the way, we need to add test code for the related function for CI. It is fine to have a sepearated PR for that.


orphaning_disable_example = `
# Removes the "orphaning enable" annotation from a federated resources of Deployment foo,
kubefedctl orphaning disable deployments.apps foo --host-cluster-context=cluster1`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deployments.apps is type config object name. If my understanding is right, it should be Federated* type. Same comments for enable.go, status.go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an example of the command (flag) usage, so it operates with a specific types. In the above explanation mentions a generic "federated resource"
The same convention exists with others kubefedctl and kubectl commands

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the command line can operate on a specified federated type with object name specified as documented in user guide.

kubefedctl orphaning-deletion enable <federated type> <name>

My question is about the example of using <federated type>

deployments.apps is a FederatedTypeConfig object but not a federated type.

$ kubectl -n kube-federation-system get federatedtypeconfigs deployments.apps
NAME               AGE
deployments.apps   7m

I think a name with Federated prefixed makes more sense for the example. E.g. kubefedctl orphaning enable FederatedDeployment foo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks for the explanation. Fixed.

return nil
}
st, ok := annotations[sync.OrphanManagedResources]
if !ok || st == "false" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[sugguestion] functionally, it is good. To me, a definite consistent behavior should be better for a command line operation. If enable, add/update annotation to be true. If disable, there should no the annotation no matter it is false or true before the command line is executed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to save an addition update, but I'd agree with you, better have a consistent behavior.
Fixed.

@roytman
Copy link
Contributor Author

roytman commented Jul 3, 2019

Hi @xunpan , thanks for your review. I fixed part of your comments and added responses to others. Please take a look, if it is OK now.
Thanks Alexey.

Copy link
Contributor

@xunpan xunpan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 minor readability comments.

And for commits, could you please squash them. It is not encouraged to keep commits that are only used to fix previous commit in one PR.

"sigs.k8s.io/kubefed/pkg/apis/core/typeconfig"
ctlutil "sigs.k8s.io/kubefed/pkg/controller/util"
"sigs.k8s.io/kubefed/pkg/kubefedctl/enable"
"sigs.k8s.io/kubefed/pkg/kubefedctl/options"
"sigs.k8s.io/kubefed/pkg/kubefedctl/util"
"sigs.k8s.io/yaml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better readability, it is import convention in kubefed:

import(
    "core-packages"

    "3rd-party-packages"

    "kubefed-packages"
)

E.g.:

import (
	"io"
	"os"

    	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
	"k8s.io/apimachinery/pkg/runtime/schema"

	"sigs.k8s.io/kubefed/pkg/kubefedctl/enable"
	"sigs.k8s.io/kubefed/pkg/kubefedctl/options"
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it,
looks like kubefed uses a slightly different import convention:

import(
    "core-packages"

    "3rd-party-packages"

    "K8s packages"

    "kubefed-packages"
) ```
Is it correct ?


// RunEnable implements the `enable` command.
func (o *orphanResource) RunEnable(cmdOut io.Writer, config util.FedConfig) error {
fedResource, resources, err := o.GetFederatedResource(config)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resources is actually a resourceClient I think. It is also better to have resources in GetFederatedResource as resourceClient. It is a little confuse to use resource and resources in GetFederatedResource for different types of object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, fixed

@xunpan
Copy link
Contributor

xunpan commented Jul 5, 2019

@roytman
This change impacts user interface. Please also update CHANGELOG.md in Unreleased section.
E.g.
https://github.com/kubernetes-sigs/kubefed/pull/1010/files

@roytman roytman force-pushed the orphaning branch 2 times, most recently from 86d2310 to 1bbd937 Compare July 5, 2019 07:53
@roytman
Copy link
Contributor Author

roytman commented Jul 5, 2019

2 minor readability comments.

And for commits, could you please squash them. It is not encouraged to keep commits that are only used to fix previous commit in one PR.
Did it, (I was under impression that all squashes are done during merge.)

@roytman
Copy link
Contributor Author

roytman commented Jul 5, 2019

This change impacts user interface. Please also update CHANGELOG.md in Unreleased section.
E.g.
https://github.com/kubernetes-sigs/kubefed/pull/1010/files

Done, thanks

Copy link
Contributor

@xunpan xunpan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks fine to me.

The comment is for .gitignore.

.gitignore Outdated

# Files generated by JetBrains IDEs, e.g. IntelliJ IDEA
.idea/
*.iml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.gitignore is used for project related files maintenance in kubefed.

I finally agreed this rule after thinking it over. I saw some projects which use .gitignore file with hundreds of lines code with editor specific ignore. It is hard to read and maintain. You can refer to #871.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the point.
Actually, I copied the entries from the Kubernetes main repository, and probably worth to be inline with it. But this discussion is out of this PR scope.
I removed the entries.

@xunpan
Copy link
Contributor

xunpan commented Jul 9, 2019

Thanks Roytman!
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 9, 2019
Copy link
Contributor

@marun marun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits aside, this is looking good!

Without #828 there isn't an easy path to testing of the cli just yet, but I would appreciate some common code paths being created (in the vein of the managed label helpers) to leverage the coverage for the sync controller check and crudtester check.

@k8s-ci-robot k8s-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Jul 11, 2019
@roytman roytman force-pushed the orphaning branch 3 times, most recently from edce614 to 9286659 Compare July 11, 2019 13:27
@k8s-ci-robot k8s-ci-robot removed the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 11, 2019
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 11, 2019
@roytman
Copy link
Contributor Author

roytman commented Jul 11, 2019

@marun , thanks for the review.

Without #828 there isn't an easy path to testing of the cli just yet, but I would appreciate some common code paths being created (in the vein of the managed label helpers) to leverage the coverage for the sync controller check and crudtester check.

I updated the code.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 12, 2019
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 12, 2019
Copy link
Contributor

@marun marun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for cleanup, nice work! A few more nits inline. The only functional change request is to allow the addition or removal of the annotation for resources that don't pass the weak check for a federated resource.

func (o *orphanResource) GetFederatedResource(resourceClient dynamic.ResourceInterface) (*unstructured.Unstructured, error) {
resource, err := resourceClient.Get(o.resourceName, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrapf(err, "Error retrieving resource %s %q", o.typeName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use the kind here rather than the type name the user passed in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to separation of GetResourceClient and GetFederatedResource, it will be complicated. In the GetFederatedResource I don't have a reference to resourceClient only to the dynamic.ResourceInterface.
In order to use Kind, I have to

  • or return Kind from GetResourceClient and provide it to GetFederatedResource
  • or move targetClient.Resources(o.resourceNamespace) out of GetResourceClient.

Both options look problematic for me. What do you think ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the first option is a change worth making to ensure the UX consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented the first option.
For generalizing, GetResourceClient returns entire *metav1.APIResource, but it can be easily replace by Kind only.
However, there is an additional option: the current error message looks like
Error: Error retrieving resource FederatedConfigMap "default/game-config1": federatedconfigmaps.types.kubefed.k8s.io "game-config1" not found

Do we really have to print the resource Kind or its user provided type? Anyway the dynamic client prints (at list in the most common case) the resource name and group. Maybe we should just return the dynamic client error.
What do you think?

@roytman
Copy link
Contributor Author

roytman commented Jul 16, 2019

The only functional change request is to allow the addition or removal of the annotation for resources that don't pass the weak check for a federated resource.

If a resource doesn't pass the weak check for a federated resource, I suggest to print a warning and continue the processing. What do you think ?

@roytman roytman force-pushed the orphaning branch 3 times, most recently from 7dda275 to c8356c3 Compare July 16, 2019 11:37
Copy link
Contributor

@marun marun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to printing a warning if the weak check passes rather than failing.

Thank you for cleanup! Nothing functional remains. Nits inline, and there are still some outstanding requests for change from my previous review that you may have missed (mainly wording of help text).

func (o *orphanResource) GetFederatedResource(resourceClient dynamic.ResourceInterface) (*unstructured.Unstructured, error) {
resource, err := resourceClient.Get(o.resourceName, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrapf(err, "Error retrieving resource %s %q", o.typeName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the first option is a change worth making to ensure the UX consistency.

}
klog.V(2).Infof("API Resource for %s.%s/%s found", apiResource.Name, apiResource.Group, apiResource.Version)
if !util.IsFederatedAPIResource(apiResource.Kind, apiResource.Group) {
fmt.Fprintf(cmdOut, "Warning: looks like the resource %s.%s/%s is not a Federated object\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/looks like the resource//
s/is not a Federated object/does not appear to be a federated resource/

As to how to compose name and group to avoid a trailing . for core groups, please use the GroupQualifiedName function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not aware about the GroupQualifiedName function, thanks.
I changed the warning message according to your suggestion, however, as I understood the function IsFederatedAPIResource cannot 100% guarantee that the checked resource is not a Federated resource. Therefore, I'd suggest a weaker statement.
What do you think about might not be a federated resource

Copy link
Contributor

@marun marun Jul 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think does not appear to be is equivalent to might not be (i.e. this does not appear to be correct vs this is not correct).

On second thought, please go ahead with your proposed change might not be a federated resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@roytman
Copy link
Contributor Author

roytman commented Jul 17, 2019

Thanks for your reviews and sorry for the missed comments.
I have 2 suggestions: one about the warning message, maybe the statement should be weaker, and another about the error message in GetFederatedResource .
Please take a look.

Copy link
Contributor

@marun marun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github isn't letting me reply to your comment about GetFederatedResource. I agree that the message that resulted from my suggestion is unnecessarily verbose, and I apologize for causing you extra work. How about Failed to retrieve resource: %v (no need for kind in that case)?

@marun
Copy link
Contributor

marun commented Jul 17, 2019

Nice work, thank you!

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 17, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: marun, roytman

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 17, 2019
@k8s-ci-robot k8s-ci-robot merged commit 16493d5 into kubernetes-retired:master Jul 17, 2019
@roytman roytman deleted the orphaning branch July 18, 2019 21:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants