Commit graph

1504 commits

Author SHA1 Message Date
Ricardo Pchevuzinske Katz
5687721b88 Return error in case of discovery client failure
Kubernetes-commit: 011338f9efc17372f8f99abe3b2b047e7e58ac49
2025-10-23 19:28:18 -03:00
Marc Khouzam
a09bf63d3f Fix linter
Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>

Kubernetes-commit: 2631a5f21eacd4f7a02eb14ad9d950bd54ab78ed
2025-08-28 23:04:35 -07:00
Marc Khouzam
8e374f9ecd 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: 94c0e478827bdcd5fea7bb42853430cf0c364bae
2025-08-28 21:06:02 -07:00
Tim Hockin
02042ef887 Add KYAML support to kubectl
KYAML is a strict subset of YAML, which is sort of halfway between YAML
and JSON.  It has the following properties:
* Does not depend on whitespace (easier to text-patch and template).
* Always quotes value strings (no ambiguity aroud things like "no").
* Allows quoted keys, but does not require them, and only quotes them if
  they are not obviously safe (e.g. "no" would always be quoted).
* Always uses {} for structs and maps (no more obscure errors about
  mapping values).
* Always uses [] for lists (no more trying to figure out if a dash
  changes the meaning).
* When printing, it includes a header which makes it clear this is YAML
  and not ill-formed JSON.
* Allows trailing commas
* Allows comments,
* Tries to economize on vertical space by "cuddling" some kinds of
  brackets together.
* Retains comments.

Examples:

A struct:

```yaml
metadata: {
  creationTimestamp: "2024-12-11T00:10:11Z",
  labels: {
    app: "hostnames",
  },
  name: "hostnames",
  namespace: "default",
  resourceVersion: "15231643",
  uid: "f64dbcba-9c58-40b0-bbe7-70495efb5202",
}
```

A list of primitves:

```yaml
ipFamilies: [
  "IPv4",
  "IPv6",
]
```

A list of structs:

```yaml
ports: [{
  port: 80,
  protocol: "TCP",
  targetPort: 80,
}, {
  port: 443,
  protocol: "TCP",
  targetPort: 443,
}]
```

A multi-document stream:

```yaml
---
{
  foo: "bar",
}
---
{
  qux: "zrb",
}
```

Kubernetes-commit: 2cb955d8ccae30167b9610bfe51c2f86e83a1958
2025-07-14 09:24:18 -07:00
carlory
cf54a4ea54 Promoted API VolumeAttributesClass and VolumeAttributesClassList to storage.k8s.io/v1.
Promoted feature-gate `VolumeAttributesClass` to GA (on by default)

Signed-off-by: carlory <baofa.fan@daocloud.io>

Kubernetes-commit: 94bf8fc8a9d1d6c989eddad07996be0ca4dd3448
2025-04-30 17:35:21 +08:00
koba1t
fb7d414ec2 Update kubectl kustomize to kyaml/v0.20.1, cmd/config/v0.20.1, api/v0.20.1, kustomize/v5.7.1
Kubernetes-commit: ee8ef383bec15dd63c5d22ffe6a6e0703fc1ba4a
2025-07-23 22:30:05 +09:00
Mayuka Channankaiah
98b4b33964 client-go, kubectl: Replace deprecated ErrWaitTimeout with recommended method (#132718)
* client-go: Replace depracted ErrWaitTimeout with recommended method

* Fix UT and Integration tests

* IT test

Kubernetes-commit: ffe306d67958297202e9492ea644b42c0e7e694d
2025-07-24 19:32:01 +00: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
arush sharma
8067f3a1a6 kubectl: add port names to describe pod output
Kubernetes-commit: 1d0fd5928818036289a76358503778eff26e53ef
2025-07-16 22:47:06 -07:00
Davanum Srinivas
f47e5c84cc Bump k8s.io/kube-openapi to latest SHA (f3f2b991d03b)
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: ebc1ccc491c944fa0633f147698e0dc02675051d
2025-07-10 09:21:52 -04:00
Gemma Hou
76e6818d8d Improve ignore-not-found behavior (#132542)
* Improve ignore-not-found behavior

* ignore lint errcheck

Kubernetes-commit: a7e8a505c25965c074f2b10b1bf40230eca48a08
2025-07-03 01:53:24 +00:00
Ondra Kupka
edad3048e9 kubectl: Cache Verifier.HasSupport calls
The underlying implementation decodes OpenAPI schema on every HasSupport
call. This causes these calls to be expensive and noticable when many
resources are being applied.

This patch wraps the verifier with a thread-safe cache so that when many
resources of the same kind are being checked, only the first call
includes schema decoding.

This solution is specifically limited to the kubectl codebase without
any changes required in client-go, for now, although that is where the
issue is actually originating.

Kubernetes-commit: 9043afae6d98585dd14d203d48807b14b433d730
2025-05-23 21:58:05 +02:00
Kurnia D Win
4b5ec542ad feat: kubectl debug: add label for debugger pod
Kubernetes-commit: e9fcdabcf5072de662d9c02f83df5f0ac80c2a43
2025-05-15 17:32:06 +07:00
Janet Kuo
daa78b3004 Enhance help text for the 'top' command
* Detailing the metrics source
* Connecting to HPA
* Defining its scope

Kubernetes-commit: e54e01e0abbff795a5628f2e845c815e6d43c03f
2025-06-26 16:53:50 -07:00
Aleksey Gavrilov
6323c5bc57 [kubectl] drain daemonSetFilter with other APIVersion
Signed-off-by: Aleksey Gavrilov <alexey.gavrilov@flant.com>

Kubernetes-commit: a52863827bafa64a678c1291f066d2c8b85217af
2024-11-13 10:23:54 +03:00
googs1025
e33a30ea7c feature(kubectl): support mem-percent,cpu-value,cpu-average-value,mem-value,mem-average-value flag to kubectl autoscale
Signed-off-by: googs1025 <googs1025@gmail.com>

Kubernetes-commit: 6795d5366f11b7bc782223beaa4f81bef04f751c
2024-12-24 10:01:25 +08:00
Davanum Srinivas
7e06b5277c switch to latest sigs.k8s.io/yaml v1.5.0 (run update-gofmt.sh as well)
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: c5b4b133ce3252ee19b7167eb69a99d88fdefda8
2025-06-25 08:03:06 -04:00
Davanum Srinivas
a6fde79de4 Drop usage of forked copies of goyaml.v2 and goyaml.v3
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 3827d3bc4f1c17ac816b37422dbd449c276e9ff0
2025-06-17 11:00:27 -04: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
totegamma
2fa4a24584 show namespace on delete (#126619)
* show namespace on delete

* update kubectl delete message

* add test 'TestDeleteMessageOutput'

* update delete_test.go

Kubernetes-commit: 75862f3f461b8c83f3cbbf441ce4fd5357d3bba0
2025-06-24 02:15:09 +00:00
Arda Güçlü
8a11631ed9 kubectl delete: Update interactive delete to break on new line
Kubernetes-commit: fb611f4c93e6d8d8eb920f4436af748432402f50
2025-06-12 11:27:51 +03:00
Harald Nordgren
ab62ac8cf1 Revert "improve display format"
This reverts commit 28e7acf0f93f5c9edb43ab09cd181e8847409215.

Kubernetes-commit: f8b701243503fc10a037f86e77ce4df5741a07c6
2025-06-10 16:56:58 +02:00
Harald Nordgren
65d852d39c improve display format
Kubernetes-commit: 28e7acf0f93f5c9edb43ab09cd181e8847409215
2025-04-27 20:35:38 +02:00
Harald Nordgren
7ec7bb7cc1 kubectl: sort configmaps alphabetically to avoid random order
Kubernetes-commit: f30c23a7831a25266a56b9b2990fa1ca19b48ad5
2025-04-27 15:36:09 +02:00
Itamar Holder
0b4adb247f [KEP-2400] kubectl top: add a --show-swap option (#129458)
* top, refactor: turn package-exposed variables to unexpose struct fields

Signed-off-by: Itamar Holder <iholder@redhat.com>

* kubectl top node: add the --show-swap option

Example output:
> kubectl top node --show-swap
NAME     CPU(cores)   CPU(%)   MEMORY(bytes)   MEMORY(%)   SWAP(bytes)   SWAP(%)
node01   500m         8%       2836Mi          60%         0Mi           0%
node02   260m         5%       2206Mi          47%         512Mi         50%

Signed-off-by: Itamar Holder <iholder@redhat.com>

* kubectl top pod: add the --show-swap option

Example output:
> kubectl top pod -n kube-system --show-swap
NAME                                      CPU(cores)   MEMORY(bytes)   SWAP(bytes)
coredns-58d5bc5cdb-5nbk4                  2m           19Mi            0Mi
coredns-58d5bc5cdb-jsh26                  3m           37Mi            0Mi
etcd-node01                               51m          143Mi           0Mi
kube-apiserver-node01                     98m          824Mi           0Mi
kube-controller-manager-node01            20m          135Mi           0Mi
kube-proxy-ffgs2                          1m           24Mi            0Mi
kube-proxy-fhvwx                          1m           39Mi            0Mi
kube-scheduler-node01                     13m          69Mi            0Mi
metrics-server-8598789fdb-d2kcj           5m           26Mi            0Mi

Signed-off-by: Itamar Holder <iholder@redhat.com>

* kubectl top node --show-swap: add unit tests

Signed-off-by: Itamar Holder <iholder@redhat.com>

* kubectl top pod --show-swap: Add unit tests

Signed-off-by: Itamar Holder <iholder@redhat.com>

* Explicitly mark swap as unavailable when necessary

Signed-off-by: Itamar Holder <iholder@redhat.com>

---------

Signed-off-by: Itamar Holder <iholder@redhat.com>

Kubernetes-commit: 8d3fb9ee0a51b6a6ea135d991391c35806422c19
2025-06-04 17:10:38 +03:00
Maciej Szulik
17c0dde6b1 kuberc: add tests for DefaultGetPreferences
Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: 68efb079aabd3295ff4ee5cc56c89ff266e9224d
2025-06-02 16:47:02 +02:00
Stephen Kitt
abe43f6e92 kubectl: drop dependency on github.com/pkg/errors
The package is unmaintained, and kubectl doesn't rely on the
functionality it provides on top of Golang errors (stack traces).

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

Kubernetes-commit: 54b2fad0330032ae1bbac990f93a3644aa8a12af
2025-05-26 10:44:46 +02:00
Kazuki Suda
bb9c5182ea Revert shorthand for kubectl explain --output
Kubernetes-commit: df2857e7777f18c482359cfb43a72a3cdfd89646
2025-05-26 12:16:24 +09:00
Maciej Szulik
46d6f63709 kuberc: make update and update-vendor
Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: 76f95271a5d563ea31edbcd8f0e8eebf67cb3634
2025-05-15 14:15:20 +02:00
Maciej Szulik
8500d2979d kuberc: introduce fuzzing for kuberc types
Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: c29accaf5819bd4b05409cecb9bbb3ba065d840b
2025-05-16 13:45:37 +02:00
Arda Güçlü
ca5a831a47 Promote kuberc to beta
Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: b0370c483af1bdbc1e2664f53445411c585c4559
2025-05-06 12:52:20 +03:00
Maciej Szulik
b011cffff8 kuberc: pick the first known version when decoding + tests
Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: 1f355e5b44141be55da269a9183d53bbccd16c95
2025-05-15 16:24:43 +02:00
Maciej Szulik
cb7efba696 kuberc: align internal and v1alpha1 go-types with v1beta1
Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: 0341b27c5d0dfb1d10818c9976f54af22971bedc
2025-05-21 13:32:37 +02:00
Maciej Szulik
2be4847754 kuberc: add v1beta1 types
Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: 39195f9a463cce6b3ce4e3d9f648c2915407596d
2025-05-15 14:14:59 +02:00
Maciej Szulik
47f13bd18b Deprecate kubeconfig's preference field in favor of kuberc
Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: 8cf5e8db78deb186ef362f64ab779c09e9520156
2025-05-13 13:39:13 +02:00
Omer Aplatony
5ff92a69e3 Kubectl: check version skew (#127365)
Signed-off-by: Omer Aplatony <omerap12@gmail.com>

Kubernetes-commit: 35307319740a3a52cf4632c24b7f99d675537bdf
2025-05-19 20:19:14 +03:00
Maciej Szulik
52ec1da081 Add comment describing the feature gate with a link to KEP
Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: 9e3a1b0a9081ab49bbc44c415525dce862eb6a12
2025-05-08 14:43:24 +02:00
Maciej Szulik
307936eb9d Swap KUBECTL_COMMAND_HEADERS to use the proper feature gate mechanism
Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: e3f3da5e795960508089aed08fe7fd9bec0a6db2
2025-05-08 14:09:17 +02:00
Maciej Szulik
90ee929b88 Drop KUBECTL_ENABLE_CMD_SHADOW featgure gat entirely
https://kep.k8s.io/3638 has been promoted to stable back in 1.32 so now
is the right time to drop this feature gate entirely.

Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: d1b5f268b48eda4bb8acdeef52407c27add9e076
2025-05-08 14:05:19 +02:00
Maciej Szulik
d35aa2c630 Manually read verbosity before kubectl command construction
kubectl command construction is slowly getting more functionality which
sometimes requires to log certain actions. Currently we parse the
verbosity only when actually running the command, so all of construction
code is not able to use -v=5. This commit adds the manual parsing and
loglevel setting berore we even start creating the kubectl command.

Signed-off-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: 69682b75e508462e01f865a156f2171233b653d1
2025-05-08 13:29:11 +02:00
Arda Güçlü
5bcd2add11 Drop KUBECTL_DEBUG_CUSTOM_PROFILE feature gate entirely
Kubernetes-commit: 94d043b149b845a4f02f12a3d318df278194d377
2025-05-06 13:00:14 +03:00
Arda Güçlü
b0f5f0c0aa Continue alias creation when __completion is used to enable completion
Kubernetes-commit: f6d0498017fc71c72891ad9455c4391aa63c6e71
2025-05-02 13:23:22 +03:00
Jordan Liggitt
722397942b Drop null creationTimestamp from test fixtures
Kubernetes-commit: 6bb6c9934294d8265197c9dfc4c9dd3adaca147a
2025-03-24 09:37:26 -04:00
Ondra Kupka
4627533853 kubectl describe service: Add Traffic Distribution
Kubernetes-commit: ad40bc88568bdb19fdba0b960755bd014b2ae5e5
2025-04-26 18:02:19 +02:00
Rodrey
ae92d5f0bd Add more test cases to TestDescribeSecret test (#131422)
* Converted to parameterised tests.

* Added test case for sorting with casing.

* Formatted code.

* Added test case for keys that contain numbers.

Kubernetes-commit: 74e84dbf5a339a3830ddd172fe8767ca0952cbb8
2025-04-24 20:10:05 +00:00
Arda Güçlü
399c585899 Increase kubectl cp command timeout to 30 seconds
Kubernetes-commit: 9c228e81d2481150878ca3a431f0ec9a8f150b3f
2025-03-28 12:39:01 +03:00
Arthur Diniz
5b96de1a99 Set LANGUAGE env variable in TestDiffProgram for consistent locale behavior
Signed-off-by: Arthur Diniz <arthurbdiniz@gmail.com>

Kubernetes-commit: bad6c7e4cc5aef010c2fe2abfcbe51a138a04700
2025-03-21 17:28:41 +00:00
Taha Farahani
46f95a7c68 Unhandled panic crash on rollout_history printer.PrintObj (#130503)
* Change: Handling nil runtime.Object

Signed-off-by: Taha Farahani <tahacodes@proton.me>

* Change: Return only if there is error in rollout_history

Signed-off-by: Taha Farahani <tahacodes@proton.me>

* Change: Return the unknown revision error directly in rollout_history.go

Signed-off-by: Taha Farahani <tahacodes@proton.me>

* Change: Remove unintended newline

Signed-off-by: Taha Farahani <tahacodes@proton.me>

* Change: Using go idiomatic way for checking if historyInfo[o.Revision] exists

Signed-off-by: Taha Farahani <tahacodes@proton.me>

* Change: Remove 'error:' from returned error message in rollout_history.go

Signed-off-by: Taha Farahani <tahacodes@proton.me>

* Change: Check for printer.PrintObj returned err

Signed-off-by: Taha Farahani <tahacodes@proton.me>

* Change: Add TestRolloutHistoryErrors test

Signed-off-by: Taha Farahani <tahacodes@proton.me>

* Change: Simple typo fix on Complete() function description

Signed-off-by: Taha Farahani <tahacodes@proton.me>

* Change: Checking for error on o.Complete in TestRolloutHistoryErrors

Signed-off-by: Taha Farahani <tahacodes@proton.me>

---------

Signed-off-by: Taha Farahani <tahacodes@proton.me>

Kubernetes-commit: 609e4a9ba044e64a6244e053d2b1b7c545a2d2ed
2025-04-24 00:01:14 +03:30
Harald Nordgren
6c0aa1995f pr fix
Kubernetes-commit: 4e3026fdb81667fd5a9fe928736b6e4d67b225e5
2025-04-14 15:59:45 +02:00
Harald Nordgren
3a69c59961 kubectl: sort secrets alphabetically to avoid random order
Kubernetes-commit: 7d6f86594fc0a7d09710c643de63b24cdcb98e65
2025-02-20 13:28:55 +01:00