Client-go: dynamic client requested resource not found

Created on 21 Jan 2020  路  5Comments  路  Source: kubernetes/client-go

Trying to access istio crds using dynamic client, each time i access i get this error

2020/01/21 19:44:10 the server could not find the requested resource

Here is the code snippet i am trying to run

loggingRes := schema.GroupVersionResource{
        Group:    "networking.istio.io",
        Version:  "v1beta1",
        Resource: "virtualservices",
    }

    client := utils.GetKubeClientset()

    result, err := client.Resource(loggingRes).Namespace("default").Get("reviews", metav1.GetOptions{})
    if err != nil {
        log.Printf("%s", err.Error())
    }

When i switch GVR kind to deployments or native kubernetes GVR it works. Any help would be appreciated.
Here are the version i am running

BNG-188814-C02YH02XJGH8:.kube $ kubectl version
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.2", GitCommit:"66049e3b21efe110454d67df4fa62b08ea79a19b", GitTreeState:"clean", BuildDate:"2019-05-16T16:23:09Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.2", GitCommit:"66049e3b21efe110454d67df4fa62b08ea79a19b", GitTreeState:"clean", BuildDate:"2019-05-16T16:14:56Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
BNG-188814-C02YH02XJGH8:.kube $ minikube version
minikube version: v1.5.2
commit: 792dbf92a1de583fcee76f8791cff12e0c9440ad

Here is my go.mod

require (
    github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
    github.com/gorilla/mux v1.7.3
    github.com/imdario/mergo v0.3.8 // indirect
    golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
    golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
    k8s.io/apimachinery v0.17.1
    k8s.io/client-go  v12.0.0+incompatible
    k8s.io/utils v0.0.0-20200117235808-5f6fbceb4c31 // indirect
)

Most helpful comment

Verify you are using the correct resource name (kubectl api-resources will show all available resources, and you must use the plural resource name when constructing the dynamic client)

The CRD is cluster scoped

For cluster-scoped resources, omit the .Namespace("...") call

All 5 comments

is that the correct virtualservice API version? the documentation I see is v1alpha3 (e.g. https://istio.io/docs/reference/config/networking/virtual-service/)

What does kubectl api-versions output?

oh sorry it was a typo for istio, it worked for istio but not for other resources

loggingRes := schema.GroupVersionResource{
        Group:    "logging.banzaicloud.io",
        Version:  "v1beta1",
        Resource: "logging",
    }

kubectl api-versions

BNG-188814-C02YH02XJGH8:.kube adheipsingh$ kubectl api-versions
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1
apps/v1beta1
apps/v1beta2
authentication.istio.io/v1alpha1
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
autoscaling/v2beta1
autoscaling/v2beta2
batch/v1
batch/v1beta1
certificates.k8s.io/v1beta1
config.istio.io/v1alpha2
coordination.k8s.io/v1
coordination.k8s.io/v1beta1
druid.apache.org/v1alpha1
events.k8s.io/v1beta1
extensions/v1beta1
logging.banzaicloud.io/v1beta1
networking.istio.io/v1alpha3
networking.k8s.io/v1
networking.k8s.io/v1beta1
node.k8s.io/v1beta1
policy/v1beta1
rbac.authorization.k8s.io/v1
rbac.authorization.k8s.io/v1beta1
rbac.istio.io/v1alpha1
scheduling.k8s.io/v1
scheduling.k8s.io/v1beta1
security.istio.io/v1beta1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1

The CRD is cluster scoped

Verify you are using the correct resource name (kubectl api-resources will show all available resources, and you must use the plural resource name when constructing the dynamic client)

The CRD is cluster scoped

For cluster-scoped resources, omit the .Namespace("...") call

plural was the issue, i was not aware of that. Silly....

Thanks a ton @liggitt . Much Appreciated

Verify you are using the correct resource name (kubectl api-resources will show all available resources, and you must use the plural resource name when constructing the dynamic client)

The CRD is cluster scoped

For cluster-scoped resources, omit the .Namespace("...") call

Thanks @liggitt solved for me too 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gtaylor picture gtaylor  路  6Comments

ghost picture ghost  路  3Comments

strugglingyouth picture strugglingyouth  路  5Comments

jharshman picture jharshman  路  4Comments

narasago picture narasago  路  3Comments