havener

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: MIT Imports: 49 Imported by: 0

Documentation

Overview

Package havener is a convenience layer to handle Containerized CF tasks on a Kubernetes cluster, e.g. deploy, or upgrade.

It provides functions that wrap Kubernetes API calls (client-go) or Helm client calls, or even both, to help with everyday tasks on a Kubernetes cluster that runs Cloud Foundry in its containerized version. However, it is not limited to this kind of workload.

Index

Constants

View Source
const (
	Off = LogLevel(iota)
	Fatal
	Error
	Warn
	Verbose
	Debug
	Trace
)

Supported log levels include: - Off: don't print any logs - Fatal: only print fatal logs - Error: print error logs and previous levels - Warn: print warn logs and previous levels - Verbose: print verbose/info logs and previous levels - Debug: print debug logs and previous levels - Trace: print all logs

View Source
const LogDirName = "retrieved-logs"

LogDirName is the subdirectory name where retrieved logs are stored

Variables

This section is empty.

Functions

func AddShutdownFunction added in v1.0.0

func AddShutdownFunction(f func())

AddShutdownFunction adds a function to be called in case GracefulShutdown is called, for example to clean up resources.

func GenerateConfigFile added in v0.18.0

func GenerateConfigFile(valueOverrides []byte) (string, error)

GenerateConfigFile wil dump config bytes into a tmp file

func GetCert

func GetCert(certificate string) (*x509.Certificate, error)

GetCert gets a certificate and checks if it's valid

func GetCertificateFromSecret

func GetCertificateFromSecret(datamap map[string][]uint8, namespace string, secret string) map[string]*VerifiedCert

GetCertificateFromSecret looks for certificates inside the secrets and checks if they're valid

func GetLogChannel added in v1.0.0

func GetLogChannel() chan LogMessage

GetLogChannel return the log channel to be used within the internal package.

func GracefulShutdown added in v1.0.0

func GracefulShutdown()

GracefulShutdown brings down the havener package by going through registered on-shutdown functions.

func HomeDir

func HomeDir() string

HomeDir returns the HOME env key

func HumanReadableSize

func HumanReadableSize(bytes int64) string

HumanReadableSize returns the human readable version of a byte value. Values over 1024 TiB are currently not supported.

func ListDeploymentsInNamespace

func ListDeploymentsInNamespace(client kubernetes.Interface, namespace string) ([]string, error)

ListDeploymentsInNamespace returns all names of deployments in the given namespace

func ListNamespaces

func ListNamespaces(client kubernetes.Interface) ([]string, error)

ListNamespaces lists all namespaces

func ListNodes added in v1.0.0

func ListNodes(client kubernetes.Interface) ([]string, error)

ListNodes lists all nodes of the cluster Deprecated: Use Havener interface function ListNodeNames instead

func ListPods added in v0.12.0

func ListPods(client kubernetes.Interface) ([]*corev1.Pod, error)

ListPods lists all pods in all namespaces Deprecated: Use Havener interface function ListPods instead

func ListSecretsInNamespace

func ListSecretsInNamespace(client kubernetes.Interface, namespace string) ([]string, error)

ListSecretsInNamespace lists all secrets in a given namespace

func ListStatefulSetsInNamespace

func ListStatefulSetsInNamespace(client kubernetes.Interface, namespace string) ([]string, error)

ListStatefulSetsInNamespace returns all names of stateful sets in the given namespace

func MinutesToSeconds

func MinutesToSeconds(minutes int) int

MinutesToSeconds returns the amount of seconds

func OutOfClusterAuthentication

func OutOfClusterAuthentication(kubeConfig string) (*kubernetes.Clientset, *rest.Config, error)

OutOfClusterAuthentication for kube authentication from the outside

func PathToHelmChart

func PathToHelmChart(input string) (string, error)

PathToHelmChart returns an absolute path to the location of the Helm Chart directory refereced by the input string. In case the path cannot be found locally in the file system, Git repositories containing curated lists of Helm Charts will be cloned into the Havener app directory and searched for the provided location, too.

func ProcessOperators added in v1.0.0

func ProcessOperators(s string) (string, error)

ProcessOperators processes the input string and calls all operator checks.

func PurgeDeploymentsInNamespace

func PurgeDeploymentsInNamespace(kubeClient kubernetes.Interface, namespace string) error

PurgeDeploymentsInNamespace removes all deployments in the given namespace.

func PurgeNamespace

func PurgeNamespace(kubeClient kubernetes.Interface, namespace string) error

PurgeNamespace removes the namespace from the cluster.

func PurgePod added in v1.0.0

func PurgePod(kubeClient kubernetes.Interface, namespace string, podName string, gracePeriodSeconds int64, propagationPolicy metav1.DeletionPropagation) error

PurgePod removes the pod in the given namespace.

func PurgeStatefulSetsInNamespace

func PurgeStatefulSetsInNamespace(kubeClient kubernetes.Interface, namespace string) error

PurgeStatefulSetsInNamespace removes all stateful sets in the given namespace.

func SecretsInNamespace added in v1.0.0

func SecretsInNamespace(client kubernetes.Interface, namespace string) ([]corev1.Secret, error)

SecretsInNamespace lists all secrets in a given namespace

func SetConfigEnv added in v1.0.0

func SetConfigEnv(config *Config) error

SetConfigEnv processes the env operators of the config and sets them as environmental variables

func TraverseStructureAndProcessOperators added in v1.0.0

func TraverseStructureAndProcessOperators(input interface{}) (interface{}, error)

TraverseStructureAndProcessOperators traverses the provided generic structure and processes all string leafs.

func VerifyCertExpirations

func VerifyCertExpirations() ([][]string, error)

VerifyCertExpirations checks all certificates in all secrets in all namespaces

func VerifyHelmBinary added in v0.18.0

func VerifyHelmBinary() error

VerifyHelmBinary checks if the helm binary is available on your host.

Types

type Config

type Config struct {
	Name     string        `yaml:"name"`
	Releases []Release     `yaml:"releases"`
	Env      yaml.MapSlice `yaml:"env,omitempty"`
	Before   *Task         `yaml:"before,omitempty"`
	After    *Task         `yaml:"after,omitempty"`
}

Config is the Havener configuration main structure contract.

func ParseConfigFile added in v1.0.0

func ParseConfigFile(path string) (*Config, error)

ParseConfigFile reads the havener config file, unmarshals it and returns the resulting Config structure.

func ProcessConfigFile

func ProcessConfigFile(path string) (*Config, error)

ProcessConfigFile reads the havener config file from the provided path and returns the processed input file. Any shell operator will be evaluated.

type ContainerDetails added in v1.1.0

type ContainerDetails struct {
	Nodename   string
	UsedCPU    int64
	UsedMemory int64
}

ContainerDetails consists of the used values for CPU and Memory of a pod container plus the name of the cluster node it runs on

type Havener added in v1.1.0

type Havener interface {
	Client() kubernetes.Interface
	RESTConfig() *rest.Config
	ClusterName() string

	ListHelmReleases() ([]HelmRelease, error)
	DeployHelmRelease(chartname string, namespace string, chartPath string, timeOut int, valueOverrides []byte) error
	GetReleaseMessage(release Release, message string) (string, error)
	RunHelmBinary(args ...string) ([]byte, error)
	GetReleaseByName(releaseName string) (HelmRelease, error)
	PurgeHelmRelease(release HelmRelease, helmRelease string) error
	PurgeHelmReleaseByName(name string) error
	UpdateHelmRelease(chartname string, chartPath string, valueOverrides []byte, reuseVal bool) error

	ListPods(namespaces ...string) ([]*corev1.Pod, error)
	ListNodes() ([]corev1.Node, error)
	ListSecrets(namespaces ...string) ([]*corev1.Secret, error)
	ListConfigMaps(namespaces ...string) ([]*corev1.ConfigMap, error)
	ListCustomResourceDefinition(string) ([]unstructured.Unstructured, error)

	TopDetails() (*TopDetails, error)
	RetrieveLogs(parallelDownloads int, target string, includeConfigFiles bool) error

	PodExec(pod *corev1.Pod, container string, command []string, stdin io.Reader, stdout io.Writer, stderr io.Writer, tty bool) error
	NodeExec(node corev1.Node, containerImage string, timeoutSeconds int, command []string, stdin io.Reader, stdout io.Writer, stderr io.Writer, tty bool) error
}

Havener is an interface to work with a cluster through the havener abstraction layer

type HelmRelease added in v1.3.0

type HelmRelease struct {
	Name       string `json:"Name"`
	Revision   int    `json:"Revision"`
	Updated    string `json:"Updated"`
	Status     string `json:"Status"`
	Chart      string `json:"Chart"`
	AppVersion string `json:"AppVersion"`
	Namespace  string `json:"Namespace"`
}

HelmRelease defines the release metadata

type HelmReleases added in v0.18.0

type HelmReleases struct {
	Next     string        `json:"Next"`
	Releases []HelmRelease `json:"Releases"`
}

HelmReleases defines the struct when listing releases via helm in json format

type Hvnr added in v1.1.0

type Hvnr struct {
	// contains filtered or unexported fields
}

Hvnr is the internal handle to consolidate required cluster access variables

func NewHavener added in v1.1.0

func NewHavener(kubeConfigs ...string) (*Hvnr, error)

NewHavener returns a new Havener handle to perform cluster actions

func NewHavenerFromFields added in v1.5.1

func NewHavenerFromFields(client kubernetes.Interface, restconfig *rest.Config, clusterName string, kubeConfigPath string) *Hvnr

NewHavenerFromFields returns a new Havener handle using the provided input arguments (use for unit testing only)

func (*Hvnr) Client added in v1.4.0

func (h *Hvnr) Client() kubernetes.Interface

Client returns the Kubernetes interface client for the configured cluster

func (*Hvnr) ClusterName added in v1.1.0

func (h *Hvnr) ClusterName() string

ClusterName returns the name of the currently configured cluster

func (*Hvnr) DeployHelmRelease added in v1.5.0

func (h *Hvnr) DeployHelmRelease(chartname string, namespace string, chartPath string, timeOut int, valueOverrides []byte) error

DeployHelmRelease will initialize a helm in both client and server

func (*Hvnr) GetReleaseByName added in v1.5.0

func (h *Hvnr) GetReleaseByName(releaseName string) (HelmRelease, error)

GetReleaseByName returns true for an existing release

func (*Hvnr) GetReleaseMessage added in v1.5.0

func (h *Hvnr) GetReleaseMessage(release Release, message string) (string, error)

GetReleaseMessage combines a custom message with the release notes from the helm binary.

func (*Hvnr) ListConfigMaps added in v1.4.0

func (h *Hvnr) ListConfigMaps(namespaces ...string) (result []*corev1.ConfigMap, err error)

ListConfigMaps lists all confimaps in the given namespaces, if no namespace is given, then all namespaces currently available in the cluster will be used

func (*Hvnr) ListCustomResourceDefinition added in v1.4.0

func (h *Hvnr) ListCustomResourceDefinition(crdName string) (result []unstructured.Unstructured, err error)

ListCustomResourceDefinition lists all instances of an specific CRD

func (*Hvnr) ListHelmReleases added in v1.5.0

func (h *Hvnr) ListHelmReleases() ([]HelmRelease, error)

ListHelmReleases lists all known Helm Releases

func (*Hvnr) ListNodeNames added in v1.4.0

func (h *Hvnr) ListNodeNames() ([]string, error)

ListNodeNames returns a list of the names of the nodes in the cluster

func (*Hvnr) ListNodes added in v1.4.0

func (h *Hvnr) ListNodes() ([]corev1.Node, error)

ListNodes returns a list of the nodes in the cluster

func (*Hvnr) ListPods added in v1.1.0

func (h *Hvnr) ListPods(namespaces ...string) (result []*corev1.Pod, err error)

ListPods lists all pods in the given namespaces, if no namespace is given, then all namespaces currently available in the cluster will be used

func (*Hvnr) ListSecrets added in v1.4.0

func (h *Hvnr) ListSecrets(namespaces ...string) (result []*corev1.Secret, err error)

ListSecrets lists all secrets in the given namespaces, if no namespace is given, then all namespaces currently available in the cluster will be used

func (*Hvnr) NodeExec added in v1.4.0

func (h *Hvnr) NodeExec(node corev1.Node, containerImage string, timeoutSeconds int, command []string, stdin io.Reader, stdout io.Writer, stderr io.Writer, tty bool) error

NodeExec executes the provided command on the given node.

func (*Hvnr) PodExec added in v1.4.0

func (h *Hvnr) PodExec(pod *corev1.Pod, container string, command []string, stdin io.Reader, stdout io.Writer, stderr io.Writer, tty bool) error

PodExec executes the provided command in the referenced pod's container.

func (*Hvnr) PurgeHelmRelease added in v1.5.0

func (h *Hvnr) PurgeHelmRelease(release HelmRelease, helmRelease string) error

PurgeHelmRelease removes the given helm release including all its resources.

func (*Hvnr) PurgeHelmReleaseByName added in v1.5.0

func (h *Hvnr) PurgeHelmReleaseByName(name string) error

PurgeHelmReleaseByName purges the helm release with the given name

func (*Hvnr) RESTConfig added in v1.4.0

func (h *Hvnr) RESTConfig() *rest.Config

RESTConfig returns the REST config handle for the configured cluster

func (*Hvnr) ReleaseExist added in v1.5.0

func (h *Hvnr) ReleaseExist(list HelmReleases, releaseName string) bool

ReleaseExist returns true for an existing release

func (*Hvnr) RetrieveLogs added in v1.4.0

func (h *Hvnr) RetrieveLogs(parallelDownloads int, target string, includeConfigFiles bool) error

RetrieveLogs downloads log and configuration files from some well known location of all the pods of all the namespaces and stored them in the local file system.

func (*Hvnr) RunHelmBinary added in v1.5.0

func (h *Hvnr) RunHelmBinary(args ...string) ([]byte, error)

RunHelmBinary will execute helm with the provided arguments.

func (*Hvnr) TopDetails added in v1.1.0

func (h *Hvnr) TopDetails() (*TopDetails, error)

TopDetails retrieves top statistics and data of Kubernetes resources

func (*Hvnr) UpdateHelmRelease added in v1.5.0

func (h *Hvnr) UpdateHelmRelease(chartname string, chartPath string, valueOverrides []byte, reuseVal bool) error

UpdateHelmRelease will upgrade an existing release with provided override values

type LogLevel added in v1.0.0

type LogLevel int

LogLevel indicates the priority level of the log message which can be used for filtering

type LogMessage added in v1.0.0

type LogMessage struct {
	Message string
	Level   LogLevel
	Date    time.Time
}

LogMessage is a helper structure for transmitting log messages to the logger

type NoHelmChartFoundError

type NoHelmChartFoundError struct {
	Location string
}

NoHelmChartFoundError means that no Helm Charts were found at a given location

func (*NoHelmChartFoundError) Error

func (e *NoHelmChartFoundError) Error() string

type NodeDetails added in v1.1.0

type NodeDetails struct {
	UsedCPU     int64
	TotalCPU    int64
	UsedMemory  int64
	TotalMemory int64
	LoadAvg     []float64
}

NodeDetails consists of the used and total values for CPU and Memory

type Release

type Release struct {
	ChartName      string      `yaml:"name"`
	ChartNamespace string      `yaml:"namespace"`
	ChartLocation  string      `yaml:"location"`
	ChartVersion   string      `yaml:"version"`
	Overrides      interface{} `yaml:"overrides"`
	Before         *Task       `yaml:"before,omitempty"`
	After          *Task       `yaml:"after,omitempty"`
}

Release is the Havener configuration Helm Release abstraction, which consists of the Havener specific additional details, e.g. Overrides.

type Task

type Task []interface{}

Task is the obviously relative generic definition of a list of steps to be evaluated. A task can be configured before and/or after a deployment. Furthermore, a task can also be configured before and/or after each release.

type TopDetails added in v1.1.0

type TopDetails struct {
	sync.Mutex
	Nodes      map[string]NodeDetails
	Containers map[string]map[string]map[string]ContainerDetails
}

TopDetails contains the top statistics and data of Kubernetes resources

type VerifiedCert

type VerifiedCert struct {
	Cert  *x509.Certificate
	Error error
}

VerifiedCert is a struct with a parsed X.509 and/or an error if it cannot be parsed and verification failed

Jump to

Keyboard shortcuts

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