Go client for Kubernetes.
Go to file
Jack Kleeman a493c8da9a Add ReloadCertFromDisk flag to rest.Config and to kubeconfig which allows the provided client certificate files to be reloaded from disk (currently on every use)
Close outbound connections when using a cert callback and certificates rotate. This means that we won't get into a situation where we have open TLS connections using expires certs, which would get unauthorized errors at the apiserver

Attempt to retrieve a new certificate if open connections near expiry, to prevent the case where the cert expires but we haven't yet opened a new TLS connection and so GetClientCertificate hasn't been called.

Move certificate rotation logic to a separate function

Rely on generic transport approach to handle closing TLS client connections in exec plugin; no need to use a custom dialer as this is now the default behaviour of the transport when faced with a cert callback. As a result of handling this case, it is now safe to apply the transport approach even in cases where there is a custom Dialer (this will not affect kubelet connrotation behaviour, because that uses a custom transport, not just a dialer).

Check expiry of the full TLS certificate chain that will be presented, not only the leaf. Only do this check when the certificate actually rotates. Start the certificate as a zero value, not nil, so that we don't see a rotation when there is in fact no client certificate

Drain the timer when we first initialize it, to prevent immediate rotation. Additionally, calling Stop() on the timer isn't necessary.

Don't close connections on the first 'rotation'

Remove RotateCertFromDisk and RotateClientCertFromDisk flags.

Instead simply default to rotating certificates from disk whenever files are exclusively provided.

Add integration test for client certificate rotation

Simplify logic; rotate every 5 mins

Instead of trying to be clever and checking for rotation just before an
expiry, let's match the logic of the new apiserver cert rotation logic
as much as possible. We write a controller that checks for rotation
every 5 mins. We also check on every new connection.

Respond to review

Fix kubelet certificate rotation logic

The kubelet rotation logic seems to be broken because it expects its
cert files to end up as cert data whereas in fact they end up as a
callback. We should just call the tlsConfig GetCertificate callback
as this obtains a current cert even in cases where a static cert is
provided, and check that for validity.

Later on we can refactor all of the kubelet logic so that all it does is
write files to disk, and the cert rotation work does the rest.

Only read certificates once a second at most

Respond to review

1) Don't blat the cert file names
2) Make it more obvious where we have a neverstop
3) Naming
4) Verbosity

Avoid cache busting

Use filenames as cache keys when rotation is enabled, and add the
rotation later in the creation of the transport.

Caller should start the rotating dialer

Add continuous request rotation test

Rebase: use context in List/Watch

Swap goroutine around

Retry GETs on net.IsProbableEOF

Refactor certRotatingDialer

For simplicity, don't affect cert callbacks

To reduce change surface, lets not try to handle the case of a changing
GetCert callback in this PR. Reverting this commit should be sufficient
to handle that case in a later PR.

This PR will focus only on rotating certificate and key files.
Therefore, we don't need to modify the exec auth plugin.

Fix copyright year

Kubernetes-commit: 929b1559a0b855d996257ab3ad5364605edc253d
2019-06-14 22:08:58 +01:00
.github delete all duplicate empty blanks 2019-02-22 09:43:51 +08:00
deprecated snapshot clientsets pending context migration 2020-01-31 19:39:00 -08:00
discovery Refresh discovery server resources for memCacheClient in parallel 2020-02-20 13:40:23 -08:00
dynamic refactor 2020-01-27 18:19:44 -08:00
examples generated: run refactor 2020-02-08 12:30:21 -05:00
Godeps Merge pull request #88509 from robscott/ingress-v1beta1-class 2020-03-02 08:25:25 +00:00
informers Adding IngressClass to networking/v1beta1 2020-02-24 21:20:45 -08:00
kubernetes Adding IngressClass to networking/v1beta1 2020-02-24 21:20:45 -08:00
kubernetes_test generated: run refactor 2020-02-07 18:16:47 -08:00
listers Adding IngressClass to networking/v1beta1 2020-02-24 21:20:45 -08:00
metadata refactor 2020-01-27 18:19:44 -08:00
pkg Autogenerated code 2019-10-24 14:09:51 +02:00
plugin/pkg/client/auth add a flag in azure auth module to omit spn: prefix in audience claim 2020-01-28 14:29:11 -08:00
rest Add ReloadCertFromDisk flag to rest.Config and to kubeconfig which allows the provided client certificate files to be reloaded from disk (currently on every use) 2019-06-14 22:08:58 +01:00
restmapper trivial fix typo: resouce -> resource 2019-02-15 02:05:28 -08:00
scale refactor 2020-01-27 18:19:44 -08:00
testing Allow Action's Matches function to specify a subresource. 2020-01-30 12:04:23 +01:00
third_party/forked/golang/template sync: initially remove files BUILD */BUILD BUILD.bazel */BUILD.bazel 2018-03-15 09:19:38 +00:00
tools Improve rate limiter latency logging and metrics 2020-02-13 13:32:12 -08:00
transport Add ReloadCertFromDisk flag to rest.Config and to kubeconfig which allows the provided client certificate files to be reloaded from disk (currently on every use) 2019-06-14 22:08:58 +01:00
util certificates: update controllers to understand signerName field 2020-02-17 23:06:02 +00:00
CHANGELOG.md modify the error url of csi drivers 2020-01-21 02:01:01 +00:00
code-of-conduct.md Add code-of-conduct.md to staging repos 2017-12-20 15:21:56 -05:00
CONTRIBUTING.md Clarify client-go issue location (#85464) 2019-12-04 08:25:17 +00:00
go.mod Merge pull request #88509 from robscott/ingress-v1beta1-class 2020-03-02 08:25:25 +00:00
go.sum Merge pull request #88509 from robscott/ingress-v1beta1-class 2020-03-02 08:25:25 +00:00
INSTALL.md client-go: update INSTALL.md to include semver tags 2019-12-06 15:53:00 +05:30
LICENSE published by bot 2016-12-11 15:19:40 +00:00
OWNERS Updated OWNERS files to include link to docs 2019-01-30 20:05:00 +01:00
README.md Update README for release 1.17 2019-12-11 19:54:19 +05:30
SECURITY_CONTACTS Update SECURITY_CONTACTS with current PSC 2019-05-29 15:22:35 +05:30

client-go

Go clients for talking to a kubernetes cluster.

We recommend using the v0.x.y tags for Kubernetes releases >= v1.17.0 and kubernetes-1.x.y tags for Kubernetes releases < v1.17.0. See INSTALL.md for detailed installation instructions. go get k8s.io/client-go@master works, but will fetch master, which may be less stable than a tagged release.

BuildStatus Widget GoReport Widget GoDocWidget

Table of Contents

What's included

  • The kubernetes package contains the clientset to access Kubernetes API.
  • The discovery package is used to discover APIs supported by a Kubernetes API server.
  • The dynamic package contains a dynamic client that can perform generic operations on arbitrary Kubernetes API objects.
  • The plugin/pkg/client/auth packages contain optional authentication plugins for obtaining credentials from external sources.
  • The transport package is used to set up auth and start a connection.
  • The tools/cache package is useful for writing controllers.

Versioning

  • For each v1.x.y Kubernetes release, the major version (first digit) would remain 0.

  • Bugfixes will result in the patch version (third digit) changing. PRs that are cherry-picked into an older Kubernetes release branch will result in an update to the corresponding branch in client-go, with a corresponding new tag changing the patch version.

Branches and tags.

We will create a new branch and tag for each increment in the minor version number. We will create only a new tag for each increment in the patch version number. See semver for definitions of major, minor, and patch.

The HEAD of the master branch in client-go will track the HEAD of the master branch in the main Kubernetes repo.

Compatibility: your code <-> client-go

The v0.x.y tags indicate that go APIs may change in incompatible ways in different versions.

See INSTALL.md for guidelines on requiring a specific version of client-go.

Compatibility: client-go <-> Kubernetes clusters

Since Kubernetes is backwards compatible with clients, older client-go versions will work with many different Kubernetes cluster versions.

We will backport bugfixes--but not new features--into older versions of client-go.

Compatibility matrix

Kubernetes 1.15 Kubernetes 1.16 Kubernetes 1.17
kubernetes-1.15.0 +- +-
kubernetes-1.16.0 +- +-
kubernetes-1.17.0/v0.17.0 +- +-
HEAD +- +- +-

Key:

  • Exactly the same features / API objects in both client-go and the Kubernetes version.
  • + client-go has features or API objects that may not be present in the Kubernetes cluster, either due to that client-go has additional new API, or that the server has removed old API. However, everything they have in common (i.e., most APIs) will work. Please note that alpha APIs may vanish or change significantly in a single release.
  • - The Kubernetes cluster has features the client-go library can't use, either due to the server has additional new API, or that client-go has removed old API. However, everything they share in common (i.e., most APIs) will work.

See the CHANGELOG for a detailed description of changes between client-go versions.

Branch Canonical source code location Maintenance status
release-1.4 Kubernetes main repo, 1.4 branch = -
release-1.5 Kubernetes main repo, 1.5 branch = -
release-2.0 Kubernetes main repo, 1.5 branch = -
release-3.0 Kubernetes main repo, 1.6 branch = -
release-4.0 Kubernetes main repo, 1.7 branch = -
release-5.0 Kubernetes main repo, 1.8 branch = -
release-6.0 Kubernetes main repo, 1.9 branch = -
release-7.0 Kubernetes main repo, 1.10 branch = -
release-8.0 Kubernetes main repo, 1.11 branch =-
release-9.0 Kubernetes main repo, 1.12 branch =-
release-10.0 Kubernetes main repo, 1.13 branch =-
release-11.0 Kubernetes main repo, 1.14 branch
release-12.0 Kubernetes main repo, 1.15 branch
release-13.0 Kubernetes main repo, 1.16 branch
release-14.0 Kubernetes main repo, 1.17 branch
client-go HEAD Kubernetes main repo, master branch

Key:

  • Changes in main Kubernetes repo are actively published to client-go by a bot
  • = Maintenance is manual, only severe security bugs will be patched.
  • - Deprecated; please upgrade.

Deprecation policy

We will maintain branches for at least six months after their first stable tag is cut. (E.g., the clock for the release-2.0 branch started ticking when we tagged v2.0.0, not when we made the first alpha.) This policy applies to every version greater than or equal to 2.0.

Why do the 1.4 and 1.5 branch contain top-level folder named after the version?

For the initial release of client-go, we thought it would be easiest to keep separate directories for each minor version. That soon proved to be a mistake. We are keeping the top-level folders in the 1.4 and 1.5 branches so that existing users won't be broken.

Kubernetes tags

This repository is still a mirror of k8s.io/kubernetes/staging/src/client-go, the code development is still done in the staging area.

Since Kubernetes v1.8.0, when syncing the code from the staging area, we also sync the Kubernetes version tags to client-go, prefixed with kubernetes-. From Kubernetes v1.17.0, we also create matching semver v0.x.y tags for each v1.x.y Kubernetes release.

For example, if you check out the kubernetes-1.17.0 or the v0.17.0 tag in client-go, the code you get is exactly the same as if you check out the v1.17.0 tag in Kubernetes, and change directory to staging/src/k8s.io/client-go.

The purpose is to let users quickly find matching commits among published repos, like sample-apiserver, apiextension-apiserver, etc. The Kubernetes version tag does NOT claim any backwards compatibility guarantees for client-go. Please check the semantic versions if you care about backwards compatibility.

How to get it

Use go1.11+ and fetch the desired version using the go get command. For example:

go get k8s.io/client-go@v0.17.0

See INSTALL.md for detailed instructions.

How to use it

If your application runs in a Pod in the cluster, please refer to the in-cluster example, otherwise please refer to the out-of-cluster example.

Dependency management

For details on how to correctly use a dependency management for installing client-go, please see INSTALL.md.

Contributing code

Please send pull requests against the client packages in the Kubernetes main repository. Changes in the staging area will be published to this repository every day.