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

Staticcheck: vendor/k8s.io/kubectl/pkg/cmd/set and .../edit #87405

Merged
merged 1 commit into from Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions hack/.staticcheck_failures
Expand Up @@ -91,9 +91,7 @@ vendor/k8s.io/client-go/restmapper
vendor/k8s.io/client-go/tools/leaderelection
vendor/k8s.io/client-go/transport
vendor/k8s.io/component-base/metrics
vendor/k8s.io/kubectl/pkg/cmd/edit
vendor/k8s.io/kubectl/pkg/cmd/get
vendor/k8s.io/kubectl/pkg/cmd/scale
vendor/k8s.io/kubectl/pkg/cmd/set
vendor/k8s.io/kubectl/pkg/cmd/testing
vendor/k8s.io/metrics/pkg/client/custom_metrics
4 changes: 1 addition & 3 deletions staging/src/k8s.io/kubectl/pkg/cmd/edit/edit.go
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package edit

import (
"fmt"

"github.com/spf13/cobra"

"k8s.io/cli-runtime/pkg/genericclioptions"
Expand Down Expand Up @@ -77,7 +75,7 @@ func NewCmdEdit(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra
DisableFlagsInUseLine: true,
Short: i18n.T("Edit a resource on the server"),
Long: editLong,
Example: fmt.Sprintf(editExample),
Example: editExample,
Run: func(cmd *cobra.Command, args []string) {
if err := o.Complete(f, args, cmd); err != nil {
cmdutil.CheckErr(err)
Expand Down
3 changes: 2 additions & 1 deletion staging/src/k8s.io/kubectl/pkg/cmd/set/helper.go
Expand Up @@ -54,6 +54,7 @@ func selectString(s, spec string) bool {
pos := 0
match := true
parts := strings.Split(spec, "*")
Loop:
for i, part := range parts {
if len(part) == 0 {
continue
Expand All @@ -69,7 +70,7 @@ func selectString(s, spec string) bool {
// last part does not exactly match remaining part of string
case i == (len(parts)-1) && len(s) != (len(part)+next):
match = false
break
break Loop
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed, this works just fine and is only needed when two or more loops is in effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no need to add a break in switch cases for go. I think the logic here is to skip the for loop once the match variable is set as false.

default:
pos = next
}
Expand Down
2 changes: 1 addition & 1 deletion staging/src/k8s.io/kubectl/pkg/cmd/set/set_env.go
Expand Up @@ -151,7 +151,7 @@ func NewCmdEnv(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Co
DisableFlagsInUseLine: true,
Short: "Update environment variables on a pod template",
Long: envLong,
Example: fmt.Sprintf(envExample),
Example: envExample,
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(o.Complete(f, cmd, args))
cmdutil.CheckErr(o.Validate())
Expand Down
3 changes: 3 additions & 0 deletions staging/src/k8s.io/kubectl/pkg/cmd/set/set_selector.go
Expand Up @@ -175,6 +175,9 @@ func (o *SetSelectorOptions) RunSelector() error {
r := o.ResourceFinder.Do()

return r.Visit(func(info *resource.Info, err error) error {
if 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.

This might change behaviour, since we'll break earlier can you double check that?

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. But I think precheck here makes sense. Similar logic at reconcile

// RunReconcile performs the execution
func (o *ReconcileOptions) RunReconcile() error {
return o.Visitor.Visit(func(info *resource.Info, err error) error {
if err != nil {
return err
}

return err
}
patch := &Patch{Info: info}

if len(o.resourceVersion) != 0 {
Expand Down
2 changes: 1 addition & 1 deletion staging/src/k8s.io/kubectl/pkg/cmd/set/set_subject_test.go
Expand Up @@ -411,7 +411,7 @@ func TestAddSubject(t *testing.T) {
}
for _, tt := range tests {
changed := false
got := []rbacv1.Subject{}
var got []rbacv1.Subject
if changed, got = addSubjects(tt.existing, tt.subjects); (changed != false) != tt.wantChange {
t.Errorf("%q. addSubjects() changed = %v, wantChange = %v", tt.Name, changed, tt.wantChange)
}
Expand Down