skew

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2021 License: MIT Imports: 12 Imported by: 0

README

kubectl skew

test Go Report Card

A simple kubectl plugin to show if your kubernetes/kubectl version is "skewed"

skew-s

What's this?

With kubectl skew , you can check if your kubernetes usage meets the version skew policy.

In kubernetes, version skew policy is a bit confusing, especially for beginners.
However, it is important to make sure you are always following the policy because using unsupported cluster/kubectl is problematic and even dangerous.
In order to know if your kubernetes usage is met with it, you need to know the cluster version, client version, and current latest version. Of course, you have to understand the detail of the policy.
kubectl ver skew command helps this situation. When you run it, it automatically fetches the cluster, client, and latest version and judges if it's following the policy.
By using kubectl skew, it will be easy for you to understand if your kubernetes usage meets the policy.

Installation

Currently "krew" kubectl plugin manager installation is unsupported.

Manually via go get
go install github.com/dty1er/kubectl-skew/cmd/kubectl-skew

Usage

You simply need to run kubectl skew, which shows if there is the kubernetes cluster and kubectl versions skew.

  • cluster version problem

skew-s

  • kubectl version problem

skew-c

  • following version skew policy

skew

Upcoming releases

  • Support output option (e.g. -o json)

Contributions

Always welcome. Just opening an issue should be also greatful.

LICENSE

MIT

Documentation

Overview

Copyright © 2021 Hidetatsu Yaginuma. All rights reserved.

Copyright © 2021 Hidetatsu Yaginuma. All rights reserved.

Copyright © 2021 Hidetatsu Yaginuma. All rights reserved.

Index

Constants

This section is empty.

Variables

View Source
var InspectCurrentVersion = func() (*Versions, error) {
	versions := &Versions{}

	cmd := exec.Command("kubectl", []string{"version", "--short"}...)
	out, err := cmd.Output()
	if err != nil {
		return nil, err
	}

	idx := 0
	scanner := bufio.NewScanner(bytes.NewReader(out))
	for scanner.Scan() {
		if idx >= 2 {
			return nil, fmt.Errorf("something wrong: kubectl version --short result is more than 3 lines")
		}

		line := scanner.Text()
		splitted := strings.Split(line, ": ")
		if len(splitted) != 2 {
			return nil, fmt.Errorf("something wrong: kubectl version --short result has unexpected format")
		}

		switch idx {
		case 0:
			if splitted[0] != "Client Version" {
				return nil, fmt.Errorf("something wrong: kubectl version --short result first line is unexpected")
			}
			v, err := semver.NewVersion(splitted[1])
			if err != nil {
				return nil, err
			}
			versions.Client = v
		case 1:
			if splitted[0] != "Server Version" {
				return nil, fmt.Errorf("something wrong: kubectl version --short result second line is unexpected")
			}
			v, err := semver.NewVersion(splitted[1])
			if err != nil {
				return nil, err
			}
			versions.Server = v
		}

		idx++
	}

	if err := scanner.Err(); err != nil {
		return nil, err
	}

	if debugClient != "" {
		dcv, err := semver.NewVersion(debugClient)
		if err != nil {
			return nil, err
		}
		versions.Client = dcv
	}

	if debugServer != "" {
		dsv, err := semver.NewVersion(debugServer)
		if err != nil {
			return nil, err
		}
		versions.Server = dsv
	}

	return versions, nil
}

InspectCurrentVersion runs "kubectl version --short" and parses the result to inspect the kubectl and kubernetes cluster version. This function highly depends on the kubectl implementation, so it might be broken when kubectl makes breaking changes.

View Source
var InspectLatestVersion = func() (*semver.Version, error) {
	u := "https://dl.k8s.io/release/stable.txt"

	resp, err := http.Get(u)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	b, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}

	v, err := semver.NewVersion(string(b))
	if err != nil {
		return nil, err
	}

	return v, nil
}

Functions

func New

func NewSkewCmd

func NewSkewCmd() *cobra.Command

func RunSkew

func RunSkew(w io.Writer) error

Types

type Options

type Options struct {
	genericclioptions.IOStreams
	// contains filtered or unexported fields
}

type VersionSkew

type VersionSkew struct {
	ServerAndLatestDelta int
	ServerNeedsUpdate    bool

	ServerAndClientDelta int
	ClientNeedsUpdate    bool

	ClientNeedsDowngradeOrServerCanBeUpdated bool
}

func CalcKubeVerSkew

func CalcKubeVerSkew(latest, server, client *semver.Version) *VersionSkew

CalcKubeVerSkewClient compares given 2 versions and check if there's too big skew. First argument must be server version and second must be client's. First return is minor ver diff, second one is if it's too much. It compares their minor versions and checks if there are 2 or more difference. This is following the kubernetes official version skew policy. For more details, see the official documentation. https://kubernetes.io/docs/setup/release/version-skew-policy/

type Versions

type Versions struct {
	Client *semver.Version
	Server *semver.Version
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL