diff --git a/go/kubernetes/kubernetes.go b/go/kubernetes/kubernetes.go index 3b89823..6521a0f 100644 --- a/go/kubernetes/kubernetes.go +++ b/go/kubernetes/kubernetes.go @@ -35,6 +35,9 @@ type Kubernetes struct { // inCluster dedicate whether kubernetes client in cluster inCluster bool + + // clientset reference kubernetes.Clientset + clientset *kubernetes.Clientset } type NewOption func(kubernetes *Kubernetes) error @@ -111,6 +114,7 @@ func New(options ...NewOption) (*Kubernetes, error) { if err != nil { return nil, err } + k.clientset = clientset grs, err := restmapper.GetAPIGroupResources(clientset.Discovery()) if err != nil { @@ -129,6 +133,15 @@ func New(options ...NewOption) (*Kubernetes, error) { return k, nil } +func (k *Kubernetes) Version() string { + version, err := k.clientset.Discovery().ServerVersion() + if err != nil { + return "" + } + + return version.String() +} + func (k *Kubernetes) ListNamespaces() ([]string, error) { namespaceResource, err := k.Resource("", Namespaces.String()) if err != nil { diff --git a/go/package.go b/go/package.go index 83a6d9b..6c26189 100644 --- a/go/package.go +++ b/go/package.go @@ -121,6 +121,9 @@ type ClusterResource interface { type Cluster interface { Close() error + // Version return version of cluster + Version() string + // ConfigPath return config path of cluster ConfigPath() string