本文整理匯總了Golang中k8s/io/client-go/1/4/kubernetes.Clientset類的典型用法代碼示例。如果您正苦於以下問題:Golang Clientset類的具體用法?Golang Clientset怎麽用?Golang Clientset使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Clientset類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createReplicaSetOrDie
func createReplicaSetOrDie(cs *release_1_4.Clientset, ns string, size int32, exclusive bool) {
container := api.Container{
Name: "busybox",
Image: "gcr.io/google_containers/echoserver:1.4",
}
if exclusive {
container.Ports = []api.ContainerPort{
{HostPort: 5555, ContainerPort: 5555},
}
}
rs := &extensions.ReplicaSet{
ObjectMeta: api.ObjectMeta{
Name: "rs",
Namespace: ns,
},
Spec: extensions.ReplicaSetSpec{
Replicas: &size,
Selector: &extensions.LabelSelector{
MatchLabels: map[string]string{"foo": "bar"},
},
Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{
Labels: map[string]string{"foo": "bar"},
},
Spec: api.PodSpec{
Containers: []api.Container{container},
},
},
},
}
_, err := cs.Extensions().ReplicaSets(ns).Create(rs)
framework.ExpectNoError(err, "Creating replica set %q in namespace %q", rs.Name, ns)
}
示例2: getDeployment
func getDeployment(kubeClient *kubernetes.Clientset) (*v1beta1ext.Deployment, error) {
deployment, err := kubeClient.Extensions().Deployments(namespace).Get("deis-router")
if err != nil {
return nil, err
}
return deployment, nil
}
示例3: waitForPodsOrDie
func waitForPodsOrDie(cs *release_1_4.Clientset, ns string, n int) {
By("Waiting for all pods to be running")
err := wait.PollImmediate(framework.Poll, 10*time.Minute, func() (bool, error) {
selector, err := labels.Parse("foo=bar")
framework.ExpectNoError(err, "Waiting for pods in namespace %q to be ready", ns)
pods, err := cs.Core().Pods(ns).List(api.ListOptions{LabelSelector: selector})
if err != nil {
return false, err
}
if pods == nil {
return false, fmt.Errorf("pods is nil")
}
if len(pods.Items) < n {
framework.Logf("pods: %v < %v", len(pods.Items), n)
return false, nil
}
ready := 0
for i := 0; i < n; i++ {
if pods.Items[i].Status.Phase == apiv1.PodRunning {
ready++
}
}
if ready < n {
framework.Logf("running pods: %v < %v", ready, n)
return false, nil
}
return true, nil
})
framework.ExpectNoError(err, "Waiting for pods in namespace %q to be ready", ns)
}
示例4: getAppServices
func getAppServices(kubeClient *kubernetes.Clientset) (*v1.ServiceList, error) {
serviceClient := kubeClient.Services(api.NamespaceAll)
services, err := serviceClient.List(listOptions)
if err != nil {
return nil, err
}
return services, nil
}
示例5: buildAppConfig
func buildAppConfig(kubeClient *kubernetes.Clientset, service v1.Service, routerConfig *RouterConfig) (*AppConfig, error) {
appConfig := newAppConfig(routerConfig)
appConfig.Name = service.Labels["app"]
// If we didn't get the app name from the app label, fall back to inferring the app name from
// the service's own name.
if appConfig.Name == "" {
appConfig.Name = service.Name
}
// if app name and Namespace are not same then combine the two as it
// makes deis services (as an example) clearer, such as deis/controller
if appConfig.Name != service.Namespace {
appConfig.Name = service.Namespace + "/" + appConfig.Name
}
err := modeler.MapToModel(service.Annotations, "", appConfig)
if err != nil {
return nil, err
}
// If no domains are found, we don't have the information we need to build routes
// to this application. Abort.
if len(appConfig.Domains) == 0 {
return nil, nil
}
// Step through the domains, and decide which cert, if any, will be used for securing each.
// For each that is a FQDN, we'll look to see if a corresponding cert-bearing secret also
// exists. If so, that will be used. If a domain isn't an FQDN we will use the default cert--
// even if that is nil.
for _, domain := range appConfig.Domains {
if strings.Contains(domain, ".") {
// Look for a cert-bearing secret for this domain.
if certMapping, ok := appConfig.CertMappings[domain]; ok {
secretName := fmt.Sprintf("%s-cert", certMapping)
certSecret, err := getSecret(kubeClient, secretName, service.Namespace)
if err != nil {
return nil, err
}
if certSecret != nil {
certificate, err := buildCertificate(certSecret, domain)
if err != nil {
return nil, err
}
appConfig.Certificates[domain] = certificate
}
}
} else {
appConfig.Certificates[domain] = routerConfig.PlatformCertificate
}
}
appConfig.ServiceIP = service.Spec.ClusterIP
endpointsClient := kubeClient.Endpoints(service.Namespace)
endpoints, err := endpointsClient.Get(service.Name)
if err != nil {
return nil, err
}
appConfig.Available = len(endpoints.Subsets) > 0 && len(endpoints.Subsets[0].Addresses) > 0
return appConfig, nil
}
示例6: createPodDisruptionBudgetOrDie
func createPodDisruptionBudgetOrDie(cs *release_1_4.Clientset, ns string, minAvailable intstr.IntOrString) {
pdb := policy.PodDisruptionBudget{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Namespace: ns,
},
Spec: policy.PodDisruptionBudgetSpec{
Selector: &unversioned.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}},
MinAvailable: minAvailable,
},
}
_, err := cs.Policy().PodDisruptionBudgets(ns).Create(&pdb)
Expect(err).NotTo(HaveOccurred())
}
示例7: getSecret
func getSecret(kubeClient *kubernetes.Clientset, name string, ns string) (*v1.Secret, error) {
secretClient := kubeClient.Secrets(ns)
secret, err := secretClient.Get(name)
if err != nil {
statusErr, ok := err.(*errors.StatusError)
// If the issue is just that no such secret was found, that's ok.
if ok && statusErr.Status().Code == 404 {
// We'll just return nil instead of a found *api.Secret
return nil, nil
}
return nil, err
}
return secret, nil
}
示例8: getBuilderService
// getBuilderService will return the service named "deis-builder" from the same namespace as
// the router, but will return nil (without error) if no such service exists.
func getBuilderService(kubeClient *kubernetes.Clientset) (*v1.Service, error) {
serviceClient := kubeClient.Services(namespace)
service, err := serviceClient.Get("deis-builder")
if err != nil {
statusErr, ok := err.(*errors.StatusError)
// If the issue is just that no deis-builder was found, that's ok.
if ok && statusErr.Status().Code == 404 {
// We'll just return nil instead of a found *api.Service.
return nil, nil
}
return nil, err
}
return service, nil
}
示例9: createPodsOrDie
func createPodsOrDie(cs *release_1_4.Clientset, ns string, n int) {
for i := 0; i < n; i++ {
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: fmt.Sprintf("pod-%d", i),
Namespace: ns,
Labels: map[string]string{"foo": "bar"},
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: "busybox",
Image: "gcr.io/google_containers/echoserver:1.4",
},
},
RestartPolicy: api.RestartPolicyAlways,
},
}
_, err := cs.Pods(ns).Create(pod)
framework.ExpectNoError(err, "Creating pod %q in namespace %q", pod.Name, ns)
}
}
示例10:
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/test/e2e/framework"
)
// timeout is used for most polling/waiting activities
const timeout = 60 * time.Second
// schedulingTimeout is longer specifically because sometimes we need to wait
// awhile to guarantee that we've been patient waiting for something ordinary
// to happen: a pod to get scheduled and move into Ready
const schedulingTimeout = 5 * time.Minute
var _ = framework.KubeDescribe("DisruptionController", func() {
f := framework.NewDefaultFramework("disruption")
var ns string
var cs *release_1_4.Clientset
BeforeEach(func() {
// skip on GKE since alpha features are disabled
framework.SkipIfProviderIs("gke")
cs = f.StagingClient
ns = f.Namespace.Name
})
It("should create a PodDisruptionBudget", func() {
createPodDisruptionBudgetOrDie(cs, ns, intstr.FromString("1%"))
})
It("should update PodDisruptionBudget status", func() {
createPodDisruptionBudgetOrDie(cs, ns, intstr.FromInt(2))
示例11:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
release_1_4 "k8s.io/client-go/1.4/kubernetes"
"k8s.io/client-go/1.4/pkg/api/unversioned"
api "k8s.io/client-go/1.4/pkg/api/v1"
policy "k8s.io/client-go/1.4/pkg/apis/policy/v1alpha1"
"k8s.io/client-go/1.4/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/test/e2e/framework"
)
var _ = framework.KubeDescribe("DisruptionController", func() {
f := framework.NewDefaultFramework("disruption")
var ns string
var cs *release_1_4.Clientset
BeforeEach(func() {
// skip on GKE since alpha features are disabled
framework.SkipIfProviderIs("gke")
cs = f.StagingClient
ns = f.Namespace.Name
})
It("should create a PodDisruptionBudget", func() {
createPodDisruptionBudgetOrDie(cs, ns, intstr.FromString("1%"))
})
It("should update PodDisruptionBudget status", func() {
createPodDisruptionBudgetOrDie(cs, ns, intstr.FromInt(2))
示例12:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
release_1_4 "k8s.io/client-go/1.4/kubernetes"
"k8s.io/client-go/1.4/pkg/api/unversioned"
api "k8s.io/client-go/1.4/pkg/api/v1"
policy "k8s.io/client-go/1.4/pkg/apis/policy/v1alpha1"
"k8s.io/client-go/1.4/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/test/e2e/framework"
)
var _ = framework.KubeDescribe("DisruptionController [Feature:PodDisruptionbudget]", func() {
f := framework.NewDefaultFramework("disruption")
var ns string
var cs *release_1_4.Clientset
BeforeEach(func() {
cs = f.StagingClient
ns = f.Namespace.Name
})
It("should create a PodDisruptionBudget", func() {
pdb := policy.PodDisruptionBudget{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Namespace: ns,
},
Spec: policy.PodDisruptionBudgetSpec{
Selector: &unversioned.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}},
MinAvailable: intstr.FromString("1%"),