Kubernetes Go Client package paths

12/22/2021

How do I find what is the exact path for any sub-package of the Kubernetes Go client?

I am confused by the whole Go dependency (go get k8s.io/client-go@latest) because I see lots of equivalent/similar V1, or V1beta1 or prefixes like XXX that sometimes work some other times panic in what I perceive as an arbitrary way.

However, when I check the docs it's hard to find the information about interfaces, structure definitions and package names (the thing I am blocked on at the moment).

When I go here after many clicks: https://pkg.go.dev/k8s.io/api@v0.23.1/core/v1#Container then how do I translate this URL into a Go package? It could be the package for the Container struct, but the same for any other "Kubernetes thing".

Looking at the examples at https://github.com/kubernetes/client-go/blob/master/examples/out-of-cluster-client-configuration/main.go I found they were importing metav1 "k8s.io/apimachinery/pkg/apis/meta/v1", so I tried corev1 "k8s.io/apimachinery/pkg/apis/core/v1", but the compiler panics with

no required module provides package k8s.io/apimachinery/pkg/apis/core/v1; to add it:
        go get k8s.io/apimachinery/pkg/apis/core/v1

So I tried go mod tidy, but I get the same error.

I've also tried "k8s.io/client-go/util/core" or "k8s.io/client-go/core" - it doesn't work, but there must be a consistent rule to figure out these package names.

I was used to infer package names from the GitHub repository URLs e.g. importing github.com/kubernetes/client-go or similar, but for some reason here with Kubernetes they don't seem to be used that way.

How do I find the rules to infer package imports from those docs at those URLs at https://pkg.go.dev?

-- TPPZ
go-packages
godoc
kubernetes
kubernetes-go-client

0 Answers