From 62d1251874cb259d38d727300ac4b2646c4122c8 Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Fri, 2 Jun 2017 13:44:49 -0700 Subject: [PATCH] clientgo/examples: add ToC for examples Also add authenticate- prefix to auth samples. Signed-off-by: Ahmet Alp Balkan --- hack/.linted_packages | 4 +-- hack/verify-staging-imports.sh | 2 +- .../src/k8s.io/client-go/examples/README.md | 28 +++++++++++++++++++ .../BUILD | 2 +- .../Dockerfile | 0 .../README.md | 6 ++-- .../main.go | 0 .../BUILD | 2 +- .../README.md | 7 +++-- .../main.go | 0 10 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 staging/src/k8s.io/client-go/examples/README.md rename staging/src/k8s.io/client-go/examples/{in-cluster => in-cluster-client-configuration}/BUILD (92%) rename staging/src/k8s.io/client-go/examples/{in-cluster => in-cluster-client-configuration}/Dockerfile (100%) rename staging/src/k8s.io/client-go/examples/{in-cluster => in-cluster-client-configuration}/README.md (88%) rename staging/src/k8s.io/client-go/examples/{in-cluster => in-cluster-client-configuration}/main.go (100%) rename staging/src/k8s.io/client-go/examples/{out-of-cluster => out-of-cluster-client-configuration}/BUILD (91%) rename staging/src/k8s.io/client-go/examples/{out-of-cluster => out-of-cluster-client-configuration}/README.md (82%) rename staging/src/k8s.io/client-go/examples/{out-of-cluster => out-of-cluster-client-configuration}/main.go (100%) diff --git a/hack/.linted_packages b/hack/.linted_packages index a04fb93796eb..fb5e9cb4be46 100644 --- a/hack/.linted_packages +++ b/hack/.linted_packages @@ -384,8 +384,8 @@ staging/src/k8s.io/apiserver/plugin/pkg/authenticator/password/allow staging/src/k8s.io/apiserver/plugin/pkg/authenticator/request/basicauth staging/src/k8s.io/client-go/discovery staging/src/k8s.io/client-go/examples/create-update-delete-deployment -staging/src/k8s.io/client-go/examples/in-cluster -staging/src/k8s.io/client-go/examples/out-of-cluster +staging/src/k8s.io/client-go/examples/in-cluster-client-configuration +staging/src/k8s.io/client-go/examples/out-of-cluster-client-configuration staging/src/k8s.io/client-go/examples/third-party-resources-deprecated staging/src/k8s.io/client-go/informers staging/src/k8s.io/client-go/informers/admissionregistration diff --git a/hack/verify-staging-imports.sh b/hack/verify-staging-imports.sh index 452efd0456ba..66ccd73eabe3 100755 --- a/hack/verify-staging-imports.sh +++ b/hack/verify-staging-imports.sh @@ -80,7 +80,7 @@ if grep -rq '// import "k8s.io/kubernetes/' 'staging/'; then exit 1 fi -for EXAMPLE in vendor/k8s.io/client-go/examples/{in-cluster,out-of-cluster,third-party-resources-deprecated} vendor/k8s.io/apiextensions-apiserver/examples ; do +for EXAMPLE in vendor/k8s.io/client-go/examples/{in-cluster-client-configuration,out-of-cluster-client-configuration,third-party-resources-deprecated} vendor/k8s.io/apiextensions-apiserver/examples ; do test -d "${EXAMPLE}" # make sure example is still there if go list -f '{{ join .Deps "\n" }}' "./${EXAMPLE}/..." | sort | uniq | grep -q k8s.io/client-go/plugin; then echo "${EXAMPLE} imports client-go plugins by default, but shouldn't." diff --git a/staging/src/k8s.io/client-go/examples/README.md b/staging/src/k8s.io/client-go/examples/README.md new file mode 100644 index 000000000000..08909dd59606 --- /dev/null +++ b/staging/src/k8s.io/client-go/examples/README.md @@ -0,0 +1,28 @@ +# client-go Examples + +This directory contains examples that cover various use cases and functionality +for client-go. + +### Configuration + +- [**Authenticate in cluster**](./in-cluster-client-configuration): Configure a + client while running inside the Kubernetes cluster. +- [**Authenticate out of cluster**](./out-of-cluster-client-configuration): + Configure a client to access a Kubernetes cluster from outside. + +### Basics + +- [**Managing resources with API**](./create-update-delete-deployment): Create, + get, update, delete a Deployment resource. + +### Advanced Concepts + +- [**Work queues**](./workqueue): Create a hotloop-free controller with the + rate-limited workqueue and the [informer framework][informer]. +- [**Third-party resources (deprecated)**](./third-party-resources-deprecated): + Register a custom resource type with the API, create/update/query this custom + type, and write a controller drives the cluster state based on the changes to + the custom resources. + +[informer]: https://godoc.org/k8s.io/client-go/tools/cache#NewInformer + diff --git a/staging/src/k8s.io/client-go/examples/in-cluster/BUILD b/staging/src/k8s.io/client-go/examples/in-cluster-client-configuration/BUILD similarity index 92% rename from staging/src/k8s.io/client-go/examples/in-cluster/BUILD rename to staging/src/k8s.io/client-go/examples/in-cluster-client-configuration/BUILD index 5e9e9e69cad4..038801eed63d 100644 --- a/staging/src/k8s.io/client-go/examples/in-cluster/BUILD +++ b/staging/src/k8s.io/client-go/examples/in-cluster-client-configuration/BUILD @@ -9,7 +9,7 @@ load( ) go_binary( - name = "in-cluster", + name = "in-cluster-client-configuration", library = ":go_default_library", tags = ["automanaged"], ) diff --git a/staging/src/k8s.io/client-go/examples/in-cluster/Dockerfile b/staging/src/k8s.io/client-go/examples/in-cluster-client-configuration/Dockerfile similarity index 100% rename from staging/src/k8s.io/client-go/examples/in-cluster/Dockerfile rename to staging/src/k8s.io/client-go/examples/in-cluster-client-configuration/Dockerfile diff --git a/staging/src/k8s.io/client-go/examples/in-cluster/README.md b/staging/src/k8s.io/client-go/examples/in-cluster-client-configuration/README.md similarity index 88% rename from staging/src/k8s.io/client-go/examples/in-cluster/README.md rename to staging/src/k8s.io/client-go/examples/in-cluster-client-configuration/README.md index 0e251d134fa9..811b750c9e26 100644 --- a/staging/src/k8s.io/client-go/examples/in-cluster/README.md +++ b/staging/src/k8s.io/client-go/examples/in-cluster-client-configuration/README.md @@ -1,7 +1,7 @@ # Authenticating inside the cluster -This example shows you how you can write an application that authenticates to -the Kubernetes API while it is running on a Kubernetes cluster. +This example shows you how to configure a client with client-go to authenticate +to the Kubernetes API from an application running inside the Kubernetes cluster. client-go uses the [Service Account token][sa] mounted inside the Pod at the `/var/run/secrets/kubernetes.io/serviceaccount` path when the @@ -11,7 +11,7 @@ client-go uses the [Service Account token][sa] mounted inside the Pod at the First compile the application for Linux: - cd in-cluster + cd in-cluster-client-configuration GOOS=linux go build -o ./app . Then package it to a docker image using the provided Dockerfile to run it on diff --git a/staging/src/k8s.io/client-go/examples/in-cluster/main.go b/staging/src/k8s.io/client-go/examples/in-cluster-client-configuration/main.go similarity index 100% rename from staging/src/k8s.io/client-go/examples/in-cluster/main.go rename to staging/src/k8s.io/client-go/examples/in-cluster-client-configuration/main.go diff --git a/staging/src/k8s.io/client-go/examples/out-of-cluster/BUILD b/staging/src/k8s.io/client-go/examples/out-of-cluster-client-configuration/BUILD similarity index 91% rename from staging/src/k8s.io/client-go/examples/out-of-cluster/BUILD rename to staging/src/k8s.io/client-go/examples/out-of-cluster-client-configuration/BUILD index 7545acad7d49..92f4666d9974 100644 --- a/staging/src/k8s.io/client-go/examples/out-of-cluster/BUILD +++ b/staging/src/k8s.io/client-go/examples/out-of-cluster-client-configuration/BUILD @@ -9,7 +9,7 @@ load( ) go_binary( - name = "out-of-cluster", + name = "out-of-cluster-client-configuration", library = ":go_default_library", tags = ["automanaged"], ) diff --git a/staging/src/k8s.io/client-go/examples/out-of-cluster/README.md b/staging/src/k8s.io/client-go/examples/out-of-cluster-client-configuration/README.md similarity index 82% rename from staging/src/k8s.io/client-go/examples/out-of-cluster/README.md rename to staging/src/k8s.io/client-go/examples/out-of-cluster-client-configuration/README.md index f82e8d31abd6..80da4a168959 100644 --- a/staging/src/k8s.io/client-go/examples/out-of-cluster/README.md +++ b/staging/src/k8s.io/client-go/examples/out-of-cluster-client-configuration/README.md @@ -1,7 +1,8 @@ # Authenticating outside the cluster -This example shows you how to authenticate to the Kubernetes API from an -application running outside the Kubernetes cluster with client-go. +This example shows you how to configure a client with client-go to authenticate +to the Kubernetes API from an application running outside the Kubernetes +cluster. You can use your kubeconfig file that contains the context information of your cluster to initialize a client. The kubeconfig file is also used @@ -14,7 +15,7 @@ Make sure your `kubectl` is configured and pointed to a cluster. Run Run this application with: - cd out-of-cluster + cd out-of-cluster-client-configuration go build -o app . ./app diff --git a/staging/src/k8s.io/client-go/examples/out-of-cluster/main.go b/staging/src/k8s.io/client-go/examples/out-of-cluster-client-configuration/main.go similarity index 100% rename from staging/src/k8s.io/client-go/examples/out-of-cluster/main.go rename to staging/src/k8s.io/client-go/examples/out-of-cluster-client-configuration/main.go