-
Notifications
You must be signed in to change notification settings - Fork 40k
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
(#21648)add kubectl set port command #51947
Conversation
Hi @zjj2wry. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with I understand the commands that are listed here. 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. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: zjj2wry Assign the PR to them by writing No associated issue. Update pull-request body to add a reference to an issue, or get approval with The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
cc @kubernetes/sig-cli-pr-reviews |
@zjj2wry: Reiterating the mentions to trigger a notification: 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. |
pkg/kubectl/cmd/set/set_port.go
Outdated
"fmt" | ||
"io" | ||
"strings" | ||
|
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.
remove this newline?
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.
agree 👍
pkg/kubectl/cmd/set/set_port.go
Outdated
|
||
"strconv" | ||
|
||
"github.com/spf13/cobra" |
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.
add a newline here?
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.
alse agree
pkg/kubectl/cmd/set/set_port.go
Outdated
cmd.Flags().BoolVar(&options.All, "all", false, "Select all resources in the namespace of the specified resource types") | ||
cmd.Flags().StringVarP(&options.Selector, "selector", "l", "", "Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)") | ||
cmd.Flags().BoolVar(&options.Local, "local", false, "If true, set port will NOT contact api-server but run locally.") | ||
cmd.Flags().Int("port", 80, i18n.T("Name or number for the port on the container that the service should direct traffic to. Optional.")) |
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.
port
should be marked as required? I think we'd better not set default value, especially 80
. WDYT?
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.
yes, i will updated
pkg/kubectl/cmd/set/set_port.go
Outdated
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "port (-f FILENAME | TYPE NAME)", |
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.
appending --port
?
pkg/kubectl/cmd/set/set_port.go
Outdated
|
||
cmd := &cobra.Command{ | ||
Use: "port (-f FILENAME | TYPE NAME)", | ||
Short: i18n.T("Update port of a pod template"), |
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.
What about Update existing container port(s) of resources
?
pkg/kubectl/cmd/set/set_port.go
Outdated
if len(containers) == 0 { | ||
fmt.Println(info.Mapping.Resource, info.Name, o.containerSelector) | ||
_, err := fmt.Fprintf(o.Err, "warning: %s/%s does not have any containers matching %q\n", info.Mapping.Resource, info.Name, o.containerSelector) | ||
if err != 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.
what about
if _, err := xxx; err != nil {
return 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.
ok
pkg/kubectl/cmd/set/set_port.go
Outdated
return err | ||
} | ||
for _, c := range containers { | ||
if !o.overwrite { |
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.
L199-L205 seems have nothing to do with c
. Can we move it to outer?
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.
yes, thank you point it
pkg/kubectl/cmd/set/set_port.go
Outdated
if _, err := fmt.Fprintln(o.Out, "no resources changed"); err != nil { | ||
return nil, err | ||
} | ||
return nil, 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.
return nil, 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.
yes, this should be return nil,nil
for _, patch := range patches { | ||
info := patch.Info | ||
if patch.Err != nil { | ||
allErrs = append(allErrs, fmt.Errorf("error: %s/%s %v\n", info.Mapping.Resource, info.Name, patch.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.
not sure for adding \n
here.
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.
yes, this should
} | ||
|
||
// no changes | ||
if string(patch.Patch) == "{}" || len(patch.Patch) == 0 { |
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.
should have a better way of string(patch.Patch) == "{}"
.
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 follow other set command
@dixudx thanks, i will fix this tomorrow |
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.
@dixudx thank your careful review work. i will fix as soon as possible
o.Output = cmdutil.GetFlagString(cmd, "output") | ||
o.port = cmdutil.GetFlagInt(cmd, "port") | ||
o.protocol = strings.ToUpper(cmdutil.GetFlagString(cmd, "protocol")) | ||
o.containerSelector = cmdutil.GetFlagString(cmd, "containers") |
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 parse this in L184
o.Local = cmdutil.GetFlagBool(cmd, "local") | ||
o.DryRun = cmdutil.GetDryRunFlag(cmd) | ||
o.Output = cmdutil.GetFlagString(cmd, "output") | ||
o.port = cmdutil.GetFlagInt(cmd, "port") |
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.
not sure, but i'd more like keep a style.
pkg/kubectl/cmd/set/set_port.go
Outdated
cmd.Flags().BoolVar(&options.All, "all", false, "Select all resources in the namespace of the specified resource types") | ||
cmd.Flags().StringVarP(&options.Selector, "selector", "l", "", "Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)") | ||
cmd.Flags().BoolVar(&options.Local, "local", false, "If true, set port will NOT contact api-server but run locally.") | ||
cmd.Flags().Int("port", 80, i18n.T("Name or number for the port on the container that the service should direct traffic to. Optional.")) |
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.
yes, i will updated
pkg/kubectl/cmd/set/set_port.go
Outdated
if o.protocol != "TCP" && o.protocol != "UDP" { | ||
errors = append(errors, fmt.Errorf("protocol must tcp or udp")) | ||
} | ||
if o.port < 0 { |
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.
agree, i will follow server-side
pkg/kubectl/cmd/set/set_port.go
Outdated
if len(containers) == 0 { | ||
fmt.Println(info.Mapping.Resource, info.Name, o.containerSelector) | ||
_, err := fmt.Fprintf(o.Err, "warning: %s/%s does not have any containers matching %q\n", info.Mapping.Resource, info.Name, o.containerSelector) | ||
if err != 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.
ok
pkg/kubectl/cmd/set/set_port.go
Outdated
return err | ||
} | ||
for _, c := range containers { | ||
if !o.overwrite { |
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.
yes, thank you point it
pkg/kubectl/cmd/set/set_port.go
Outdated
if _, err := fmt.Fprintln(o.Out, "no resources changed"); err != nil { | ||
return nil, err | ||
} | ||
return nil, 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.
yes, this should be return nil,nil
return nil | ||
} | ||
|
||
func (o *PortOptions) Validate() 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.
port (-f FILENAME | TYPE NAME) [--port=PORT]
I think we'd better add validation on the type here.
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 validation in f.UpdatePodSpecForObject(info.Object, func(spec *api.PodSpec) error
} | ||
|
||
var ( | ||
portResources = ` |
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.
Should we add like this? This does not seems like k8s style.
Please refer below,
kubernetes/pkg/kubectl/cmd/cmd.go
Lines 202 to 242 in ea01771
validResources = `Valid resource types include: | |
* all | |
* certificatesigningrequests (aka 'csr') | |
* clusterrolebindings | |
* clusterroles | |
* clusters (valid only for federation apiservers) | |
* componentstatuses (aka 'cs') | |
* configmaps (aka 'cm') | |
* controllerrevisions | |
* cronjobs | |
* customresourcedefinition (aka 'crd') | |
* daemonsets (aka 'ds') | |
* deployments (aka 'deploy') | |
* endpoints (aka 'ep') | |
* events (aka 'ev') | |
* horizontalpodautoscalers (aka 'hpa') | |
* ingresses (aka 'ing') | |
* jobs | |
* limitranges (aka 'limits') | |
* namespaces (aka 'ns') | |
* networkpolicies (aka 'netpol') | |
* nodes (aka 'no') | |
* persistentvolumeclaims (aka 'pvc') | |
* persistentvolumes (aka 'pv') | |
* poddisruptionbudgets (aka 'pdb') | |
* podpreset | |
* pods (aka 'po') | |
* podsecuritypolicies (aka 'psp') | |
* podtemplates | |
* replicasets (aka 'rs') | |
* replicationcontrollers (aka 'rc') | |
* resourcequotas (aka 'quota') | |
* rolebindings | |
* roles | |
* secrets | |
* serviceaccounts (aka 'sa') | |
* services (aka 'svc') | |
* statefulsets | |
* storageclasses | |
` |
But we're trying to replace such hard-coded way, refer to #42873 and #51324.
@liggitt PTAL. For updating such container ports, can we use the old hard-coded strings.
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 mean support update env's resources
/kind feature |
/unassign |
/ok-to-test |
@zjj2wry: The following tests failed, say
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. |
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/types" | ||
utilerrors "k8s.io/apimachinery/pkg/util/errors" | ||
"k8s.io/kubernetes/pkg/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.
We are not introducing new deps on k8s.io/kubernetes. How can this PR be done without this? Can we use the versioned objects.
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.
we want to do this anyway, see the TODO in https://github.com/kubernetes/kubernetes/pull/53158/files#diff-466503ed5c81843c5ba705bc4c6fd4dc
// TODO: switch UpdatePodSpecForObject to work on v1.PodSpec, use info.VersionedObject, and avoid conversion completely
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.
Why a TODO? Can we do this now before this PR goes in? We are actively trying to remove these dependencies from kubectl.
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.
agree, was saying we could use this as an opportunity to resolve the TODO
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.
oh perfect :)
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.
there is a issue created by wangshiyang. will help fix it priority then fix this PR
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.
open PR #54554 fix this
return nil, err | ||
} | ||
if transformed && err == nil { | ||
return runtime.Encode(o.Encoder, info.Object) |
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.
rework this with the change from https://github.com/kubernetes/kubernetes/pull/53158/files#diff-466503ed5c81843c5ba705bc4c6fd4dc
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 is, this would fail intermittently on DaemonSet and ReplicaSet objects
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.
@liggitt nice, thank you very much.
needs tests in test-cmd-util.sh on the various resources |
will updated it quickly |
/assign @pwittrock |
/unassign @pwittrock |
This PR hasn't been active in 30 days. It will be closed in 59 days (Jan 23, 2018). cc @fabianofranz @seans3 @soltysh @zjj2wry You can add 'keep-open' label to prevent this from happening, or add a comment to keep it open another 90 days |
/unassign |
/close |
What this PR does / why we need it:
#21648
add kubectl set port command
Which issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close that issue when PR gets merged): fixes #Special notes for your reviewer:
Release note: