Commit graph

161 commits

Author SHA1 Message Date
Takehiro Ogura
7aefd5b71b Update po, mo files for kubectl Japanese translation (#131176)
* Update Japanese translation for kubectl

* Update test for kubectl help

* apply kubernetes translations rules https://kubernetes.io/ja/docs/contribute/localization/#basic-policy

* Update kubectl help test string

* rebuild kubectl mo file

* fix k8s specific terms to original one

Kubernetes-commit: 37be90f2959691c6d527ebb545675e66c1aac4c7
2026-04-23 05:48:41 +09:00
Nikhil
ad4e7654ea Remove deprecated PodRequestsAndLimits from kubectl/pkg/util/resource (#137442)
* Remove deprecated PodRequestsAndLimits from kubectl/pkg/util/resource

The PodRequestsAndLimits function was deprecated in favor of
k8s.io/component-helpers/resource.PodRequests and PodLimits,
which also support pod-level resources. There are no remaining
consumers in kubectl.

This removal includes the unexported helpers: podRequests,
podLimits, determineContainerReqs, max, addResourceList, and
maxResourceList.

* Remove test for deleted max helper function

Kubernetes-commit: e026a9482a167bec567f16f87efe9df4c09dbb06
2026-03-09 19:53:31 +05:30
Nikhil
3bc887ac93 kubectl describe: migrate to component-helpers resource package and add pod-level resources test (#137394)
* kubectl describe: migrate to component-helpers resource package and add pod-level resources test

Refactor describe.go to use k8s.io/component-helpers/resource package for pod resource
calculations. This migration enables proper support for pod-level resources feature.

Changes:
- Import resourcehelper from k8s.io/component-helpers/resource
- Replace PodRequestsAndLimits() with separate PodRequests() and PodLimits() calls

Add TestDescribeNodeWithPodLevelResources to verify describeNodeResource works correctly
when pods have pod-level resources (Spec.Resources) configured.

Signed-off-by: KunWuLuan <kunwuluan@gmail.com>

* address review feedback: verify computed values in test and deprecate PodRequestsAndLimits

---------

Signed-off-by: KunWuLuan <kunwuluan@gmail.com>
Co-authored-by: KunWuLuan <kunwuluan@gmail.com>

Kubernetes-commit: 63080a762b383dbac02c44b3755e15543132d44e
2026-03-05 17:14:32 +00:00
杨军10092085
a324deac7b Add --detach-keys for kubectl attach command
Kubernetes-commit: ee02a8ab32b2f25c034d76464b3909fd59a132b7
2025-10-31 14:57:46 +08:00
Stephen Kitt
2e358d6313 Deprecate obsolete slice utility functions
... and update users to use standard library functions.

Signed-off-by: Stephen Kitt <skitt@redhat.com>

Kubernetes-commit: d42d1e3d1f73ac2975b89f9482c2ecfaeeed13f6
2025-07-15 09:02:48 +02:00
Mads Jensen
07471296e7 Fixes under staging.
Kubernetes-commit: ae8838f58a5859c33f2443b7df8a4bc525fde95b
2026-02-06 22:44:34 +01:00
Tim Allclair
beafecea32 Use quantity.Sign() instead of quantity.Cmp(zeroQuantity)
Kubernetes-commit: e8b7c959c9bacabb14100f871ffe19a02a7a1528
2026-02-04 10:38:23 -08:00
Daniel Maizel
8ec1b93d42 fix: handle nil ResourceList in max() to prevent panic
Kubernetes-commit: 7d5b4710bda738ec34f5bff23e02e930f09a0687
2026-01-28 16:07:25 +02:00
Abhigyan Shekhar
29b2482d8e FIX: Deep copy MapType in CEL composition to prevent data race
This commit fixes a fatal crash (concurrent map read/write) in
NewCompositedCompilerFromTemplate by:

- Refactoring CEL EnvSet composition to eliminate cloning and symbol conflicts
- Adding NewCompositedCompilerForTypeChecking for typechecking
- Removing deprecated CompositionEnv type and functions
- Adding regression test for concurrency race condition
- Using mustExtend helper function for clearer intent

Kubernetes-commit: 7bc62e74ab39048b00194b8ef6ead09c2dfb5e98
2026-01-08 07:39:15 +05:30
Patrick Ohly
0b6b58f68a e2e: suppress or ignore init log output
klog calls during init are becoming a problem because now test/e2e/framework
depends in test/utils/ktesting which bumps up the default verbosity during init
to make test output more complete when there is no argument parsing.

For cadvisor, an upstream fix is
needed (https://github.com/google/cadvisor/pull/3778). For kubectl we can make
it silently accept the valid (!) LC_ALL=C.

Kubernetes-commit: d17aaf5e29f209ca71047078650e9dcd266e47a4
2025-12-10 16:00:33 +01:00
Patrick Ohly
2082ef9b6e build: remove deprecated '// +build' tag
This has been replaced by `//build:...` for a long time now.

Removal of the old build tag was automated with:

    for i in $(git grep -l '^// +build' | grep -v -e '^vendor/'); do if ! grep -q '^// Code generated' "$i"; then sed -i -e '/^\/\/ +build/d' "$i"; fi; done

Kubernetes-commit: ad79e479c2314d1de91e54bc5630c52027f12e21
2025-12-01 15:54:18 +01:00
Benjamin Elder
b27fef8d9e remove deadcode HashObject from k8s.io/kubectl/pkg/util
I can't find evidence that anything is using this anymore, if anyone does depend on this it is a tiny function that depends only on public symbols and they can just place a copy somewhere else.

Kubernetes-commit: 4e29dcdf7567cd79749b7ad35378538b1b523247
2025-08-26 15:07:10 -07:00
Benjamin Elder
495c59a507 mark remaining md5 usage TODO and exclude from lint
Kubernetes-commit: 797d3165191847b60dda3d8e6822e2854462a118
2025-08-13 16:57:37 -07:00
Marc Khouzam
aa186336f3 Fix linter
Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>

Kubernetes-commit: d194619979252d33c525e972cfaf0eea9dc64b43
2025-08-28 23:04:35 -07:00
Marc Khouzam
4dec168032 Fix completion of resource names
The output format is now used by the `Complete()` function, so it must
be set before invoking said function.

The commit also adds a unit tests for this scenario.

Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>

Kubernetes-commit: f3d278e75d1137f1c91dde7415bc577af3c3be82
2025-08-28 21:06:02 -07:00
Mikhail Mazurskiy
ce4d90902a Decouple term and remotecommand packages
This allows consumers of term to not pull in dependencies on
github.com/gorilla/websocket and github.com/moby/spdystream.

Kubernetes-commit: 640dabd58b04b72f646ed85947cb8b407b36dc08
2025-08-03 20:35:40 +10:00
Dharmit Shah
3cb662b4be JSON & YAML output for kubectl api-resources (#132604)
* Add JSON & YAML output support for kubectl api-resources

Create a separate `PrintFlags` struct within the apiresources.go file
that handles printing only for `kubetl api-resources` because existing
output formats, i.e., wide and name, are already implemented
independently from HumanReadableFlags and NamePrintFlags.

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Use separate printer type for all options

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Unit tests for JSON & YAML outputs

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Separate file for print types

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Move JSON-YAML tests to separate function

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Fix broken unit test

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Unifying JSON & YAML unit test functions

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Fix linter errors

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* PR feedback and linter again

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

---------

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

Kubernetes-commit: cb33accc8fc4d44e902da4926eee7b828c5e51ec
2025-07-24 15:35:50 +00:00
Patrick Ohly
da311e8e7e kubectl: avoid logging during init
LoadTranslations gets called during the init phase:

     0  0x0000000005926c56 in k8s.io/kubectl/pkg/util/i18n.LoadTranslations
        at ./staging/src/k8s.io/kubectl/pkg/util/i18n/i18n.go:146
     1  0x0000000005926727 in k8s.io/kubectl/pkg/util/i18n.init.func1
        at ./staging/src/k8s.io/kubectl/pkg/util/i18n/i18n.go:60
     2  0x000000000592780f in k8s.io/kubectl/pkg/util/i18n.lazyLoadTranslations.func1
        at ./staging/src/k8s.io/kubectl/pkg/util/i18n/i18n.go:191
     3  0x0000000001b876e8 in sync.(*Once).doSlow
        at /nvme/gopath/go-1.24.0/src/sync/once.go:78
     4  0x0000000001b8753e in sync.(*Once).Do
        at /nvme/gopath/go-1.24.0/src/sync/once.go:69
     5  0x0000000005927565 in k8s.io/kubectl/pkg/util/i18n.lazyLoadTranslations
        at ./staging/src/k8s.io/kubectl/pkg/util/i18n/i18n.go:187
     6  0x00000000059275cd in k8s.io/kubectl/pkg/util/i18n.T
        at ./staging/src/k8s.io/kubectl/pkg/util/i18n/i18n.go:201
     7  0x000000000599fb6d in k8s.io/kubectl/pkg/cmd/apiresources.init
        at <autogenerated>:1
     8  0x0000000001b41bf4 in runtime.doInit1
        at /nvme/gopath/go-1.24.0/src/runtime/proc.go:7350
     9  0x0000000001b6bf8a in runtime.doInit
        at /nvme/gopath/go-1.24.0/src/runtime/proc.go:7317
    10  0x0000000001b33910 in runtime.main
        at /nvme/gopath/go-1.24.0/src/runtime/proc.go:254
    11  0x0000000001b72881 in runtime.goexit
        at /nvme/gopath/go-1.24.0/src/runtime/asm_amd64.s:1700

During init, klog verbosity is either zero (making the log call redundant
because it doesn't print anything) or some other init function reconfigures
logging, in which case the output is potentially confusing because it is not
guaranteed that logging is reconfigured before the log call is invoked.

In other scenarios, flag parsing might switch from klog text format to
something else entirely, which then leads to a mixture of text and e.g. JSON
output. In general, code running during init should not log.

Kubernetes-commit: 0276769c2c85e14902f39760abce82512aa6b120
2025-06-24 11:07:47 +02:00
Tim Allclair
f38b1de6c2 Consider AllocatableResources when computing pod requests
Kubernetes-commit: c2927727107cc8123c2688ea571f464650df6b2b
2025-03-17 21:23:32 -07:00
Natasha Sarkar
ed22800c0c Move pod resize status to pod conditions
Kubernetes-commit: a15520fbeaf458e2fc0f2be6e1ae0f9572369495
2025-03-17 22:01:05 +00:00
vivzbansal
79fb20cb8b Resolved latest review comments
Kubernetes-commit: 5889da1bbc7a3e515bf6e3d5ca35d600020ff046
2024-12-17 07:56:13 +00:00
lixiv
be364695f5 Add tests for kubectl qos (#129388)
* Add tests for kubectl qos

* Update staging/src/k8s.io/kubectl/pkg/util/qos/qos_test.go

Co-authored-by: Arda Güçlü <aguclu@redhat.com>

---------

Co-authored-by: Arda Güçlü <aguclu@redhat.com>

Kubernetes-commit: 215d0b094b686ae0ad83a8f2d3078e5860a979ba
2024-12-30 09:06:10 +00:00
Patrick Ohly
348f12d905 remove import doc comments
The "// import <path>" comment has been superseded by Go modules.
We don't have to remove them, but doing so has some advantages:

- They are used inconsistently, which is confusing.
- We can then also remove the (currently broken) hack/update-vanity-imports.sh.
- Last but not least, it would be a first step towards avoiding the k8s.io domain.

This commit was generated with
   sed -i -e 's;^package \(.*\) // import.*;package \1;' $(git grep -l '^package.*// import' | grep -v 'vendor/')

Everything was included, except for
   package labels // import k8s.io/kubernetes/pkg/util/labels
because that package is marked as "read-only".

Kubernetes-commit: 8a908e0c0bd96a3455edf7e3b5f5af90564e65b0
2024-12-02 14:43:58 +01:00
Arda Güçlü
61dc2ecb38 Use generic Contains rather than deprecated ContainsString
Kubernetes-commit: 8312c3ec242faf30f3967e59465ca5a764a4ee85
2024-11-25 11:30:04 +03:00
Arda Güçlü
608a0553d7 Use generic sets rather than deprecated sets.String
Kubernetes-commit: c3f15fd707a092e6cb7d96b84b81ada1f118d759
2024-11-21 13:22:39 +03:00
ndixita
9a565d149e QOS changes for Pod Level resources
Kubernetes-commit: 26f11c458620751733250b35d1f60c9ed2a96e57
2024-10-30 01:24:36 +00:00
AxeZhan
4657409ea3 consider sidecar containers in maxContainerRestarts
Kubernetes-commit: 7533123eb5e7c6ecd59d00d236235581f7f1157b
2024-05-19 23:50:25 +08:00
Tim Allclair
af49e676b2 Stop using status.AllocatedResources to aggregate resources
Kubernetes-commit: 81df1958196e04f04d038e5ec9e2025989a30b29
2024-10-25 21:18:19 -07:00
Yihao Wang
9a6ad3e08e Fix typo in i18n usage examples
Kubernetes-commit: e9c30951051b66bb5050d0d5bf622d4ef7a4481c
2024-01-17 13:12:21 +13:00
Matthieu MOREL
36d3a02b4d fix: enable expected-actual rule from testifylint in module k8s.io/kubectl
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

Kubernetes-commit: 223ea3445c2ced92630732ca765dee56bccae8ed
2024-09-27 07:47:42 +02:00
Abhishek Kr Srivastav
36d480f43c Fix Go vet errors for master golang
Co-authored-by: Rajalakshmi-Girish <rajalakshmi.girish1@ibm.com>
Co-authored-by: Abhishek Kr Srivastav <Abhishek.kr.srivastav@ibm.com>

Kubernetes-commit: 95860cff1c418ea6f5494e4a6168e7acd1c390ec
2024-09-12 18:15:22 +05:30
babugeet
0b359223b4 Added logic to check portname in sidecar container (init)
Signed-off-by: "babugeet <abhinandhbg@gmail.com>"

Kubernetes-commit: 7a810c6bb6591c4d617b585144d8f54ebaaed334
2024-06-11 20:05:39 +05:30
TessaIO
b56ea4761e test: improve unit tests for container name autocompletion
Signed-off-by: TessaIO <ahmedgrati1999@gmail.com>

Kubernetes-commit: fe81d0d5ac32c59bce138291cfcdaf5422617b06
2024-05-16 21:40:50 +02:00
TessaIO
5f33246cf8 feat: add ports autocompletion for kubectl port-forward command
Signed-off-by: TessaIO <ahmedgrati1999@gmail.com>

Kubernetes-commit: a84e893afa2d4fdd1e42ee6047812ff46daa9296
2024-05-01 23:33:39 +02:00
rmiki
3e85d33843 [ja]fix typo in "kubectl config delete-context -h"
Kubernetes-commit: 6229729e86775febdb99b45d03be2b4026f00846
2024-03-13 01:21:01 +09:00
José Carlos Chávez
65a57a36aa chore: adds consistent vanity import to files and provides tooling for verifying and updating them. (#120642)
* chore: drops update vanity imports from script.

* chore: changes copyright year to 2024.

* chore: makes lint happy.

Kubernetes-commit: 6d6398ef9266abce3518a4c9a3d4e4d8feeffdc1
2024-02-08 15:58:16 +00:00
weilaaa
b84e274c59 use build-in max and min func to instead of k8s.io/utils/integer funcs
Kubernetes-commit: eb8f3f194fed16484162aebdaab69168e02f8cb4
2023-12-15 15:09:11 +08:00
yulng
4afdc439d1 remove PruneWhitelist, use prune-allowlist instead
Signed-off-by: yulng <wei.yang@daocloud.io>
Signed-off-by: Paco Xu <paco.xu@daocloud.io>

Kubernetes-commit: 06679402e75d001d54770c9ec67cacbf28794009
2023-07-05 11:38:20 +08:00
Sean Sullivan
348bd97228 OpenAPIResourcesGetter allows lazy-loading OpenAPI V2
Kubernetes-commit: 6614a29f470f802915d1467f5050dbca1f8bc562
2023-03-13 20:28:40 -07:00
Vinay Kulkarni
3eb40ffbb0 Update pkg/apis/core/helper/qos/qos.go
Co-authored-by: Itamar Holder <77444623+iholder101@users.noreply.github.com>

Kubernetes-commit: 40b604e374144351eac463e7077fdb1903f5a033
2023-08-07 10:52:26 -07:00
vinay kulkarni
cacd4f8556 Code review fix: Move GetPodQOS code to ComputePodQOS. If set, return PodStatus.QOSClass from GetPodQOS.
Kubernetes-commit: 4063ca40501ce589b4de1ffa5cc814cd9e03e0ac
2023-08-07 14:42:36 +00:00
vinay kulkarni
35d73b6cda Perf optimization: Move away from GetPodQOS, using PodStatus.QOSClass instead
Kubernetes-commit: 5d4410b9601f27942fa1d1a4e65c2aa3a65637b1
2023-07-29 13:30:09 +00:00
Arda Güçlü
507fbad069 Add shortname ambiguity warning in shortcut expander (#117668)
* Add warning handler callback function in shortcut expander

Currently, errors in client-go are propagated back to the callers via
function returns. However, there is no elegant way for just warning users.
For example, when user wants to get a resource with it's short name format
and if there are multiple resources belonging to this short name, we need to
warn user about this ambugity which one is picked and which ones are discarded.

Not only to overcome this particular case mentioned above, but also propose a
way for the possible warnings in the future, this commit adds a warningHandler
callback function in shortcutExpander.

* Add warningPrinter functionality in ConfigFlags

ConfigFlags has neither warning user in a standardized
format functionality nor passing warning callback functions to other upper level
libraries such as client-go.

This commit adds an ability that user can set warningPrinters
according to their IOStreams and this warningPrinters will be used
to raise possible warnings happening not only in cli-runtime but
also in client-go.

* Pass warning callback function in ConfigFlags to shortcutExpander

This commit passes warning callback function to print possible
warnings happened in shortcut expander to warn user in a
standardized format.

* Add integration test for CRDs having ambiguous short names

This commit adds integration test to assure that warning message
related to this ambiguity is printed when resources are being retrieved via their short name
representations in cases where multiple resources have same
short names.

This integration test also ensures that the logic behind which resource
will be selected hasn't been changed which may cause disperancies in
clusters.

* Remove defaultConfigFlag global variable

* Move default config flags initialization into function

* Skip warning for versions of same group/resource

* Run update-vendor

* Warn only once when there are multiple versions registered for ambiguous resource

* Apply gocritic review

* Add multi-resource multi-version ambiguity unit test

Kubernetes-commit: a504aed54d028dbc8ea2508142c94d309f5f1ec6
2023-10-11 19:58:38 +00:00
Todd Neal
f5a7ea080f kubectl: fix describe node output when sidecars are present
Update the resource calculation so that it accumulates the resources
from scheduled pods correctly when those pods contain restartable
init containers.

Kubernetes-commit: 479b2d03a4369b8ae4565ba73850c703331cdcc5
2023-07-21 09:02:11 -05:00
Brian Pursley
70109f0921 Prefer pods without a deletion timestamp over pods with a deletion timestamp when getting an ordered list of active pods.
This allows commands like kubectl port-forward, when used with deployments, to avoid selecting a pod that is terminating (due to a rollout, for example).

Kubernetes-commit: d281daee335dc3b2aa67fb3128f00d7d2f5f7d91
2023-07-18 08:31:37 -04:00
Mauren Berti
03a51b01e7 Update the template.pot file with latest message IDs.
Update the template.pot file with the current state of the messages in kubectl. That allows localized messages to be updated accordingly and picked up correctly.

Kubernetes-commit: dfce076c6cf0ad8f7a896a87c07143c63e2d67bd
2023-06-27 12:10:46 -04:00
Devesh Goyal
03e1b53324 Update k8s.po
Fixed typo mistake

Kubernetes-commit: 0789bbe9f7acdaf0f2c203aef1da292358842f09
2023-05-21 19:33:33 +05:30
Jefftree
6d49571c40 Update gnostic references
Kubernetes-commit: 2111e79f56acdfa6a8dab56780c52e3abc608758
2023-06-01 18:25:39 +00:00
LronDC
22b4cf895f Optimize usage message of commands which have subcommands.
Signed-off-by: LronDC <lun.su@daocloud.io>

Kubernetes-commit: 15678e4a67e1b725368ca1bd3a97b670c5d97776
2023-05-10 18:10:28 +08:00
Stephen Kitt
cfd2169f88 cli: replace intstr.FromInt with intstr.FromInt32
This touches cases where FromInt() is used on numeric constants, or
values which are already int32s, or int variables which are defined
close by and can be changed to int32s with little impact.

Signed-off-by: Stephen Kitt <skitt@redhat.com>

Kubernetes-commit: 45836971f27ca70cd7742e8ee66e99e3c648cf9f
2023-03-14 16:17:48 +01:00