* client-go: Replace depracted ErrWaitTimeout with recommended method
* Fix UT and Integration tests
* IT test
Kubernetes-commit: ffe306d67958297202e9492ea644b42c0e7e694d
* 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
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
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