k8s

package
v0.44.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: Apache-2.0 Imports: 42 Imported by: 1

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

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

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

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

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
	MattermostClientsetV1Alpha mmclientv1alpha1.Interface
	MattermostClientsetV1Beta  mmclientv1beta1.Interface
	KubeagClientSet            kubeagclient.Interface
	// contains filtered or unexported fields
}

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

func NewFromConfig

func NewFromConfig(config *rest.Config, logger log.FieldLogger) (*KubeClient, error)

NewFromConfig takes in an already created Kubernetes config object, and returns a KubeClient for accessing the kubernetes API

func NewFromFile

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

NewFromFile returns a new KubeClient for accessing the kubernetes API. (previously named 'New')

func (*KubeClient) CreateFromFile

func (kc *KubeClient) CreateFromFile(file ManifestFile, installationName string) 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) CreateOrUpdateNamespace

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

CreateOrUpdateNamespace creates or update a namespace

func (*KubeClient) CreateOrUpdateNamespaces

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

CreateOrUpdateNamespaces creates or update kubernetes namespaces

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) 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

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) GetPodsFromDaemonSet

func (kc *KubeClient) GetPodsFromDaemonSet(namespace, daemonSetName string) (*corev1.PodList, error)

GetPodsFromDaemonSet gets the pods that belong to a given daemonset.

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) GetPodsFromStatefulset

func (kc *KubeClient) GetPodsFromStatefulset(namespace, statefulSetName string) (*corev1.PodList, error)

GetPodsFromStatefulset gets the pods that belong to a given stateful set.

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

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

RemoteCommand executes a kubernetes command against a remote cluster.

func (*KubeClient) UpdateStorageClassVolumeBindingMode

func (kc *KubeClient) UpdateStorageClassVolumeBindingMode(class string) (metav1.Object, error)

UpdateStorageClassVolumeBindingMode updates the storage class volume binding mode from immediate to WaitForFirstConsumer.

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