Client-go: the server could not find the requested resource

Created on 13 Apr 2017  路  1Comment  路  Source: kubernetes/client-go

Hi,

I'm currently facing this issue:

panic: the server could not find the requested resource

goroutine 1 [running]:
github.com/PrestaShop/presto-plateforme/presthost/worker/plugins.Test(0xc4201632e0, 0x17)
    /home/yann/Gopath/src/github.com/PrestaShop/presto-plateforme/presthost/worker/plugins/gke.go:21 +0x35e
github.com/PrestaShop/presto-plateforme/presthost/worker.Run(0xc4201632e0, 0x17)
    /home/yann/Gopath/src/github.com/PrestaShop/presto-plateforme/presthost/worker/main.go:10 +0xae
main.main()
    /home/yann/Gopath/src/github.com/PrestaShop/presto-plateforme/presthost/main.go:21 +0x14b

With this code

import (
    "fmt"
    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    "k8s.io/client-go/kubernetes"
    "k8s.io/client-go/rest"
    "k8s.io/client-go/kubernetes/typed/apps/v1beta1"
    _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
    "k8s.io/client-go/tools/clientcmd"
)

func Test(kubeconfig string) {
    clientset, betaclientset := initClientSets(kubeconfig)
    pods, err := clientset.CoreV1().Pods("").List(metav1.ListOptions{})
    if err != nil {
        panic(err.Error())
    }   
    deployments, err := betaclientset.Deployments("default").List(metav1.ListOptions{})
    if err != nil {
        panic(err.Error())
    }   
    fmt.Printf("There are %d deployments in the cluster\n", len(deployments.Items))
    fmt.Printf("There are %d pods in the cluster\n", len(pods.Items))
}

func initClientSets(kubeconfig string) (*kubernetes.Clientset, *v1beta1.AppsV1beta1Client) {
    config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
    if err != nil { 
        fmt.Printf("Fallback to cluter config (%s)", err.Error())
        config, err = rest.InClusterConfig()
        if err != nil { 
            panic(err.Error())
        }
    }
    clientset, err := kubernetes.NewForConfig(config)
    if err != nil {
        panic(err.Error())
    }
    betaclientset, err := v1beta1.NewForConfig(config)
    if err != nil {
        panic(err.Error())
    }
    return clientset, betaclientset
}

go-client is vendored on master, no tags. But I also tried with v3.0.0-beta.1 and the same error is returned.

This is a GKE 1.6 Kubernetes Cluster.

How do I access and creates deployments?

Thanks you !

Most helpful comment

Ok I figure it now

The cause is a Misunderstanding of the clientset. You have to use the right client for the right thing and deployments are in extensions.

deployments, err := clientset.ExtensionsV1beta1().Deployments("").List(metav1.ListOptions{}) 

My initClientSet function only have to return one clientset containing all kubernetes clients.

Thanks !

>All comments

Ok I figure it now

The cause is a Misunderstanding of the clientset. You have to use the right client for the right thing and deployments are in extensions.

deployments, err := clientset.ExtensionsV1beta1().Deployments("").List(metav1.ListOptions{}) 

My initClientSet function only have to return one clientset containing all kubernetes clients.

Thanks !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexec picture alexec  路  5Comments

mheese picture mheese  路  5Comments

narasago picture narasago  路  3Comments

protheusfr picture protheusfr  路  3Comments

tamalsaha picture tamalsaha  路  3Comments