Skip to content

Commit

Permalink
Move Kubernetes version helper into rawClient
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Apr 16, 2019
1 parent cbd1c9b commit b828036
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
6 changes: 3 additions & 3 deletions pkg/ctl/utils/update_kube_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
19 changes: 0 additions & 19 deletions pkg/eks/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"time"

"github.com/blang/semver"
"github.com/kris-nova/logger"
"github.com/pkg/errors"

Expand Down Expand Up @@ -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()
Expand Down
23 changes: 23 additions & 0 deletions pkg/kubernetes/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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 }

Expand Down

0 comments on commit b828036

Please sign in to comment.