Skip to content
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

Remove generator dependency of expose.go #106824

Merged
merged 1 commit into from Mar 30, 2022

Conversation

lauchokyip
Copy link
Member

@lauchokyip lauchokyip commented Dec 5, 2021

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Remove the generators dependency from kubectl expose

Which issue(s) this PR fixes:

Fixes #93100

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Remove deprecated generator and container-port flags

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/kubectl labels Dec 5, 2021
@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Dec 5, 2021
@lauchokyip
Copy link
Member Author

/cc @rikatz
/cc @soltysh

@lauchokyip
Copy link
Member Author

/triage accepted
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Dec 5, 2021
@lauchokyip
Copy link
Member Author

/retest

@lauchokyip
Copy link
Member Author

@eddiezane Maybe you can help out for this one too?

@deejross
Copy link
Contributor

/lgtm

@k8s-ci-robot
Copy link
Contributor

@deejross: changing LGTM is restricted to collaborators

In response to this:

/lgtm

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.

}
protocolsMap, err := o.ProtocolsForObject(info.Object)
if err != nil {
return cmdutil.UsageErrorf(cmd, "couldn't find protocol via introspection: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer we switch all internal errors to just return error, so fmt.Errorf("couldn't find protocol via introspection: %v", err) in the rest of the file as well. This allows consumers of the command to wrap the error and respond accordingly. Whereas cmdutil.UsafeErrorf adds unnecessarily kubectl specific information, ie. See 'kubectl expose -h' for help and examples, etc, which are already nicely handled in the cobra's Run command.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

labels, err := meta.NewAccessor().Labels(info.Object)
if err != nil {
return err
}
params["labels"] = polymorphichelpers.MakeLabels(labels)
}
if err = generate.ValidateParams(names, params); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

service/v2 has two required values: default-name and selector see https://github.com/kubernetes/kubectl/blob/1bf219da9bdd8c03758195f5b43f1ddfbe31c3e7/pkg/generate/versioned/service.go#L55-L57 make sure to have appropriate Validate method to reflect that.

Copy link
Member Author

Choose a reason for hiding this comment

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

default-name cannot be moved to Validate because if user does not provide a name it will call the API server and get from the info object which mean user does not have to provide a name beforehand.
https://github.com/kubernetes/kubectl/blob/1bf219da9bdd8c03758195f5b43f1ddfbe31c3e7/pkg/cmd/expose/expose.go#L254

same as selector
https://github.com/kubernetes/kubectl/blob/1bf219da9bdd8c03758195f5b43f1ddfbe31c3e7/pkg/cmd/expose/expose.go#L263

if len(o.Selector) == 0 {
return nil, fmt.Errorf("selector must be specified")
}
selector, err := parseLabels(o.Selector)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably worth moving that to Validate

Copy link
Member Author

Choose a reason for hiding this comment

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

See comment above


var labels map[string]string
if len(o.Labels) > 0 {
labels, err = parseLabels(o.Labels)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, move to Validate.

Copy link
Member Author

Choose a reason for hiding this comment

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

See comment above

@@ -856,3 +858,878 @@ status:
})
}
}

func TestGenerateService(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Very good extensive tests 👍

@lauchokyip
Copy link
Member Author

lauchokyip commented Dec 29, 2021

@soltysh , I don't think anything can be changed anymore. I have already thought of moving to Validate before submitting the PR but expose.go is different because almost all validation are done inside RunExpose

This PR preserves the intended behavior with generator without disrupting the flow of the code

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Dec 29, 2021
@dims
Copy link
Member

dims commented Jan 7, 2022

looks like @lauchokyip has responses for all the comments, back to approver!

/assign @soltysh

@dims
Copy link
Member

dims commented Jan 7, 2022

/retest

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 29, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lauchokyip, soltysh

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 Mar 29, 2022
@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

1 similar comment
@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

@eddiezane
Copy link
Member

/retest

@eddiezane
Copy link
Member

Flake is #108891

/retest

@k8s-ci-robot k8s-ci-robot merged commit d429c98 into kubernetes:master Mar 30, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Mar 30, 2022
@k8s-ci-robot
Copy link
Contributor

@lauchokyip: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-conformance-kind-ga-only-parallel d7ab8d4 link unknown /test pull-kubernetes-conformance-kind-ga-only-parallel
pull-kubernetes-e2e-gce-ubuntu-containerd d7ab8d4 link unknown /test pull-kubernetes-e2e-gce-ubuntu-containerd

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove generators from kubectl commands
7 participants