-
Notifications
You must be signed in to change notification settings - Fork 40.3k
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
Improvements to CLI usability and maintainability #34502
Changes from all commits
8438089
6d6aeb0
6f66c0e
f6d1ac7
4d641c4
3f7579c
0fd5c8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Copyright 2016 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"k8s.io/kubernetes/pkg/kubectl/cmd" | ||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" | ||
cmdsanity "k8s.io/kubernetes/pkg/kubectl/cmd/util/sanity" | ||
) | ||
|
||
var ( | ||
skip = []string{} | ||
) | ||
|
||
func main() { | ||
errors := []error{} | ||
|
||
kubectl := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, ioutil.Discard, ioutil.Discard) | ||
result := cmdsanity.CheckCmdTree(kubectl, cmdsanity.AllCmdChecks, []string{}) | ||
errors = append(errors, result...) | ||
|
||
if len(errors) > 0 { | ||
for i, err := range errors { | ||
fmt.Fprintf(os.Stderr, "%d. %s\n\n", i+1, err) | ||
} | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Fprintln(os.Stdout, "Congrats, CLI looks good!") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2016 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. | ||
source "${KUBE_ROOT}/hack/lib/init.sh" | ||
|
||
kube::golang::setup_env | ||
|
||
BINS=( | ||
cmd/clicheck | ||
) | ||
make -C "${KUBE_ROOT}" WHAT="${BINS[*]}" | ||
|
||
clicheck=$(kube::util::find-binary "clicheck") | ||
|
||
if ! output=`$clicheck 2>&1` | ||
then | ||
echo "FAILURE: CLI is not following one or more required conventions:" | ||
echo "$output" | ||
exit 1 | ||
else | ||
echo "SUCCESS: CLI is following all tested conventions." | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,11 +23,11 @@ import ( | |
"io" | ||
|
||
"github.com/golang/glog" | ||
"github.com/renstrom/dedent" | ||
"github.com/spf13/cobra" | ||
"k8s.io/kubernetes/pkg/api" | ||
"k8s.io/kubernetes/pkg/api/meta" | ||
"k8s.io/kubernetes/pkg/kubectl" | ||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates" | ||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" | ||
"k8s.io/kubernetes/pkg/kubectl/resource" | ||
"k8s.io/kubernetes/pkg/runtime" | ||
|
@@ -59,36 +59,36 @@ type AnnotateOptions struct { | |
} | ||
|
||
var ( | ||
annotate_long = dedent.Dedent(` | ||
annotate_long = templates.LongDesc(` | ||
Update the annotations on one or more resources. | ||
|
||
An annotation is a key/value pair that can hold larger (compared to a label), and possibly not human-readable, data. | ||
It is intended to store non-identifying auxiliary data, especially data manipulated by tools and system extensions. | ||
If --overwrite is true, then existing annotations can be overwritten, otherwise attempting to overwrite an annotation will result in an error. | ||
If --resource-version is specified, then updates will use this resource version, otherwise the existing resource-version will be used. | ||
* An annotation is a key/value pair that can hold larger (compared to a label), and possibly not human-readable, data. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's list items. Not strictly required, but if we don't use list items here we have to either give each one its own paragraph, or make it all part of a single paragraph (no line wrapping). Markdown unwraps single line breaks. |
||
* It is intended to store non-identifying auxiliary data, especially data manipulated by tools and system extensions. | ||
* If --overwrite is true, then existing annotations can be overwritten, otherwise attempting to overwrite an annotation will result in an error. | ||
* If --resource-version is specified, then updates will use this resource version, otherwise the existing resource-version will be used. | ||
|
||
`) + valid_resources | ||
` + valid_resources) | ||
|
||
annotate_example = dedent.Dedent(` | ||
# Update pod 'foo' with the annotation 'description' and the value 'my frontend'. | ||
# If the same annotation is set multiple times, only the last value will be applied | ||
kubectl annotate pods foo description='my frontend' | ||
annotate_example = templates.Examples(` | ||
# Update pod 'foo' with the annotation 'description' and the value 'my frontend'. | ||
# If the same annotation is set multiple times, only the last value will be applied | ||
kubectl annotate pods foo description='my frontend' | ||
|
||
# Update a pod identified by type and name in "pod.json" | ||
kubectl annotate -f pod.json description='my frontend' | ||
# Update a pod identified by type and name in "pod.json" | ||
kubectl annotate -f pod.json description='my frontend' | ||
|
||
# Update pod 'foo' with the annotation 'description' and the value 'my frontend running nginx', overwriting any existing value. | ||
kubectl annotate --overwrite pods foo description='my frontend running nginx' | ||
# Update pod 'foo' with the annotation 'description' and the value 'my frontend running nginx', overwriting any existing value. | ||
kubectl annotate --overwrite pods foo description='my frontend running nginx' | ||
|
||
# Update all pods in the namespace | ||
kubectl annotate pods --all description='my frontend running nginx' | ||
# Update all pods in the namespace | ||
kubectl annotate pods --all description='my frontend running nginx' | ||
|
||
# Update pod 'foo' only if the resource is unchanged from version 1. | ||
kubectl annotate pods foo description='my frontend running nginx' --resource-version=1 | ||
# Update pod 'foo' only if the resource is unchanged from version 1. | ||
kubectl annotate pods foo description='my frontend running nginx' --resource-version=1 | ||
|
||
# Update pod 'foo' by removing an annotation named 'description' if it exists. | ||
# Does not require the --overwrite flag. | ||
kubectl annotate pods foo description-`) | ||
# Update pod 'foo' by removing an annotation named 'description' if it exists. | ||
# Does not require the --overwrite flag. | ||
kubectl annotate pods foo description-`) | ||
) | ||
|
||
func NewCmdAnnotate(f cmdutil.Factory, out io.Writer) *cobra.Command { | ||
|
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.
whether we should add this check to normal verify process? like check this when commit.
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.
Yep, it does it already.
verify
runs everything that satisfieshack/verify-*.sh
, which includes this one.https://github.com/fabianofranz/kubernetes/blob/001e58e83a82f881b4a753f33d08908d885aaa2e/hack/make-rules/verify.sh#L90