k8s

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const CertManagerManifestUrl = "https://github.com/cert-manager/cert-manager/releases/download/v1.12.0/cert-manager.yaml"

TODO Make version configurable

View Source
const CertManagerNamespace = "cert-manager"

Variables

View Source
var ErrNotFound = errors.New("resource was not found")

Functions

func ApplyCertManagerManifests

func ApplyCertManagerManifests(waitForUser bool)

func CheckIfAnyKubernetesIsRunning

func CheckIfAnyKubernetesIsRunning() bool

Verifies if there's a Kubernetes cluster. Does not verify whether it is the intended Kubernetes cluster.

func CheckIfDockerIsRunning

func CheckIfDockerIsRunning() bool

func ConditionsAreMet

func ConditionsAreMet(actualConditionsMap, expectedConditionsMap map[string]interface{}) bool

Verifies whether the key-value pairs of expectedConditionsMap are contained in actualConditionsMap.

The actualConditionsMap is a single record of a conditions array similar to:

map[lastTransitionTime:2024-01-03T07:04:28Z message:Restore object has been created reason:Initialized status:False type:PermanentlyFailed]

The ConditionsAreMet function has to be applied against all condition entries, each being a condition map.

func CreateNamespace added in v0.13.0

func CreateNamespace(unattendedMode bool, namespace string)

func FindFirstPodByLabel

func FindFirstPodByLabel(namespace, label string) (string, error)

Executes similar to: kubectl get pods -n default -l 'a8s.a9s/replication-role=master,a8s.a9s/dsi-group=postgresql.anynines.com,a8s.a9s/dsi-kind=Postgresql,a8s.a9s/dsi-name=clustered' -o=jsonpath='{.items[*].metadata.name}'

func GetDynamicKubernetesClient

func GetDynamicKubernetesClient() *dynamic.DynamicClient

See: https://github.com/kubernetes/client-go > dynamic. A dynamic client can perform generic operations on arbitrary Kubernetes API objects.

func GetKubernetesClientSet

func GetKubernetesClientSet() *kubernetes.Clientset

func GetKubernetesConfig

func GetKubernetesConfig() *rest.Config

func GetKubernetesConfigPath

func GetKubernetesConfigPath() string

func Kubectl

func Kubectl(unattendedMode bool, kubectlArg ...string) (*exec.Cmd, []byte, error)

Variadic function to use kubectl.

Returns: cmd, output, err

func KubectlAct

func KubectlAct(verb, flag, filepath string, waitForUser bool)

Examples: delete postgresql {name} apply -f {path} delete -f {path}

func KubectlApplyF

func KubectlApplyF(yamlFilepath string, waitForUser bool)

func KubectlApplyKustomize

func KubectlApplyKustomize(kustomizeFilepath string, waitForUser bool)

func KubectlDeleteF

func KubectlDeleteF(yamlFilepath string, waitForUser bool)

func KubectlDeleteFileFromPod

func KubectlDeleteFileFromPod(unattendedMode bool, namespace, podName, containerName, remoteFilename string) error

Deletes a file in the remote pod/container. Executes command similar to: kubectl exec solo-0 -n default -c postgres -- rm /tmp/demo.sql

func KubectlUploadFileToPod

func KubectlUploadFileToPod(unattendedMode bool, namespace, podName, containerName, fileToUpload, remoteTargetFolder string) error

Uploads the given file to the given container in the given pod to the given remote target folder.

Example kubectl command: kubectl cp demo_data.sql default/clustered-0:/home/postgres -c postgres

func KubectlWaitForPod added in v0.13.0

func KubectlWaitForPod(namespace, podLabel string)

func KubectlWaitForSystemToBecomeReady added in v0.13.0

func KubectlWaitForSystemToBecomeReady(namespace string, expectedPodsByLabels []string)

Uses kubectl wait to wait for each expected pod to become ready. Pods are identified by label and namespace.

func WaitForCertManagerToBecomeReady

func WaitForCertManagerToBecomeReady()

func WaitForKubernetesResource

func WaitForKubernetesResource(namespace, name string, gvr schema.GroupVersionResource, desiredConditionsMap map[string]interface{}, failedConditionsMap map[string]interface{}) error

Wait for a Kubernetes resource to reach either a desired or failed state.

Namespace Name: name of the object to wait for, e.g. name of the backup The desiredConditionsMap contains the conditions to indicate success while the failedConditionsMap contains the conditions to indicate failure.

Example:

gvr := schema.GroupVersionResource{Group: "backups.anynines.com", Version: "v1beta3", Resource: "backups"}

desiredConditionsMap := make(map[string]interface{}) desiredConditionsMap["reason"] = "Complete" desiredConditionsMap["status"] = "True"

failedConditionsMap := make(map[string]interface{}) failedConditionsMap["reason"] = "PermanentlyFailed" failedConditionsMap["status"] = "True"

TODO

  • Refactor using WaitForKubernetesResourceWithFunction
  • Rename WaitForKubernetesResourceWithFunction to WaitForKubernetesResource

func WaitForKubernetesResourceWithFunction

func WaitForKubernetesResourceWithFunction(namespace, name string, gvr schema.GroupVersionResource, waitLonger func(object *m1u.Unstructured) bool) error

name refers to the metadata.name value of the object of interest.

waitLonger is a function describing what to wait for covering both success and failure scenarios. It returns true if waiting shall go on and false if the awaited event has happened.g

func WaitForServiceAccount added in v0.13.0

func WaitForServiceAccount(unattendedMode bool, namespace, serviceAccountName string)

Wait for the given service account in the given namespace to become ready. Blocks during wait.

func WaitForSystemToBecomeReady

func WaitForSystemToBecomeReady(namespace, systemName string, expectedPods []PodExpectationState)

Wait for a set of Pods known by name to enter the status "Running".

Types

type ClusterManager

type ClusterManager struct {
	ClusterName    string                    // name of the cluster
	Creator        creator.KubernetesCreator // e.g. creator.KindCreator
	CreatorName    string                    // "kind", "minikube"
	UnattendedMode bool                      // false > Ask user for feedback inbetween steps
	WorkDir        string                    // general working directory, e.g. where to store kind manifests
}

func BuildClusterManager

func BuildClusterManager(workDir, name, creatorName string, unattendedMode bool) ClusterManager

ClusterManager factory function.

Build a ClusterManager instance.

func (*ClusterManager) CreateKubernetesClusterIfNotExists

func (m *ClusterManager) CreateKubernetesClusterIfNotExists(spec creator.KubernetesClusterSpec)

func (*ClusterManager) DeleteKubernetesCluster

func (m *ClusterManager) DeleteKubernetesCluster()

func (*ClusterManager) IsClusterSelectedAsCurrentContext

func (m *ClusterManager) IsClusterSelectedAsCurrentContext(clusterName string) bool

Checks whether given cluster is also set as the current context. This ensures that subsequent actions are applied to the correct Kubernetes cluster.

type PodExpectationState

type PodExpectationState struct {
	Name    string
	Running bool
}

Represents the state of a Pod which is expected to be running at some point. The attribute "Running" is meant to be updated by a control loop.

Jump to

Keyboard shortcuts

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