mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
Updated vednor files
This commit is contained in:
38
vendor/k8s.io/client-go/examples/out-of-cluster-client-configuration/BUILD
generated
vendored
38
vendor/k8s.io/client-go/examples/out-of-cluster-client-configuration/BUILD
generated
vendored
@ -1,38 +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",
|
||||
importpath = "k8s.io/client-go/examples/out-of-cluster-client-configuration",
|
||||
library = ":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"],
|
||||
)
|
35
vendor/k8s.io/client-go/examples/out-of-cluster-client-configuration/README.md
generated
vendored
35
vendor/k8s.io/client-go/examples/out-of-cluster-client-configuration/README.md
generated
vendored
@ -1,35 +0,0 @@
|
||||
# Authenticating outside the cluster
|
||||
|
||||
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
|
||||
by the `kubectl` command to authenticate to the clusters.
|
||||
|
||||
## Running this example
|
||||
|
||||
Make sure your `kubectl` is configured and pointed to a cluster. Run
|
||||
`kubectl get nodes` to confirm.
|
||||
|
||||
Run this application with:
|
||||
|
||||
cd out-of-cluster-client-configuration
|
||||
go build -o app .
|
||||
./app
|
||||
|
||||
Running this application will use the kubeconfig file and then authenticate to the
|
||||
cluster, and print the number of nodes in the cluster every 10 seconds:
|
||||
|
||||
$ ./app
|
||||
There are 3 pods in the cluster
|
||||
There are 3 pods in the cluster
|
||||
There are 3 pods in the cluster
|
||||
...
|
||||
|
||||
Press <kbd>Ctrl</kbd>+<kbd>C</kbd> to quit this application.
|
||||
|
||||
> **Note:** You can use the `-kubeconfig` option to use a different config file. By default
|
||||
this program picks up the default file used by kubectl (when `KUBECONFIG`
|
||||
environment variable is not set).
|
85
vendor/k8s.io/client-go/examples/out-of-cluster-client-configuration/main.go
generated
vendored
85
vendor/k8s.io/client-go/examples/out-of-cluster-client-configuration/main.go
generated
vendored
@ -1,85 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 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.
|
||||
*/
|
||||
|
||||
// Note: the example only works with the code within the same release/branch.
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
// Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters).
|
||||
// _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var kubeconfig *string
|
||||
if home := homeDir(); home != "" {
|
||||
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
|
||||
} else {
|
||||
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
|
||||
}
|
||||
flag.Parse()
|
||||
|
||||
// use the current context in kubeconfig
|
||||
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
// create the clientset
|
||||
clientset, err := kubernetes.NewForConfig(config)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
for {
|
||||
pods, err := clientset.CoreV1().Pods("").List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
fmt.Printf("There are %d pods in the cluster\n", len(pods.Items))
|
||||
|
||||
// Examples for error handling:
|
||||
// - Use helper functions like e.g. errors.IsNotFound()
|
||||
// - And/or cast to StatusError and use its properties like e.g. ErrStatus.Message
|
||||
_, err = clientset.CoreV1().Pods("default").Get("example-xxxxx", metav1.GetOptions{})
|
||||
if errors.IsNotFound(err) {
|
||||
fmt.Printf("Pod not found\n")
|
||||
} else if statusError, isStatus := err.(*errors.StatusError); isStatus {
|
||||
fmt.Printf("Error getting pod %v\n", statusError.ErrStatus.Message)
|
||||
} else if err != nil {
|
||||
panic(err.Error())
|
||||
} else {
|
||||
fmt.Printf("Found pod\n")
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func homeDir() string {
|
||||
if h := os.Getenv("HOME"); h != "" {
|
||||
return h
|
||||
}
|
||||
return os.Getenv("USERPROFILE") // windows
|
||||
}
|
Reference in New Issue
Block a user