Commit Graph

162 Commits

Author SHA1 Message Date
Peter Engelbert
c529a209c2 Add client-go credential plugin to kuberc
Remove reference to internal types in kuberc types

* Remove unserialized types from public APIs

Also remove defaulting

* Don't do conversion gen for plugin policy types

Because the plugin policy types are explicitly allowed to be empty, they
should not affect conversion. The autogenerated conversion functions for
the `Preference` type will leave those fields empty.

* Remove defaulting tests

Comments and simplifications (h/t jordan liggitt)

Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>

Kubernetes-commit: fab280950dabfefabe6a8578b7a76372a9b21874
2025-10-24 16:06:33 -04:00
Nikita B
2ab8e3619f [client-go] [cli-runtime] [133916]: handle properly config override logic when override provides ClientKey, ClientCertificate: use values from overrides when one of the field (file or data) is present in inverrides
Signed-off-by: Nikita B <n2h9z4@gmail.com>

Kubernetes-commit: 6b908c192cc828abef39c35dcc4921281f950958
2025-09-08 07:01:44 +02:00
Nikita B
e703bc019f [client-go] [cli-runtime] [133916]: handle properly config override logic when override provides ClientKey, ClientCertificate
Signed-off-by: Nikita B <n2h9z4@gmail.com>

Kubernetes-commit: fc8907da38dc1a6af7d7b2c18d87c1dd35ca8c68
2025-09-06 14:05:59 +02:00
Ethan Pini
af0e2a11af kubectl: Fix current-context being written to wrong file
This is what happens when writing back a OIDC refresh token:

 - plugin/pkg/client/auth/oidc/oidc.go:282
   Calls `Persist` to save the new refresh token.

 - tools/clientcmd/config.go:372
   Calls `ModifyConfig` to save the config.

 - tools/clientcmd/config.go:167
   Calls `configAccess.GetLoadingPrecedence()` to get the files
   listed from the `KUBECONFIG` environment variable.

 - tools/clientcmd/loader.go:334
   If the `ConfigAccess` was a `ClientConfigLoadingRules`, it
   directly returns the `Precedence` slice from its `rules`
   field.

   THE PROBLEM:
     The slice can be modified by the caller, unintentionally
     changing the value of the `ClientConfigLoadingRules`'
     `Precedence` field.

 - tools/clientcmd/config.go:170
   Then proceeds to in-place sort the slice returned by the
   `ConfigAccess`. This is the same slice (by identity)
   as the `ClientConfigLoadingRules`' `Precedence` field,
   destroying its intended order.

 - tools/clientcmd/config.go:179
   Calls `configAccess.GetStartingConfig` to read the original
   config so it can be compared with the new config.

 - tools/clientcmd/loader.go:339
   Calls `NewNonInteractiveDeferredLoadingClientConfig` with
   itself as a parameter.

   CONSEQUENCE:
     At this point, its the `Precedence` has been
     unintentionally sorted. When it loads the
     config again, it gives precedence to whichever
     file comes first in ascending alphabetical order.

 - tools/clientcmd/config.go:192
   If the file returned by `GetStartingConfig` has a
   different `current-context` than the new config,
   it calls `writeCurrentContext` to update the first
   kubeconfig file in the `KUBECONFIG` environment
   variable.

 - tools/clientcmd/config.go:403
   Calls `configAccess.GetDefaultFilename` to find the
   destination kubeconfig file.

 - tools/clientcmd/loader.go:358
   Iterates through the kubeconfig files returned by
   `GetLoadingPreferences` to find the first file
   that exists.

   CONSEQUENCE:
     With the slice being sorted earlier, the files
     returned by this call of `GetLoadingPreferences`
     will be sorted alphabetically, rather than by
     their intended order.

Kubernetes-commit: ffa084f81129ea685b176a282921c4d54906c539
2025-04-14 15:19:04 -07:00
Šimon Lukašík
2d84553721 ci cleanup: make sure to remove test KUBECONFIGs
Calling os.Exit() skipped the

    `defer os.RemoveAll(tmp)`

above and thus dangling files & dirs would appear in their $TMPDIR.

Since go1.15 we can safely remove os.Exit() from TestMain() function.
As this exact issue was common enough so that go1.15 changed[1] the API of
TestMain to no longer require os.Exit to be called.

Reproducer:

    $ (cd staging/src/k8s.io/client-go; go test ./tools/clientcmd)
    $ ls -d /tmp/testkubeconfig*
    /tmp/testkubeconfig1015943687

[1]: https://go-review.googlesource.com/c/go/+/219639

Kubernetes-commit: 457df1cf9817e29381609fbf2d85854a6b6a52ac
2025-07-21 10:46:37 +02:00
Arthur Befumo
6980728f27 Fix AuthInfo godoc for Token / TokenFile precedence (#132659)
* Fix AuthInfo godoc for Token / TokenFile precedence

* nit

* update

Kubernetes-commit: 33cd2e1ba08bf6b936c0c2c29bcabe502ce75851
2025-07-02 11:55:24 -04:00
Maciej Szulik
5334fcaa9c 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
Patrick Ohly
70a4950f35 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
Jordan Liggitt
a398951ea1 Implement limited merge function
Kubernetes-commit: 4d8cbad58e21e701af735c5ffa1a9fd3393de096
2024-08-17 21:27:26 -04:00
Jordan Liggitt
56b7eaf344 Narrow merge interface to merging the same types
Kubernetes-commit: 9fde1c6a85c1390c7be7705385eb99b3ebc8e06a
2024-08-17 20:43:53 -04:00
Jordan Liggitt
b3dca7eb8a Isolate mergo use, add test coverage and error checking
Kubernetes-commit: 3b3886a4509a83aff0afe7ad42da9b7819a17aed
2024-08-17 16:42:11 -04:00
Stephen Kitt
e996fa7a55 Drop references to auth-path and kubernetes_auth
These are long gone, removed in 2016:
* AuthPath removal: https://github.com/kubernetes/kubernetes/pull/29216
* Flag removal: https://github.com/kubernetes/kubernetes/pull/40048

This removes the remnants from clientcmd, mostly in the comments
describing how the configuration is loaded.

Since getServerIdentificationPartialConfig can no longer fail (it
copies fields from one struct to another), this drops the error
return, along with the error handling in the caller.

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

Kubernetes-commit: 8a8238ba7f850241de9c5cc4b22fa1a6b6a19480
2024-07-05 14:55:44 +02:00
liyuerich
68d318f3aa drop deprecated json/yaml newSerializers, use json.NewSerializerWithOptions instead
Signed-off-by: liyuerich <yue.li@daocloud.io>

Kubernetes-commit: 3c9309db463679c348934429d8487d190ed5e64a
2024-05-29 19:00:00 +08:00
Claudiu Belu
79c893df5a Replaces path.Operation with filepath.Operation (staging)
The path module has a few different functions:
Clean, Split, Join, Ext, Dir, Base, IsAbs. These functions do not
take into account the OS-specific path separator, meaning that they
won't behave as intended on Windows.

For example, Dir is supposed to return all but the last element of the
path. For the path "C:\some\dir\somewhere", it is supposed to return
"C:\some\dir\", however, it returns ".".

Instead of these functions, the ones in filepath should be used instead.

Kubernetes-commit: 856bb5c8f266f5276f1a576f47be622d7cb384e7
2022-06-15 15:17:24 +03:00
José Carlos Chávez
76174b8af8 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 13:38:07 +00:00
Ivo Gosemann
89528c43be k8s.io/client-go: add OverridingClientConfig overriding RawConfig
Kubernetes-commit: 740b4c456d731922196f8231df9ab585198696d6
2023-07-18 13:40:12 +02:00
Ivo Gosemann
17b5405ddb k8s.io/client-go: add ClientConfig option to override raw config
Kubernetes-commit: db80aa56ed8bcf4115e30fc62d27c8a8d8ec7f92
2023-07-18 13:40:12 +02:00
devincd
f242a563ef fix typo in client-go package
Signed-off-by: devincd <505259926@qq.com>

Kubernetes-commit: 975da2fb2393350db504e50652b17c70206e1407
2023-09-08 10:31:07 +08:00
Chris Bandy
3ffcfabea2 Replace os.Setenv with testing.T.Setenv in tests
T.Setenv ensures that the environment is returned to its prior state
when the test ends. It also panics when called from a parallel test to
prevent racy test interdependencies.

Kubernetes-commit: ac5ce5cbce7ddb6ffeff755d1cf670afadb8e1fb
2023-06-05 21:03:21 -05:00
HirazawaUi
84dc0417b2 fix fd leaks and failed file removing for pkg client-go
Kubernetes-commit: 73aeed8766c2c42a6cb4fc8632b1b974f4508dde
2023-05-03 01:35:16 +08:00
Arda Güçlü
4cb373f7ca Add warning log callback in client-go loading rules (#117233)
* Add warning log callback in client-go loading rules

This provides a way to consumers use their own custom warning
mechanisms instead default klog warning.

* Use typed error instead plain string

* Fix interface change in unit test

Kubernetes-commit: 2ea6896f90c8b757d8a247d393b9a13fff2dab58
2023-05-24 18:20:07 +00:00
Chris Bandy
18ffb5c67f Replace os.Setenv with testing.T.Setenv in tests
T.Setenv ensures that the environment is returned to its prior state
when the test ends. It also panics when called from a parallel test to
prevent racy test interdependencies.

Kubernetes-commit: 89467ad3e9b051515fa9632a7373d6ef01723256
2023-04-15 10:09:47 -05:00
Tim Hockin
54190dfee5 Clean up brace whitespace in **/validation_test.go
This was making my eyes bleed as I read over code.

I used the following in vim.  I made them up on the fly, but they seemed
to pass manual inspection.

:g/},\n\s*{$/s//}, {/
:w
:g/{$\n\s*{$/s//{{/
:w
:g/^\(\s*\)},\n\1},$/s//}},/
:w
:g/^\(\s*\)},$\n\1}$/s//}}/
:w

Kubernetes-commit: d55b67b349021b6c46fc6ce78f2a36bd4217145f
2023-05-02 00:36:15 -07:00
Shiming Zhang
3b78b11d95 Add json tag
Kubernetes-commit: d0677f528c03ff5556830bc2e9b9c40824b160ee
2023-05-01 23:05:32 +08:00
Shiming Zhang
1ec6a37b5c Fix LocationOfOrigin shows up unexpectedly
Kubernetes-commit: 4d9261c7567a7498d16754b7c5bf3b9ea834e5a6
2023-04-25 10:58:07 +08:00
Tim Hockin
12553015e2 Replace uses of ObjectReflectDiff with cmp.Diff
ObjectReflectDiff is already a shim over cmp.Diff, so no actual output
or behavior changes

Kubernetes-commit: bc302fa4144d21a338683cd83701661f97be4aba
2023-03-23 11:34:03 -07:00
Marly Puckett
769443557e Update redacting functionality to redact all sensitive info in config when printing with view (#109189)
* Add RedactSecrets function

* Move RedactSecrets method to existing RawBytesData case

* Update TestRedactSecrets to use new pattern of os.CreateTemp()

Kubernetes-commit: e721272d10dd6c4d85ff613182ba0eaddcec9272
2022-11-08 17:30:10 +00:00
Shyam Jeedigunta
49ac40b489 Autogen code
Kubernetes-commit: f9c46a0e3361e19de93c02562fedfff7de448dc2
2022-09-07 18:05:42 -07:00
Shyam Jeedigunta
b8a8d94944 Add DisableCompression option to KubeConfig
Kubernetes-commit: 641fd5b482c6117d459a22d99f76aae086c3524f
2022-09-07 18:04:17 -07:00
inosato
27de641f75 Remove ioutil from client-go
Signed-off-by: inosato <si17_21@yahoo.co.jp>

Kubernetes-commit: 88dfa51b6003c90e8f0a0508939a1d79950a40df
2022-07-30 20:54:41 +09:00
Davanum Srinivas
2a6c116e40 Generate and format files
- Run hack/update-codegen.sh
- Run hack/update-generated-device-plugin.sh
- Run hack/update-generated-protobuf.sh
- Run hack/update-generated-runtime.sh
- Run hack/update-generated-swagger-docs.sh
- Run hack/update-openapi-spec.sh
- Run hack/update-gofmt.sh

Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: a9593d634c6a053848413e600dadbf974627515f
2022-07-19 20:54:13 -04:00
Abirdcfly
ca60e0ea14 fix a possible panic because of taking the address of nil
Signed-off-by: Abirdcfly <fp544037857@gmail.com>

Kubernetes-commit: c8c2819a4d7327f33a143f65c6af2bff5ef49735
2022-07-19 10:39:08 +08:00
Nick Santos
5ce7078061 client-go: fix panic in ConfirmUsable validation
Fixes https://github.com/kubernetes/client-go/issues/1108

Kubernetes-commit: 7d2c6096c212d9c31e7cd0bccb6dc2dec9a4ef6a
2022-06-07 15:53:16 -04:00
Arda Güçlü
a6257fdee4 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:21:02 +00:00
Antonio Ojea
2e69bf9be0 fix unassigned error on client-go test
Kubernetes-commit: 01a0fba3620c433f49120d82f908069281482a17
2021-11-16 16:58:52 +01:00
Margo Crawford
5fca705b7d --as-uid flag in kubectl and kubeconfigs.
This corresponds to previous work to allow impersonating UIDs:
* Introduce Impersonate-UID header: #99961
* Add UID to client-go impersonation config #104483

Signed-off-by: Margo Crawford <margaretc@vmware.com>

Kubernetes-commit: 7e079f5144474cae05802771f604df2b748d781f
2021-10-19 16:12:31 -07:00
Andrey Smirnov
8f8a83c908 fix: wrap errors correct when validating kubeconfig
This allows to check for specific errors using `errors.Is`.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>

Kubernetes-commit: a5647fa417de6d17ba200f1b4bcd2bb28cceb22c
2021-09-16 22:56:08 +03:00
Jordan Liggitt
5960e3c05a Propagate conversion errors
Kubernetes-commit: ba1ca0d4591f06f796ea2d93463a4c5caaa33cc7
2021-09-13 11:49:17 -04:00
Stephen Augustus
624e6827e6 generated: Run hack/update-gofmt.sh
Signed-off-by: Stephen Augustus <foo@auggie.dev>

Kubernetes-commit: 481cf6fbe753b9eb2a47ced179211206b0a99540
2021-08-12 17:13:11 -04:00
Andrew Keesler
37ed584bed exec credential provider: InteractiveMode support
The value here is that the exec plugin author can use the kubeconfig to assert
how standard input is treated with respect to the exec plugin, e.g.,
- an exec plugin author can ensure that kubectl fails if it cannot provide
  standard input to an exec plugin that needs it (Always)
- an exec plugin author can ensure that an client-go process will still call an
  exec plugin that prefers standard input even if standard input is not
  available (IfAvailable)

Signed-off-by: Andrew Keesler <akeesler@vmware.com>

Kubernetes-commit: cd83d89ac94c5b61fdd38840098e7223e5af0d34
2021-06-14 17:15:36 -04:00
刁浩 10284789
5b0c7191ef simplify returning boolean expression in staging/src/k8s.io/client-go/tools
Signed-off-by: 刁浩 10284789 <diao.hao@zte.com.cn>

Kubernetes-commit: 9173414da6d1c70436b256d6068e3737a7434f6a
2021-05-24 07:15:36 +00:00
Stephen Augustus
b13f594878 Fixup golang.org/x/term staticcheck warnings
Errors from staticcheck:
cmd/preferredimports/preferredimports.go:38:2:
  package golang.org/x/crypto/ssh/terminal is deprecated:
  this package moved to golang.org/x/term.  (SA1019)
vendor/k8s.io/client-go/plugin/pkg/client/auth/exec/exec.go:36:2:
  package golang.org/x/crypto/ssh/terminal is deprecated:
  this package moved to golang.org/x/term.  (SA1019)
vendor/k8s.io/client-go/tools/clientcmd/auth_loaders.go:26:2:
  package golang.org/x/crypto/ssh/terminal is deprecated:
  this package moved to golang.org/x/term.  (SA1019)

Please review the above warnings. You can test via:
  hack/verify-staticcheck.sh <failing package>
If the above warnings do not make sense, you can exempt the line or
file. See:
  https://staticcheck.io/docs/#ignoring-problems

generated:
- hack/update-internal-modules.sh
- hack/lint-dependencies.sh
- hack/update-vendor.sh

Signed-off-by: Stephen Augustus <foo@auggie.dev>

Kubernetes-commit: d9435800b65d6787beaf061546599d757b8e87c9
2021-03-02 00:14:47 -05:00
Fabian Ruff
a125444d4d Return error when persister fails to modify config
Kubernetes-commit: 9efd1fd12f646b0a328702cca4c52fdf0966212d
2021-02-16 08:45:59 +01:00
Jordan Liggitt
b620e827ab Isolate TestModifyContext from $KUBECONFIG
Kubernetes-commit: ce7e1e214a9b690f2222397c82c14c0d10905940
2021-02-01 14:03:07 -05:00
xiongzhongliang
d7ba1f2e01 use klog.Info and klog.Warning when had no format
Kubernetes-commit: 90f4aeeea4cc5f96caa6ed87c67ca7e62d1ba21c
2020-11-14 00:55:06 +08:00
Mikhail Mazurskiy
29b07456f5 Check errors of the Close call
Error from out.Close() was not checked

Kubernetes-commit: f9b928f1f13821b65ea4ef783f847993c51fb4dd
2020-06-15 21:47:08 +10:00
Mikhail Mazurskiy
6cc39819fd Make inClusterConfigProvider thread safe
If configuration object is used concurrently
it is not safe to mutate self.
There is no need for mutation so avoid it
just in case.

Kubernetes-commit: 9e360eb05efafd0fcabd5a065b62cb8226da94c2
2020-06-15 21:17:45 +10:00
Mikhail Mazurskiy
6d09f8e62e Stop using mergo.MergeWithOverwrite
Use the recommended replacement instead.

Kubernetes-commit: 243a9b204e14dc9c92f08cd3252c31731b9532fd
2020-06-15 21:11:27 +10:00
Mikhail Mazurskiy
277eea62aa Cleanup currentMigrationRules
1. Use filepath for filename manipulations
2. Restructure method logic

Kubernetes-commit: 11800147f51e85b9a4fb7eb2654cae3ded9d8cf0
2020-06-15 20:59:21 +10:00
Marek Siarkowicz
e93788d387 Add datapolicy tags to staging/src/k8s.io/client-go/
Kubernetes-commit: e29c568c4a9cd45d15665345aa015e21bcff52dd
2020-10-29 18:15:52 +01:00