Go client for Kubernetes.
Go to file
Kubernetes Publisher 615dfd3eb0 Merge pull request #64122 from ixdy/update-rules_go-and-gazelle
Automatic merge from submit-queue (batch tested with PRs 64122, 64936, 65288, 65383). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Update to rules_go 0.12.1 and gazelle 0.12.0 and perform related cleanups

**What this PR does / why we need it**: my initial intent was to simply update to rules_go 0.12.1 and gazelle 0.12.0.

A few internal changes / deprecations meant that I finally needed to clean up some technical debt. This also fixes #64122.
I've attempted to keep the steps as separate commits to make it easier to review:

1. Disable gazelle proto rule generation; legacy proto rules are deprecated, and we don't (currently) build protos at build time anyway, instead generating them with `hack/update-generated-protobuf.sh` and then checking them in. We can revisit this in the future if we'd like.
2. Remove the legacy `go_default_library_protos` filegroups using [buildozer](https://github.com/bazelbuild/buildtools/tree/master/buildozer). We don't use these, anyway.
3. Update the rules_go bazel workspace dependency to 0.12.1.
4. Vendor gazelle 0.12.0 and update BUILD files with `hack/update-bazel.sh`. This causes a lot of diffs, because `select()`s are no longer used in `srcs` attributes, external tests are folded into non-external tests, and vendored targets get an `importmap` attribute.
5. Set `gazelle:prefix` on `staging/src/BUILD` to make gazelle treat these correctly(ish). This allows us to remove the sed rewrite hack in `hack/update-bazel.sh`.
6. Explicitly set `# gazelle:importmap_prefix k8s.io/kubernetes/vendor` on `vendor/`, so that all vendored dependencies get the right importmap. gazelle 0.12.0 uses the bazel workspace name + `vendor/` as a prefix, which doesn't work with native go. Newer gazelle will use the go prefix (https://github.com/bazelbuild/bazel-gazelle/pull/207), but it's not released yet. Setting this correctly now also fixes later `BUILD` churn.
7. Re-run `hack/update-bazel.sh`. This causes a bunch of diffs, since anything under `staging/src` now uses the `staging/src/` path instead of `vendor/`. (Both would work for bazel, but gazelle uses the former, since `vendor/` uses symlinks.) Also `importmap`s under `vendor/` are fixed.
8. Reformat a few files (using [buildifier](https://github.com/bazelbuild/buildtools/tree/master/buildifier)) to make later diffs easier to read.
9. Rework the `go_genrule` rules to use the new `go_genrule` from https://github.com/kubernetes/repo-infra/pull/72, which is more bazely, since it uses the rules_go `go_path` rule instead of lots of shell.
10. Remove the deprecated `go_prefix` rule from the root BUILD.bazel file.
11. Set `# gazelle:importmap_prefix k8s.io/kubernetes/vendor` on `staging/src` as well, which ensures that these repos are treated as vendored dependencies. (It's basically the bazel-y way of doing the `vendor/k8s.io` symlinks.)
12. Run `hack/update-bazel.sh` one last time to fix all of the `importmap`s under `staging/src`.

Note re: point 6 above - we're pretty much ignoring the `vendor/k8s.io` symlinks entirely now under bazel. Using the `gazelle:prefix` directive ensures these get mapped into the right go importpath, and the `go_path` rule installs these correctly now too.

**Special notes for your reviewer**: this should not be submitted before https://github.com/kubernetes/repo-infra/pull/72, obviously.

**Release note**:

```release-note
NONE
```

/assign @BenTheElder @fejta @thockin
cc @cblecker @jayconrod

Kubernetes-commit: 1ad1c8c7f80d99b9625924b2102a04a555162bfb
2018-06-24 19:08:44 +00:00
.github client-go: document README exception in .github/PULL_REQUEST_TEMPLATE.md 2018-05-29 09:16:25 +02:00
deprecated-dynamic fix dynamic client name 2018-05-09 12:58:12 -04:00
discovery Collapse memcached discovery client onto parallelized discovery method 2018-05-09 18:00:12 -04:00
dynamic fix dynamic client name 2018-05-09 12:58:12 -04:00
examples Add client-go example using fake client in test. 2018-06-20 18:35:57 -07:00
Godeps Merge pull request #64122 from ixdy/update-rules_go-and-gazelle 2018-06-24 19:08:44 +00:00
informers Revert "Auto-generated code for the Vertical Pod Autoscaler API." 2018-06-07 14:12:22 -04:00
kubernetes Revert "Auto-generated code for the Vertical Pod Autoscaler API." 2018-06-07 14:12:22 -04:00
listers Revert "Auto-generated code for the Vertical Pod Autoscaler API." 2018-06-07 14:12:22 -04:00
pkg Update generated files 2018-06-13 09:53:47 +02:00
plugin/pkg/client/auth client-go: promote exec plugin support to beta 2018-05-31 14:28:27 -07:00
rest client-go: make exec auth and auth provider mutually exclusive 2018-06-01 10:34:45 -07:00
restmapper construct resource.Builder from kubeconfig flags 2018-05-09 13:53:07 -04:00
scale Update generated files 2018-06-13 09:53:47 +02:00
testing add Patch support in fake kubeClient 2018-04-11 11:37:30 -07: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 Update generated files 2018-06-13 09:53:47 +02:00
transport Add TLS support to exec authenticator plugin 2018-05-30 14:03:32 -07:00
util Re-use private key after failed CSR 2018-06-13 11:27:25 -07:00
vendor Merge pull request #65034 from caesarxuchao/json-case-sensitive 2018-06-14 23:07:59 +00:00
.travis.yml
CHANGELOG.md Add client-go 7.0.0 changelog 2018-04-03 13:16:13 +05:30
code-of-conduct.md Add code-of-conduct.md to staging repos 2017-12-20 15:21:56 -05:00
CONTRIBUTING.md Document that changes to the README.md are done in this repo 2018-05-25 10:32:46 -07:00
INSTALL.md Update README.md and INSTALL.md for v6.0.0 2017-12-18 17:36:01 +01:00
LICENSE
OWNERS client-go: start fresh with owner file 2018-05-25 15:49:44 +02:00
README.md Rewording for clarity 2018-05-24 12:51:22 -07:00
SECURITY_CONTACTS add PST to main SECURITY_CONTACTS as formality 2018-05-24 09:33:43 -04:00

client-go

Go clients for talking to a kubernetes cluster.

We currently recommend using the v7.0.0 tag. See INSTALL.md for detailed installation instructions. go get k8s.io/client-go/... works, but will build master, which doesn't handle the dependencies well.

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 transport package is used to set up auth and start a connection.
  • The tools/cache package is useful for writing controllers.

Versioning

client-go follows semver. We will not make backwards-incompatible changes without incrementing the major version number. A change is backwards-incompatible either if it i) changes the public interfaces of client-go, or ii) makes client-go incompatible with otherwise supported versions of Kubernetes clusters.

Changes that add features in a backwards-compatible way will result in bumping the minor version (second digit) number.

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.

A consequence of this is that client-go version numbers will be unrelated to Kubernetes version numbers.

Branches and tags.

We will create a new branch and tag for each increment in the major version number or 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 master branch will track HEAD in the main Kubernetes repo and accumulate changes. Consider HEAD to have the version x.(y+1).0-alpha or (x+1).0.0-alpha (depending on whether it has accumulated a breaking change or not), where x and y are the current major and minor versions.

Compatibility: your code <-> client-go

client-go follows semver, so until the major version of client-go gets increased, your code will compile and will continue to work with explicitly supported versions of Kubernetes clusters. You must use a dependency management system and pin a specific major version of client-go to get this benefit, as HEAD follows the upstream Kubernetes repo.

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.4 Kubernetes 1.5 Kubernetes 1.6 Kubernetes 1.7 Kubernetes 1.8 Kubernetes 1.9 Kubernetes 1.10
client-go 1.4 - - - - - -
client-go 1.5 + - - - - - -
client-go 2.0 +- +- +- +- +- +-
client-go 3.0 +- +- - +- +- +-
client-go 4.0 +- +- +- +- +- +-
client-go 5.0 +- +- +- +- +- +-
client-go 6.0 +- +- +- +- +- +-
client-go 7.0 +- +- +- +- +- +-
client-go 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
client-go 1.4 Kubernetes main repo, 1.4 branch = -
client-go 1.5 Kubernetes main repo, 1.5 branch = -
client-go 2.0 Kubernetes main repo, 1.5 branch = -
client-go 3.0 Kubernetes main repo, 1.6 branch = -
client-go 4.0 Kubernetes main repo, 1.7 branch = -
client-go 5.0 Kubernetes main repo, 1.8 branch
client-go 6.0 Kubernetes main repo, 1.9 branch
client-go 7.0 Kubernetes main repo, 1.10 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

As of April 2018, client-go is still a mirror of k8s.io/kubernetes/staging/src/client-go, the code development is still done in the staging area. Since Kubernetes 1.8 release, when syncing the code from the staging area, we also sync the Kubernetes version tags to client-go, prefixed with "kubernetes-". For example, if you check out the kubernetes-v1.8.0 tag in client-go, the code you get is exactly the same as if you check out the v1.8.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

You can use go get k8s.io/client-go/... to get client-go, but you will get the unstable master branch and client-go's vendored dependencies will not be added to your $GOPATH. So we think most users will want to use a dependency management system. 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

If your application depends on a package that client-go depends on, and you let the Go compiler find the dependency in GOPATH, you will end up with duplicated dependencies: one copy from the GOPATH, and one from the vendor folder of client-go. This will cause unexpected runtime error like flag redefinition, since the go compiler ends up importing both packages separately, even if they are exactly the same thing. If this happens, you can either

  • run godep restore (godep) in the client-go/ folder, then remove the vendor folder of client-go. Then the packages in your GOPATH will be the only copy
  • or run godep save in your application folder to flatten all dependencies.

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.