From b828036f9c1833a62a8a16015fe46316c5d6dae7 Mon Sep 17 00:00:00 2001 From: Ilya Dmitrichenko Date: Tue, 16 Apr 2019 09:57:19 +0100 Subject: [PATCH] Move Kubernetes version helper into `rawClient` --- pkg/ctl/utils/update_kube_proxy.go | 6 +++--- pkg/eks/eks.go | 19 ------------------- pkg/kubernetes/client.go | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/pkg/ctl/utils/update_kube_proxy.go b/pkg/ctl/utils/update_kube_proxy.go index c9b4329e962..c18cf25b4ee 100644 --- a/pkg/ctl/utils/update_kube_proxy.go +++ b/pkg/ctl/utils/update_kube_proxy.go @@ -65,15 +65,15 @@ func doUpdateKubeProxy(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg st return errors.Wrapf(err, "getting credentials for cluster %q", meta.Name) } - clientSet, err := ctl.NewStdClientSet(cfg) + rawClient, err := ctl.NewRawClient(cfg) if err != nil { return err } - cprv, err := ctl.ControlPlaneReleaseVersion(clientSet) + kubernetesVersion, err := rawClient.ServerVersion() if err != nil { return err } - return defaultaddons.UpdateKubeProxyImageTag(clientSet, cprv, false) + return defaultaddons.UpdateKubeProxyImageTag(rawClient.ClientSet(), kubernetesVersion, false) } diff --git a/pkg/eks/eks.go b/pkg/eks/eks.go index d3e71d07b94..e3bdb273139 100644 --- a/pkg/eks/eks.go +++ b/pkg/eks/eks.go @@ -7,7 +7,6 @@ import ( "strings" "time" - "github.com/blang/semver" "github.com/kris-nova/logger" "github.com/pkg/errors" @@ -83,24 +82,6 @@ func (c *ClusterProvider) ControlPlaneVersion() string { return *c.Status.cachedClusterInfo.Version } -// ControlPlaneReleaseVersion returns full release version (Kubernetes API) -// NOTE: kubernetes.Interface cannot be used here, as it is missing ServerVersion -func (c *ClusterProvider) ControlPlaneReleaseVersion(clientSet *kubernetes.Clientset) (string, error) { - v, err := clientSet.ServerVersion() - if err != nil { - return "", errors.Wrapf(err, "getting Kubernetes API version") - } - - sv, err := semver.ParseTolerant(v.GitVersion) - if err != nil { - return "", errors.Wrapf(err, "parsing Kubernetes API version") - } - - sv.Pre = nil // clear extra info - - return sv.String(), nil -} - // GetClusterVPC retrieves the VPC configuration func (c *ClusterProvider) GetClusterVPC(spec *api.ClusterConfig) error { stack, err := c.NewStackManager(spec).DescribeClusterStack() diff --git a/pkg/kubernetes/client.go b/pkg/kubernetes/client.go index ff8ed256517..1d30c6abe98 100644 --- a/pkg/kubernetes/client.go +++ b/pkg/kubernetes/client.go @@ -3,6 +3,7 @@ package kubernetes import ( "fmt" + "github.com/blang/semver" jsonpatch "github.com/evanphx/json-patch" "github.com/kris-nova/logger" "github.com/pkg/errors" @@ -17,6 +18,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/apimachinery/pkg/types" "k8s.io/cli-runtime/pkg/genericclioptions/resource" + "k8s.io/client-go/discovery" kubeclient "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" restclient "k8s.io/client-go/rest" @@ -74,6 +76,27 @@ func (c *RawClient) new() (*RawClient, error) { return c, nil } +func getServerVersion(discoveryClient discovery.DiscoveryInterface) (string, error) { + v, err := discoveryClient.ServerVersion() + if err != nil { + return "", errors.Wrapf(err, "getting Kubernetes API version") + } + + sv, err := semver.ParseTolerant(v.GitVersion) + if err != nil { + return "", errors.Wrapf(err, "parsing Kubernetes API version") + } + + sv.Pre = nil // clear extra info + + return sv.String(), nil +} + +// ServerVersion will use discovery API to fetch version of Kubernetes control plane +func (c *RawClient) ServerVersion() (string, error) { + return getServerVersion(c.ClientSet().Discovery()) +} + // ClientSet returns the underlying ClientSet func (c *RawClient) ClientSet() kubeclient.Interface { return c.clientSet }