kubexp

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2018 License: MIT Imports: 28 Imported by: 0

README

kubexp (KubeExplorer)

CircleCI codecov

kubexp is a console user interface for kubernetes. You get an efficient access and overview of kubernetes resources without much typing effort.

browse

see more features here

Setup

rbac

Your service account must have a rolebinding to cluster admin in each k8s cluster. The file rbac-default-clusteradmin.yaml contains the according clusterrolebinding for the default service account:

kubectl apply -f rbac-default-clusteradmin.yaml
configure clusters

kubexp uses ~/.kube/config to read the k8s contexts. The user of a context must have a token defined:

apiVersion: v1
clusters:
...
contexts:
...
users:
- name: ...
  user:
    # this line is needed!
    token: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9....
...

Having access to your cluster with kubectl you can add the token to your current context:

TOKEN=$(kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d '\t' | xargs)
KUBE_USER=$(kubectl config get-contexts | grep "*" | awk -v N=4 '{print $N}')
kubectl config set-credentials $KUBE_USER --token="$TOKEN"
get executable

Go to releases page and download the binary for your platform.

KUBEXP_RELEASE="v0.6.0"
wget https://github.com/alitari/kubexp/releases/download/${KUBEXP_RELEASE}/kubexp
chmod +x kubexp
command line options

Call kubexp -help

first steps

Once the ui is up, you can press h for help.

building and running

set the GOOS environment variable according your os

# setup development environment
SRCDIR=${GOPATH:-${HOME}/go}/src/github.com/alitari/ && mkdir -p $SRCDIR && cd $SRCDIR
git clone https://github.com/alitari/kubexp.git && cd kubexp
# fetch dependencies
go get -v -t -d ./...

export GOOS="linux"
# export GOOS="windows"
# build executable
./build.sh bin
# execute linux
bin/kubexp
# execute windows
# bin/kubexp.exe

# execute tests
go test main/..
running with docker

To run the kubexp container you need to mount the config file. Note, that when kubexp runs in a container the port-forward feature will not work.

docker run -it -v ~/.kube/config:/root/.kube/config alitari/kubexp:latest

Credits

  • GOCUI go framework for console user interfaces

Documentation

Index

Constants

View Source
const (
	// DecimalExponent ...
	DecimalExponent = Format("DecimalExponent") // e.g., 12e6
	// BinarySI ...
	BinarySI = Format("BinarySI") // e.g., 12Mi (12 * 2^20)
	// DecimalSI ...
	DecimalSI = Format("DecimalSI") // e.g., 12M  (12 * 10^6)
)

Variables

View Source
var (

	// ErrFormatWrong that could happen while parsing a string.
	ErrFormatWrong = errors.New("quantities must match the regular expression '" + splitREString + "'")
	// ErrNumeric ...
	ErrNumeric = errors.New("unable to parse numeric part of quantity")
	// ErrSuffix ...
	ErrSuffix = errors.New("unable to parse quantity's suffix")

	// MaxMilliValue we can represent milli-units for.
	// Compare with the return value of Quantity.Value() to
	// see if it's safe to use Quantity.MilliValue().
	MaxMilliValue = int64(((1 << 63) - 1) / 1000)
)

Functions

func Run

func Run()

Run entrypoint of the program

Types

type ClusterResourcesDef

type ClusterResourcesDef struct {
	Capacity   *NodeResourcesDef
	Alloctable *NodeResourcesDef
	Requested  *ResourcesDef
	Limit      *ResourcesDef
}

ClusterResourcesDef ...

func (*ClusterResourcesDef) PercentCPU

func (c *ClusterResourcesDef) PercentCPU() string

PercentCPU ...

func (*ClusterResourcesDef) PercentMem

func (c *ClusterResourcesDef) PercentMem() string

PercentMem ...

type Format

type Format string

Format lists the three possible formattings of a quantity.

type NodeResourcesDef

type NodeResourcesDef struct {
	ResDef ResourcesDef
	Pods   int
}

NodeResourcesDef ...

func (*NodeResourcesDef) String

func (r *NodeResourcesDef) String() string

type Quantity

type Quantity struct {
	// Amount is public, so you can manipulate it if the accessor
	// functions are not sufficient.
	Amount *inf.Dec

	// Change Format at will. See the comment for Canonicalize for
	// more details.
	Format
}

Quantity is a fixed-point representation of a number. It provides convenient marshaling/unmarshaling in JSON and YAML, in addition to String() and Int64() accessors.

The serialization format is:

<quantity> ::= <signedNumber><suffix>

(Note that <suffix> may be empty, from the "" case in <decimalSI>.)

<digit> ::= 0 | 1 | ... | 9 <digits> ::= <digit> | <digit><digits> <number> ::= <digits> | <digits>.<digits> | <digits>. | .<digits> <sign> ::= "+" | "-" <signedNumber> ::= <number> | <sign><number> <suffix> ::= <binarySI> | <decimalExponent> | <decimalSI> <binarySI> ::= Ki | Mi | Gi | Ti | Pi | Ei

(International System of units; See: http://physics.nist.gov/cuu/Units/binary.html)

<decimalSI> ::= m | "" | k | M | G | T | P | E

(Note that 1024 = 1Ki but 1000 = 1k; I didn't choose the capitalization.)

<decimalExponent> ::= "e" <signedNumber> | "E" <signedNumber>

No matter which of the three exponent forms is used, no quantity may represent a number greater than 2^63-1 in magnitude, nor may it have more than 3 decimal places. Numbers larger or more precise will be capped or rounded up. (E.g.: 0.1m will rounded up to 1m.) This may be extended in the future if we require larger or smaller quantities.

When a Quantity is parsed from a string, it will remember the type of suffix it had, and will use the same type again when it is serialized.

Before serializing, Quantity will be put in "canonical form". This means that Exponent/suffix will be adjusted up or down (with a corresponding increase or decrease in Mantissa) such that:

a. No precision is lost
b. No fractional digits will be emitted
c. The exponent (or suffix) is as large as possible.

The sign will be omitted unless the number is negative.

Examples:

1.5 will be serialized as "1500m"
1.5Gi will be serialized as "1536Mi"

NOTE: We reserve the right to amend this canonical format, perhaps to

allow 1.5 to be canonical.

TODO: Remove above disclaimer after all bikeshedding about format is over,

or after March 2015.

Note that the quantity will NEVER be internally represented by a floating point number. That is the whole point of this exercise.

Non-canonical values will still parse as long as they are well formed, but will be re-emitted in their canonical form. (So always use canonical form, or don't diff.)

This format is intended to make it difficult to use these numbers without writing some sort of special handling code in the hopes that that will cause implementors to also use a fixed point implementation.

func MustParse

func MustParse(str string) Quantity

MustParse turns the given string into a quantity or panics; for tests or others cases where you know the string is valid.

func NewMilliQuantity

func NewMilliQuantity(value int64, format Format) *Quantity

NewMilliQuantity returns a new Quantity representing the given value * 1/1000 in the given format. Note that BinarySI formatting will round fractional values, and will be changed to DecimalSI for values x where (-1 < x < 1) && (x != 0).

func NewQuantity

func NewQuantity(value int64, format Format) *Quantity

NewQuantity returns a new Quantity representing the given value in the given format.

func ParseQuantity

func ParseQuantity(str string) (*Quantity, error)

ParseQuantity turns str into a Quantity, or returns an error.

func (*Quantity) Add

func (q *Quantity) Add(y Quantity) error

Add ...

func (*Quantity) Canonicalize

func (q *Quantity) Canonicalize() (string, Suffix)

Canonicalize returns the canonical form of q and its suffix (see comment on Quantity).

Note about BinarySI:

  • If q.Format is set to BinarySI and q.Amount represents a non-zero value between -1 and +1, it will be emitted as if q.Format were DecimalSI.
  • Otherwise, if q.Format is set to BinarySI, frational parts of q.Amount will be rounded up. (1.1i becomes 2i.)

func (*Quantity) Copy

func (q *Quantity) Copy() *Quantity

Copy is a convenience function that makes a deep copy for you. Non-deep copies of quantities share pointers and you will regret that.

func (Quantity) MarshalJSON

func (q Quantity) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface.

func (*Quantity) MilliValue

func (q *Quantity) MilliValue() int64

MilliValue returns the value of q * 1000; this could overflow an int64; if that's a concern, call Value() first to verify the number is small enough.

func (*Quantity) Set

func (q *Quantity) Set(value int64)

Set sets q's value to be value.

func (*Quantity) SetMilli

func (q *Quantity) SetMilli(value int64)

SetMilli sets q's value to be value * 1/1000.

func (*Quantity) String

func (q *Quantity) String() string

String formats the Quantity as a string.

func (*Quantity) Sub

func (q *Quantity) Sub(y Quantity) error

Sub ...

func (*Quantity) UnmarshalJSON

func (q *Quantity) UnmarshalJSON(value []byte) error

UnmarshalJSON implements the json.Unmarshaller interface.

func (*Quantity) Value

func (q *Quantity) Value() int64

Value returns the value of q; any fractional part will be lost.

type ResourcesDef

type ResourcesDef struct {
	CPU    Quantity
	Memory Quantity
}

ResourcesDef ...

func (*ResourcesDef) String

func (r *ResourcesDef) String() string

type Suffix

type Suffix string

Suffix ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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