mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 10:53:34 +00:00
4
vendor/k8s.io/client-go/examples/README.md
generated
vendored
4
vendor/k8s.io/client-go/examples/README.md
generated
vendored
@ -25,3 +25,7 @@ for client-go.
|
||||
the custom resources.
|
||||
|
||||
[informer]: https://godoc.org/k8s.io/client-go/tools/cache#NewInformer
|
||||
|
||||
### Testing
|
||||
|
||||
- [**Fake Client**](./fake-client): Use a fake client in tests.
|
40
vendor/k8s.io/client-go/examples/create-update-delete-deployment/BUILD
generated
vendored
40
vendor/k8s.io/client-go/examples/create-update-delete-deployment/BUILD
generated
vendored
@ -1,40 +0,0 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "create-update-delete-deployment",
|
||||
embed = [":go_default_library"],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["main.go"],
|
||||
importpath = "k8s.io/client-go/examples/create-update-delete-deployment",
|
||||
deps = [
|
||||
"//vendor/k8s.io/api/apps/v1beta1:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
|
||||
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
|
||||
"//vendor/k8s.io/client-go/util/homedir:go_default_library",
|
||||
"//vendor/k8s.io/client-go/util/retry:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
2
vendor/k8s.io/client-go/examples/create-update-delete-deployment/README.md
generated
vendored
2
vendor/k8s.io/client-go/examples/create-update-delete-deployment/README.md
generated
vendored
@ -49,7 +49,7 @@ Running this command will execute the following operations on your cluster:
|
||||
|
||||
Each step is separated by an interactive prompt. You must hit the
|
||||
<kbd>Return</kbd> key to proceed to the next step. You can use these prompts as
|
||||
a break to take time to run `kubectl` and inspect the result of the operations
|
||||
a break to take time to run `kubectl` and inspect the result of the operations
|
||||
executed.
|
||||
|
||||
You should see an output like the following:
|
||||
|
34
vendor/k8s.io/client-go/examples/create-update-delete-deployment/main.go
generated
vendored
34
vendor/k8s.io/client-go/examples/create-update-delete-deployment/main.go
generated
vendored
@ -24,7 +24,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
appsv1beta1 "k8s.io/api/apps/v1beta1"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
@ -53,14 +53,19 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
deploymentsClient := clientset.AppsV1beta1().Deployments(apiv1.NamespaceDefault)
|
||||
deploymentsClient := clientset.AppsV1().Deployments(apiv1.NamespaceDefault)
|
||||
|
||||
deployment := &appsv1beta1.Deployment{
|
||||
deployment := &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "demo-deployment",
|
||||
},
|
||||
Spec: appsv1beta1.DeploymentSpec{
|
||||
Spec: appsv1.DeploymentSpec{
|
||||
Replicas: int32Ptr(2),
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"app": "demo",
|
||||
},
|
||||
},
|
||||
Template: apiv1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
@ -128,27 +133,6 @@ func main() {
|
||||
}
|
||||
fmt.Println("Updated deployment...")
|
||||
|
||||
// Rollback Deployment
|
||||
prompt()
|
||||
fmt.Println("Rolling back deployment...")
|
||||
// Once again use RetryOnConflict to avoid update conflicts
|
||||
retryErr = retry.RetryOnConflict(retry.DefaultRetry, func() error {
|
||||
result, getErr := deploymentsClient.Get("demo-deployment", metav1.GetOptions{})
|
||||
if getErr != nil {
|
||||
panic(fmt.Errorf("Failed to get latest version of Deployment: %v", getErr))
|
||||
}
|
||||
|
||||
result.Spec.RollbackTo = &appsv1beta1.RollbackConfig{
|
||||
Revision: 0, // can be specific revision number, or 0 for last revision
|
||||
}
|
||||
_, updateErr := deploymentsClient.Update(result)
|
||||
return updateErr
|
||||
})
|
||||
if retryErr != nil {
|
||||
panic(fmt.Errorf("Rollback failed: %v", retryErr))
|
||||
}
|
||||
fmt.Println("Rolled back deployment...")
|
||||
|
||||
// List Deployments
|
||||
prompt()
|
||||
fmt.Printf("Listing deployments in namespace %q:\n", apiv1.NamespaceDefault)
|
||||
|
14
vendor/k8s.io/client-go/examples/fake-client/README.md
generated
vendored
Normal file
14
vendor/k8s.io/client-go/examples/fake-client/README.md
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
# Fake Client Example
|
||||
|
||||
This example demonstrates how to use a fake client with SharedInformerFactory in tests.
|
||||
|
||||
It covers:
|
||||
* Creating the fake client
|
||||
* Setting up real informers
|
||||
* Injecting events into those informers
|
||||
|
||||
## Running
|
||||
|
||||
```
|
||||
go test -v k8s.io/client-go/examples/fake-client
|
||||
```
|
20
vendor/k8s.io/client-go/examples/fake-client/doc.go
generated
vendored
Normal file
20
vendor/k8s.io/client-go/examples/fake-client/doc.go
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package fakeclient contains examples on how to use fakeclient in tests.
|
||||
// Note: This file is here to avoid warnings on go build since there are no
|
||||
// non-test files in this package.
|
||||
package fakeclient
|
77
vendor/k8s.io/client-go/examples/fake-client/main_test.go
generated
vendored
Normal file
77
vendor/k8s.io/client-go/examples/fake-client/main_test.go
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package fakeclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
// TestFakeClient demonstrates how to use a fake client with SharedInformerFactory in tests.
|
||||
func TestFakeClient(t *testing.T) {
|
||||
// Use a timeout to keep the test from hanging.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
|
||||
// Create the fake client.
|
||||
client := fake.NewSimpleClientset()
|
||||
|
||||
// We will create an informer that writes added pods to a channel.
|
||||
pods := make(chan *v1.Pod, 1)
|
||||
informers := informers.NewSharedInformerFactory(client, 0)
|
||||
podInformer := informers.Core().V1().Pods().Informer()
|
||||
podInformer.AddEventHandler(&cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(obj interface{}) {
|
||||
pod := obj.(*v1.Pod)
|
||||
t.Logf("pod added: %s/%s", pod.Namespace, pod.Name)
|
||||
pods <- pod
|
||||
cancel()
|
||||
},
|
||||
})
|
||||
|
||||
// Make sure informers are running.
|
||||
informers.Start(ctx.Done())
|
||||
|
||||
// This is not required in tests, but it serves as a proof-of-concept by
|
||||
// ensuring that the informer goroutine have warmed up and called List before
|
||||
// we send any events to it.
|
||||
for !podInformer.HasSynced() {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
|
||||
// Inject an event into the fake client.
|
||||
p := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "my-pod"}}
|
||||
_, err := client.Core().Pods("test-ns").Create(p)
|
||||
if err != nil {
|
||||
t.Errorf("error injecting pod add: %v", err)
|
||||
}
|
||||
|
||||
// Wait and check result.
|
||||
<-ctx.Done()
|
||||
select {
|
||||
case pod := <-pods:
|
||||
t.Logf("Got pod from channel: %s/%s", pod.Namespace, pod.Name)
|
||||
default:
|
||||
t.Error("Informer did not get the added pod")
|
||||
}
|
||||
}
|
37
vendor/k8s.io/client-go/examples/in-cluster-client-configuration/BUILD
generated
vendored
37
vendor/k8s.io/client-go/examples/in-cluster-client-configuration/BUILD
generated
vendored
@ -1,37 +0,0 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "in-cluster-client-configuration",
|
||||
embed = [":go_default_library"],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["main.go"],
|
||||
importpath = "k8s.io/client-go/examples/in-cluster-client-configuration",
|
||||
deps = [
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
|
||||
"//vendor/k8s.io/client-go/rest:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
8
vendor/k8s.io/client-go/examples/in-cluster-client-configuration/README.md
generated
vendored
8
vendor/k8s.io/client-go/examples/in-cluster-client-configuration/README.md
generated
vendored
@ -25,7 +25,13 @@ build the image on Minikube:
|
||||
docker build -t in-cluster .
|
||||
|
||||
If you are not using Minikube, you should build this image and push it to a registry
|
||||
that your Kubernetes cluster can pull from.
|
||||
that your Kubernetes cluster can pull from. If you have RBAC enabled, use the following
|
||||
snippet to create role binding which will grant the default service account view
|
||||
permissions.
|
||||
|
||||
```
|
||||
kubectl create clusterrolebinding default-view --clusterrole=view --serviceaccount=default:default
|
||||
```
|
||||
|
||||
Then, run the image in a Pod with a single instance Deployment:
|
||||
|
||||
|
37
vendor/k8s.io/client-go/examples/out-of-cluster-client-configuration/BUILD
generated
vendored
37
vendor/k8s.io/client-go/examples/out-of-cluster-client-configuration/BUILD
generated
vendored
@ -1,37 +0,0 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "out-of-cluster-client-configuration",
|
||||
embed = [":go_default_library"],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["main.go"],
|
||||
importpath = "k8s.io/client-go/examples/out-of-cluster-client-configuration",
|
||||
deps = [
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
|
||||
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
43
vendor/k8s.io/client-go/examples/workqueue/BUILD
generated
vendored
43
vendor/k8s.io/client-go/examples/workqueue/BUILD
generated
vendored
@ -1,43 +0,0 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "workqueue",
|
||||
embed = [":go_default_library"],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["main.go"],
|
||||
importpath = "k8s.io/client-go/examples/workqueue",
|
||||
deps = [
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/fields:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
|
||||
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
|
||||
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
|
||||
"//vendor/k8s.io/client-go/util/workqueue:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
16
vendor/k8s.io/client-go/examples/workqueue/main.go
generated
vendored
16
vendor/k8s.io/client-go/examples/workqueue/main.go
generated
vendored
@ -21,7 +21,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@ -72,7 +72,7 @@ func (c *Controller) processNextItem() bool {
|
||||
func (c *Controller) syncToStdout(key string) error {
|
||||
obj, exists, err := c.indexer.GetByKey(key)
|
||||
if err != nil {
|
||||
glog.Errorf("Fetching object with key %s from store failed with %v", key, err)
|
||||
klog.Errorf("Fetching object with key %s from store failed with %v", key, err)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@ func (c *Controller) handleErr(err error, key interface{}) {
|
||||
|
||||
// This controller retries 5 times if something goes wrong. After that, it stops trying.
|
||||
if c.queue.NumRequeues(key) < 5 {
|
||||
glog.Infof("Error syncing pod %v: %v", key, err)
|
||||
klog.Infof("Error syncing pod %v: %v", key, err)
|
||||
|
||||
// Re-enqueue the key rate limited. Based on the rate limiter on the
|
||||
// queue and the re-enqueue history, the key will be processed later again.
|
||||
@ -110,7 +110,7 @@ func (c *Controller) handleErr(err error, key interface{}) {
|
||||
c.queue.Forget(key)
|
||||
// Report to an external entity that, even after several retries, we could not successfully process this key
|
||||
runtime.HandleError(err)
|
||||
glog.Infof("Dropping pod %q out of the queue: %v", key, err)
|
||||
klog.Infof("Dropping pod %q out of the queue: %v", key, err)
|
||||
}
|
||||
|
||||
func (c *Controller) Run(threadiness int, stopCh chan struct{}) {
|
||||
@ -118,7 +118,7 @@ func (c *Controller) Run(threadiness int, stopCh chan struct{}) {
|
||||
|
||||
// Let the workers stop when we are done
|
||||
defer c.queue.ShutDown()
|
||||
glog.Info("Starting Pod controller")
|
||||
klog.Info("Starting Pod controller")
|
||||
|
||||
go c.informer.Run(stopCh)
|
||||
|
||||
@ -133,7 +133,7 @@ func (c *Controller) Run(threadiness int, stopCh chan struct{}) {
|
||||
}
|
||||
|
||||
<-stopCh
|
||||
glog.Info("Stopping Pod controller")
|
||||
klog.Info("Stopping Pod controller")
|
||||
}
|
||||
|
||||
func (c *Controller) runWorker() {
|
||||
@ -152,13 +152,13 @@ func main() {
|
||||
// creates the connection
|
||||
config, err := clientcmd.BuildConfigFromFlags(master, kubeconfig)
|
||||
if err != nil {
|
||||
glog.Fatal(err)
|
||||
klog.Fatal(err)
|
||||
}
|
||||
|
||||
// creates the clientset
|
||||
clientset, err := kubernetes.NewForConfig(config)
|
||||
if err != nil {
|
||||
glog.Fatal(err)
|
||||
klog.Fatal(err)
|
||||
}
|
||||
|
||||
// create the pod watcher
|
||||
|
Reference in New Issue
Block a user