kube

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

README

🌳 Kubernetes Helper Bonzai Command Branch

GoDoc License

Install

This command can be installed as a standalone program or composed into a Bonzai™ command tree.

Standalone

go install github.com/rwxrob/kube/cmd/kube@latest

Composed

package z

import (
	Z "github.com/rwxrob/kube/z"
	"github.com/rwxrob/kube"
)

var Cmd = &Z.Cmd{
	Name:     `z`,
	Commands: []*Z.Cmd{help.Cmd, kube.Cmd},
}

Tab Completion

To activate bash completion just use the complete -C option from your .bashrc or command line. There is no messy sourcing required. All the completion is done by the program itself.

complete -C kube kube

If you don't have bash or tab completion check use the shortcut commands instead.

Embedded Documentation

All documentation (like manual pages) has been embedded into the source code of the application. See the source or run the program with help to access it.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var Cmd = &Z.Cmd{
	Name:      `kube`,
	Summary:   `({{.Version}}) Kubernetes utility commands`,
	Version:   `v0.1.0`,
	Copyright: `Copyright 2021 Robert S Muhlestein`,
	License:   `Apache-2.0`,
	Source:    `git@github.com:rwxrob/kube.git`,
	Issues:    `github.com/rwxrob/kube/issues`,

	Commands: []*Z.Cmd{help.Cmd, contextCmd},
	MinArgs:  1,

	Description: `
		The {{cmd .Name}} commands provide user-centric utilities and tools
		for working with Kubernetes clusters and applications.
	`,
}

Functions

func CurrentContext

func CurrentContext() string

CurrentContext first loads the kubeconfig (see Config.Load) and then returns the current-context value or empty string if not found.

Example
package main

import (
	"fmt"
	"log"
	"os"
	"path/filepath"
	"strings"

	"github.com/rwxrob/kube"
)

func main() {

	path := []string{
		filepath.Join(`testdata`, `conf1.yaml`),
		filepath.Join(`testdata`, `conf2.yaml`),
	}
	pathstr := strings.Join(path, string(filepath.ListSeparator))
	log.Println(pathstr)
	orig := os.Getenv(`KUBECONFIG`)
	os.Setenv(`KUBECONFIG`, pathstr)
	defer func() {
		if orig != "" {
			os.Setenv(`KUBECONFIG`, orig)
		}
	}()

	fmt.Println(kube.CurrentContext())

}
Output:

foo

func DefConfFile

func DefConfFile() string

DefConfFile returns the full path to the default config file depending on the OS. Returns empty if nothing found.

Types

type Config

type Config struct {
	O map[string]any `yaml:",inline"`
}

func (*Config) Load

func (c *Config) Load() error

Load follows the same conventions as kubectl for loading Kubernetes configuration YAML data, first from all files in any KUBECONFIG environment variable path are loaded with the values of the last file having priority over those before it. If KUBECONFIG is not set or empty then .kube/config file in the users' home directory is loaded instead. Any files that do not exist are silently ignored.

Example (Kubeconfig)
package main

import (
	"fmt"
	"log"
	"os"
	"path/filepath"
	"strings"

	"github.com/rwxrob/kube"
)

func main() {

	path := []string{
		filepath.Join(`testdata`, `conf1.yaml`),
		filepath.Join(`testdata`, `conf2.yaml`),
	}
	pathstr := strings.Join(path, string(filepath.ListSeparator))
	log.Println(pathstr)
	orig := os.Getenv(`KUBECONFIG`)
	os.Setenv(`KUBECONFIG`, pathstr)
	defer func() {
		if orig != "" {
			os.Setenv(`KUBECONFIG`, orig)
		}
	}()

	c := kube.Config{}
	c.Load()
	fmt.Println(c.O[`current-context`])

}
Output:

foo

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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