k8s

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: Apache-2.0 Imports: 33 Imported by: 0

README

Kubernetes Package

This package contains the resources necessary to create a client capable of interacting with different kubernetes clusters.

The clientset for the Mattermost ClusterInstallation custom resource now resides in the mattermost-operator repository. This provides a single source of truth for ClusterInstallation objects. To change the clientset used here, first update the code in mattermost-operator and then import the changes.

More information on doing this can be found in the mattermost-operator README.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateTotalPodMilliResourceRequests added in v0.2.0

func CalculateTotalPodMilliResourceRequests(pods *corev1.PodList) (int64, int64)

CalculateTotalPodMilliResourceRequests calculates the total CPU and memory milli resource requirements of a list of pods.

Types

type ClusterResources added in v0.2.0

type ClusterResources struct {
	MilliTotalCPU    int64
	MilliUsedCPU     int64
	MilliTotalMemory int64
	MilliUsedMemory  int64
}

ClusterResources is a snapshot of a cluster's total and currently-used resources.

func (*ClusterResources) CalculateCPUPercentUsed added in v0.2.0

func (r *ClusterResources) CalculateCPUPercentUsed(additional int64) int

CalculateCPUPercentUsed calculates the CPU usage percentage of a cluster with an optional additional load. Pass in 0 to calculate the current CPU usage of the cluster.

func (*ClusterResources) CalculateMemoryPercentUsed added in v0.2.0

func (r *ClusterResources) CalculateMemoryPercentUsed(additional int64) int

CalculateMemoryPercentUsed calculates the memory usage percentage of a cluster with an optional additional load. Pass in 0 to calculate the current memory usage of the cluster.

type KubeClient

type KubeClient struct {
	Clientset           kubernetes.Interface
	ApixClientset       apixclient.Interface
	MattermostClientset mmclient.Interface
	// contains filtered or unexported fields
}

KubeClient interfaces with a Kubernetes cluster in the same way kubectl would.

func New

func New(configLocation string, logger log.FieldLogger) (*KubeClient, error)

New returns a new KubeClient for accessing the kubernetes API.

func (*KubeClient) CreateFromFile

func (kc *KubeClient) CreateFromFile(file ManifestFile) error

CreateFromFile will create the Kubernetes resources in the provided file.

The current behavior leads to the create being attempted on all resources in the provided file. An error is returned if any of the create actions failed. This process equates to running `kubectl create -f FILENAME`.

func (*KubeClient) CreateFromFiles

func (kc *KubeClient) CreateFromFiles(files []ManifestFile) error

CreateFromFiles will create Kubernetes resources from the provided manifest files.

func (*KubeClient) CreateNamespaceIfDoesNotExist

func (kc *KubeClient) CreateNamespaceIfDoesNotExist(namespaceName string) (*corev1.Namespace, error)

CreateNamespaceIfDoesNotExist creates a kubernetes namespace if it doesn't exist already.

func (*KubeClient) CreateNamespacesIfDoesNotExist

func (kc *KubeClient) CreateNamespacesIfDoesNotExist(namespaceNames []string) ([]*corev1.Namespace, error)

CreateNamespacesIfDoesNotExist creates kubernetes namespaces if they don't exist already.

Any errors will be returned immediately and the remaining namespaces will be skipped.

func (*KubeClient) CreateOrUpdateSecret

func (kc *KubeClient) CreateOrUpdateSecret(namespace string, secret *corev1.Secret) (metav1.Object, error)

CreateOrUpdateSecret creates or update a secret

func (*KubeClient) CreateSecret

func (kc *KubeClient) CreateSecret(namespaceName, secretName, secretKey, secretValue string) (*corev1.Secret, error)

CreateSecret creates kubernetes secret.

func (*KubeClient) DeleteNamespaces

func (kc *KubeClient) DeleteNamespaces(namespaceNames []string) error

DeleteNamespaces deletes kubernetes namespaces.

Any errors will be returned immediately and the remaining namespaces will be skipped.

func (*KubeClient) GetConfig added in v0.2.0

func (kc *KubeClient) GetConfig() *rest.Config

GetConfig exposes the rest.Config for use with other k8s packages.

func (*KubeClient) GetNamespaces

func (kc *KubeClient) GetNamespaces(namespaceNames []string) ([]*corev1.Namespace, error)

GetNamespaces returns a list of kubernetes namespace objects if they exist.

Any errors will be returned immediately and the remaining namespaces will be skipped.

func (*KubeClient) GetPodsFromDeployment

func (kc *KubeClient) GetPodsFromDeployment(namespace, deploymentName string) (*corev1.PodList, error)

GetPodsFromDeployment gets the pods that belong to a given deployment.

func (*KubeClient) GetSecrets

func (kc *KubeClient) GetSecrets(nameSpace string, secretsNames []string) ([]*corev1.Secret, error)

GetSecrets returns a list of kubernetes secret objects if they exist.

Any errors will be returned immediately and the remaining secrets will be skipped.

func (*KubeClient) RemoteCommand added in v0.2.0

func (kc *KubeClient) RemoteCommand(method string, url *url.URL) ([]byte, error)

RemoteCommand executes a kubernetes command against a remote cluster.

func (*KubeClient) WaitForPodRunning

func (kc *KubeClient) WaitForPodRunning(ctx context.Context, namespace, podName string) (*corev1.Pod, error)

WaitForPodRunning will poll a given kubernetes pod at a regular interval for it to enter the 'Running' state. If the pod fails to become ready before the provided timeout then an error will be returned.

type ManifestFile

type ManifestFile struct {
	Path            string
	DeployNamespace string
}

ManifestFile is a file containing kubernetes resources.

func (*ManifestFile) Basename

func (f *ManifestFile) Basename() string

Basename returns the base filename of the manifest file.

Jump to

Keyboard shortcuts

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