Commit Graph

464 Commits

Author SHA1 Message Date
Kevin Delgado 61f42e595f add server-side validation support to kubectl
Kubernetes-commit: fe3772890f650f9bcf020b43dc5a51fab0fa17f4
2022-03-09 14:52:32 +00:00
Arda Güçlü 11acf004c8 Remove deprecated discovery/ServerResources function
ServerResources function was deprecated and instead ServerGroupsAndResources
function is suggested.

This PR removes ServerResources function and move every place to use ServerGroupsAndResources.

Kubernetes-commit: ef39a8914291ba200bd5486c88a7575ffd4b7d1d
2021-12-22 11:14:09 +03:00
Ikko Ashimine be8cd595fc Fix typo in get_test.go
overide -> override

Kubernetes-commit: 10cdb0546aa7b89d8d6ab93d0826e4cda5c060eb
2021-12-13 22:56:22 +09:00
Maciej Szulik d2031a1eed Start deprecating long/golang version information
Kubernetes-commit: 43c09f6f9dc22771ac1b6b4459e4c2ce5d55c82a
2022-03-24 18:02:14 +01:00
Marc Khouzam cd5b039b42 Refactor completion code into its own package
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

Kubernetes-commit: c4f8c57b43843abd13bae677b73c622e1c30b46f
2022-03-24 09:06:05 -04:00
Marc Khouzam cd245d2e22 Support completion for the <type>/<name> form
This commit teaches the shell completion logic how to handle the
<type>/<name> form for resource specification.

It also teaches the 'exec' command how to complete its '--container/-c'
flag using container names.

Also, for commands that work on pods, kubectl will now also suggest
completion choices of the form <type>/<name> for resource types that
contain pods (see below for more details).

The following commands can now have completion of the <type>/<name>
form. Commands that accept any resource type:

annotate
apply edit-last-applied
apply view-last-applied
delete
describe
edit
get
label
patch

Commands that accept a subset of resource types:

autoscale
expose
rollout history
rollout pause
rollout restart
rollout resume
rollout status
rollout undo
scale
taint

Commands that apply to resource types that contain pods:

attach
exec
logs
port-foward

For these last four commands, the possible resource types are now
included in the completion choices.  For example:
    kubectl exec d<TAB>
will suggest
    daemonsets/   deployments/

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

Kubernetes-commit: cf66f5c3cbd0a0e2f223af438ee4c6bc7e4a907c
2022-03-01 10:45:59 -05:00
Yuvaraj Kakaraparthi 38487e770c kubectl: add --support to get, patch, edit and replace commands
Co-authored-by: Nikhita Raghunath <nikitaraghunath@gmail.com>

Kubernetes-commit: a5aa858d44651ba48bdce634a39b55be91216614
2021-07-07 08:30:59 -07:00
Patrick Ohly 7c4cfc5d12 enhance and fix log calls
Some of these changes are cosmetic (repeatedly calling klog.V instead of
reusing the result), others address real issues:

- Logging a message only above a certain verbosity threshold without
  recording that verbosity level (if klog.V().Enabled() { klog.Info... }):
  this matters when using a logging backend which records the verbosity
  level.

- Passing a format string with parameters to a logging function that
  doesn't do string formatting.

All of these locations where found by the enhanced logcheck tool from
https://github.com/kubernetes/klog/pull/297.

In some cases it reports false positives, but those can be suppressed with
source code comments.

Kubernetes-commit: edffc700a43e610f641907290a5152ca593bad79
2022-02-16 12:17:47 +01:00
Chok Yip Lau 6a5a78c26b Beautify kubectl help flag commands
Kubernetes-commit: 1c031d4fa8450550fa9a6bd5abe7fac45816156e
2021-09-02 13:41:07 -04:00
Katrina Verey 5bb84013cd kubectl version should include bundled kustomize version
Kubernetes-commit: 44e63e8ff8e7f98c75dc86d8c41553a5cce6a603
2022-03-23 19:17:29 -04:00
brianpursley 131a58c252 Renamed create_authinfo.go, create_cluster.go, and create_context.go
to match their kubectl config subcommand names and reflect that they
are used for setting values, not just creating.

Deprecated NewCmdConfigSetAuthInfo in favor of NewCmdConfigSetCredentials.

Did some minor refactoring of one of the complete functions to eliminate
an unused argument and not wrap returned errors that do not add detail.

Kubernetes-commit: 48007fc32bb473d1d0d7d7c24b9daa2157e433d1
2022-02-06 21:31:13 -05:00
mozillazg 66c4b40dd6 kubectl: Remove deprecated flags
Remove the deprecated `--serviceaccount`, `--hostport`, `--requests` and `--limits` flags

Kubernetes-commit: 95f5d507f5b5a19d9b031bfa5eb46e72311f9896
2022-03-19 15:32:06 +08:00
Arda Güçlü 1474736be3 Remove DiscoveryClient from diff command
This PR removes `DiscoveryClient` field in diff command. Because
it is not used anywhere in diff command.

Kubernetes-commit: 5fdf97ad8e3a9b7a16479a5ec4ebff3d38c55a18
2022-03-08 09:59:49 +03:00
Monis Khan f315a5dd88 kubectl create token: use duration instead of expiration seconds
Expiration seconds is great for an unambiguous REST API.  It it not
a great input for a command line meant to be used by humans.

Signed-off-by: Monis Khan <mok@vmware.com>

Kubernetes-commit: 6b9d556c9dc1fca37349833d38f8921f436e1874
2022-03-18 16:11:13 -04:00
kkkkun b5be321e1a sort custom column print flags
Kubernetes-commit: 36ed148761cb5a30c21b45a64d95cabd1a9d07ff
2022-03-03 22:31:58 +08:00
Jefftree ef358291b5 googleapis/gnostic -> google/gnostic
Kubernetes-commit: 8a1d5947ad34ba275192341baa4e5fef8e6c7f24
2022-03-15 20:36:21 -07:00
Kevin Delgado 7e681490ec Generalize dry run verify to arbitrary query param
Kubernetes-commit: d6c83281bc696474a76365a879f2255b8b568786
2022-03-09 14:51:50 +00:00
Lee Verberne 3d7e4b3f7f Print kubectl debug messages received when starting a container (#108591)
* kubectl debug: print container messages

This provides feedback to the user, for example that the server is
unable to pull the debug container image.

* Label debug container updates as warnings

Co-authored-by: Eddie Zaneski <eddiezane@gmail.com>

Co-authored-by: Eddie Zaneski <eddiezane@gmail.com>

Kubernetes-commit: 90956e6d3e9df02d932f9954911b89a3fd1619fb
2022-03-10 02:41:45 +00:00
brianpursley 5cd0db54d5 Add unit tests for cluster, context, and user command line completion functions
Kubernetes-commit: 996f79738e6f6c7dc9723cffe2b0bddc267777c6
2022-02-12 11:23:35 -05:00
W. Trevor King 5ff8356c5b kubectl drain: Generic "declare a controller" message
When it initially landed in kubernetes/kubernetes@c6e9ad066e (Initial
node drain implementation for #3885, 2015-08-30,
kubernetes/kubernetes#16698), the drain logic looked in a created-by
annotation for recognized kinds [1], so listing the set of recognized
kinds was a clear approach.

Sometime later, the source moved into ownerReferences, but the
hard-coded set of recognized controller kinds remained.

When kubernetes/kubernetes@2f1108451f (Remove hard-coded
pod-controller check, 2017-12-05, kubernetes/kubernetes#56864) removed
the hard-coded set of recognized controller kinds, it should have also
updated these messages to remove stale references to the previous
hard-coded values.  This commit catches the message strings up with
that commit.

[1]: c6e9ad066e (diff-211259b8a8ec42f105264c10897dad48029badb538684e60e43eaead68c3d219R216)

Kubernetes-commit: 587f4f04cc5fc18f4e85ed6a4a06bbf1bfee0496
2022-02-23 16:26:59 -08:00
jlsong01 4b64056435 kubectl version should fail when given extra arguments
Kubernetes-commit: 969cc463efcfacac728bac218534d0a027d448ee
2022-02-05 22:29:08 +08:00
czm 46b7c48533 fix defer in for loop, maybe resource leak
Kubernetes-commit: 684c5bf2a77f96b7db608e3c726a1d7da1a68421
2022-02-20 11:39:11 +08:00
Wojciech Tyczyński 3f11f31017 Stop setting selfLink in kubectl
Kubernetes-commit: 9015f27e6d8295d7dcdbf5915024f28cc00d4d2f
2022-02-16 17:13:54 +01:00
jlsong01 a64711ac83 add warning when kubectl set env from secret leads to uppercase
Kubernetes-commit: feb84ccef4a69fc1710003c71bc496b94448f094
2022-02-08 19:10:12 +08:00
Sebastian Sterk 31436b2c03 simple grammar fix
Kubernetes-commit: 5e286470fa16c4d53aa24b76a4fe94edf7b7016c
2022-02-02 00:02:11 +01:00
David Hotham 675d0d2328 Completions for kubectl config delete-user
Kubernetes-commit: 62eb74880cc3a97b04d1ea7fab62a207433a0f77
2021-12-20 14:40:56 +00:00
Eddie Zaneski d76986fd7a Change level for klog.Fatal
Signed-off-by: Eddie Zaneski <eddiezane@gmail.com>

Kubernetes-commit: cd71d3f7881f0c66dbd28aec7af7a0ea0e2acf60
2022-02-10 14:43:19 -07:00
Jordan Liggitt 344e97b543 Add command to request a bound service account token
Kubernetes-commit: fca9b1d9fcc7288ecb93c969ff9907a5def2dc9e
2022-01-31 11:46:50 -05:00
Arda Güçlü 119abb31f8 Add manually invalidate cache documentation into delete
When CRDs are deleted, discovery local cache is not invalidated.
This brings about `resource not found` error when new CRD with same name is created
with different fields(ie. changing scope from cluster-wide to namespaced).
Because this already deleted CRD still stays in serverresources.json and kubectl tries to use it.

This local cached files have 10 minutes TTL. After deletion, if user waits 10 minutes,
files will be expired and deleted and there will be no errors. However, 10 minutes is a long time
and cache needs to be invalidated after deletion occurs.

This PR adds a document into delete command by noting that there might be a need to invalidate discovery
cache when CRD is deleted. In addition to that this PR adds a test to catch this behavior.

Kubernetes-commit: 43d8b3459baec794c8a3a858c04f1562a09886a3
2021-12-21 11:53:09 +03:00
Aram Peres 8e80d8fd7e Cleanup kubectl label selectors with 'cmdutil.AddLabelSelectorFlagVar'
Kubernetes-commit: 8f8138bc35f59ef04b77a3520d8d1065603ccdb7
2022-01-06 23:28:44 -05:00
ncapps 9f0231784c Update label selector message to clarify that constraints use AND operator
Kubernetes-commit: 62baa0af4c995cdf401339bfb92d6ae172fe5c6d
2022-01-07 17:25:17 +00:00
astraw99 7f5c2f206a fix label msg
Kubernetes-commit: 83fe357f3e45423662f461f7cfd66bb18c122d33
2022-01-20 10:56:46 +08:00
brianpursley 24505ed13a Upgrade Cobra from 1.2.1 to 1.3.0 to fix a bug where bash completions don't work when the kubectl command uses the --context flag to specify a context that contains a colon
Kubernetes-commit: 64fac6cf49839ba058345dc471f038e5008a05f1
2022-01-12 10:37:13 -05:00
Philip Hamer b11bd1ffd7 add test case for issue 106277 (PR 106268) (#106532)
* add test case for issue 106277 - fix edit of non-registered custom API types

* remove unneeded struct, as suggested

Kubernetes-commit: ea2dff12e6df93ac27684707ea48f7781eb669b5
2022-01-12 01:49:19 +00:00
Kebe d100fd0cee Add completion for
Kubernetes-commit: a57e6c892448f0ef21d7af551170773b57e8b397
2021-11-30 18:20:05 +08:00
Tobias Klauser 7b07391a3a kubectl: remove unnecessary fmt.Sprintf
Directly use the %#v verb in fmt.Fprintf instead.

Kubernetes-commit: 169f1845fc29a9002645e0a4df9489fee1ae7128
2021-11-04 13:45:47 +01:00
Jian Li 3f7abd9859 cmd/kubectl: make 'kubectl logs' default to the first container when default container cannot be determined or found by annotations (#105964)
* cmd/kubectl: make 'kubectl logs' default to the first container.

While running 'kubectl logs <pod>', If '-c' is omited and the pod has more than one container, and no default container can be determined from annotations, this command shows an error message and exits. With this fix, it defaults to the first container in such scenarios and show its logs. This aligns behavior with what 'kubectl exec' does currently, and is more in line with KEP SIG-CLI 2227 design.

* fix unit test(forgotten)

* fix spelling typo

Kubernetes-commit: 0977a5d7cda59d5bd324bf2730846905e072fbbf
2022-01-07 09:40:41 +08:00
Aram Peres 22a27cb97d Add label selector in 'kubectl rollout' commands
Kubernetes-commit: 5a5ac86a80464019e3e85d57306156839511d397
2022-01-06 16:53:29 -05:00
W. Trevor King cdcb6ed356 kubectl: Document --for's Unicode case-folding condition-value comparison
When the wait command was added in 76794643c5 (add wait, 2018-05-18, #64034),
this comparison was via ToLower.  It moved to use Unicode case folding
[1,2] in f4940cf55f (Staticcheck:
vendor/k8s.io/kubectl/pkg/scale|describe/versioned|cmd/top|cmd/util/editor|cmd/top,
2020-01-21, #87403).

[1]: https://pkg.go.dev/strings#EqualFold
[2]: http://www.unicode.org/reports/tr30/tr30-1.html

Kubernetes-commit: f69d52338b21da938021af37f49f49a83016534d
2021-08-30 19:41:08 -07:00
Paul Barfuss 0208a3ee09 Replace hardcoded kubectl with kubectl.Name()
Kubernetes-commit: 77be26c3b83dd28be450c8790ecee823750f9a8c
2021-12-10 15:58:52 -05:00
Paul Barfuss 9b4102b899 kubectl: fix hard-coded value in zsh completion
Kubernetes-commit: 339c361ca0156cbf2be5aa64f52a0afd332f5708
2021-12-07 15:13:39 -05:00
Ricardo Katz 36401bb108 fix nil pointer in create secret commands
Kubernetes-commit: 50015c2da621ecaee581f64f737aa2e527905f14
2021-12-25 21:24:21 -03:00
Jonny Langefeld a8accff4dc Fix default config flags
This is a follow up to #105520 which only changed the new default config flags in the `NewKubectlCommand` function if `kubeConfigFlags == nil`. However they are not nil because they were initialized before here:
2fe968deb6/staging/src/k8s.io/kubectl/pkg/cmd/cmd.go (L97)

This fix uses the same defaults for both functions

Signed-off-by: Jonny Langefeld <jonny.langefeld@gmail.com>

Kubernetes-commit: c4fbd35cf4bdc76b86dd74e468b69328f5aa20f9
2021-12-19 19:59:46 -08:00
Ross Peoples 88ea823a7a Allow create.specialVerbs to be customized
Kubernetes-commit: 9b2f24aee0668ef54e7f51acc79e51b93f1aedb3
2021-12-16 13:08:28 -06:00
Arda Güçlü f6fcb7d932 Enable setting proxyurl in kubeconfig via kubectl config (#105566)
* Enable setting proxyurl in kubeconfig via kubectl config

This PR enables setting `proxy-url` in kubeconfig via kubectl config.

* Add godoc for proxy-url unit tests

Kubernetes-commit: afdde383210294c3da573decc44b5ce55cffcb94
2021-12-20 21:54:05 +00:00
Ross Peoples 866baec66e Allow custom img resolver and flags for set image
Kubernetes-commit: 2f56584853355c0ab16e5ad2b0195d8dfcd7dc6b
2021-12-16 14:06:46 -06:00
sunzhaochang 16d7d99cc5 Add Close() for profile
Kubernetes-commit: 82c9d80295451dad4b9a5af89f34bb56b3a9904b
2021-12-15 21:03:34 +08:00
Julian V. Modesto 5c9b92b57c Re-introduce removed kubectl --dry-run values.
For 1.23, we removed the kubectl `--dry-run` empty default value (`--dry-run`)
and boolean values (`--dry-run=true` and `--dry-run=false`). This change
required requiring users to specify `--dry-run=client` or `--dry-run=server`
due to a deprecation. This change was made in #105327.

After reconsideration, this change is not worth the churn for users.
It's likely that many users rely on these values for automated and manual use
cases.

This change reverts #105327 and re-introduces the values `--dry-run`,
`--dry-run=true`, and `--dry-run=false`.

Kubernetes-commit: cc4998b2b131ca9906b847600bd5ad3be70eff3a
2021-12-13 15:04:49 -05:00
Arda Güçlü ab3928acd9 Refactor diff/prune
This PR does some refactors for diff/prune;

- GetRESTMappings takes value array instead reference
- Move getObjectName into diff instead prune
- License, etc. changes

Kubernetes-commit: 6c449dd272c95f2aeb3bb77e67d312d8df21bd62
2021-11-08 11:22:10 +03:00
Arda Güçlü 2d0f4303f1 Get object name correctly for pruned resources
Kubernetes-commit: a19bd5e47436c1f0a2aea20c4a992da18f8ba480
2021-10-06 17:01:19 +03:00