Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyCertManagerManifests(waitForUser bool)
- func CheckIfAnyKubernetesIsRunning() bool
- func CheckIfDockerIsRunning() bool
- func ConditionsAreMet(actualConditionsMap, expectedConditionsMap map[string]interface{}) bool
- func CountPodsInNamespace(namespace string) int
- func CreateNamespace(unattendedMode bool, namespace string)
- func FindFirstPodByLabel(namespace, label string) (string, error)
- func GetDynamicKubernetesClient() *dynamic.DynamicClient
- func GetKubernetesClientSet() *kubernetes.Clientset
- func GetKubernetesConfig() *rest.Config
- func GetKubernetesConfigPath() string
- func Kubectl(unattendedMode bool, kubectlArg ...string) (*exec.Cmd, []byte, error)
- func KubectlAct(verb, flag, filepath string, waitForUser bool)
- func KubectlApplyF(yamlFilepath string, waitForUser bool)
- func KubectlApplyKustomize(kustomizeFilepath string, waitForUser bool)
- func KubectlDeleteF(yamlFilepath string, waitForUser bool)
- func KubectlDeleteFileFromPod(unattendedMode bool, namespace, podName, containerName, remoteFilename string) error
- func KubectlUploadFileToPod(unattendedMode bool, ...) error
- func KubectlWaitForPod(namespace, podLabel string)
- func KubectlWaitForSystemToBecomeReady(namespace string, expectedPodsByLabels []string)
- func WaitForCertManagerToBecomeReady()
- func WaitForKubernetesResource(namespace, name string, gvr schema.GroupVersionResource, ...) error
- func WaitForKubernetesResourceWithFunction(namespace, name string, gvr schema.GroupVersionResource, ...) error
- func WaitForServiceAccount(unattendedMode bool, namespace, serviceAccountName string)
- func WaitForSystemToBecomeReady(namespace, systemName string, expectedPods []PodExpectationState)
- type ClusterManager
- type PodExpectationState
Constants ¶
const CertManagerManifestUrl = "https://github.com/cert-manager/cert-manager/releases/download/v1.12.0/cert-manager.yaml"
const CertManagerNamespace = "cert-manager"
Variables ¶
var Creator creator.KubernetesCreator
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 ¶
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 CountPodsInNamespace ¶
https://github.com/kubernetes/client-go/blob/master/examples/in-cluster-client-configuration/main.go
func CreateNamespace ¶ added in v0.13.0
func FindFirstPodByLabel ¶
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 GetKubernetesConfigPath ¶
func GetKubernetesConfigPath() string
func KubectlAct ¶
Examples: delete postgresql {name} apply -f {path} delete -f {path}
func KubectlApplyF ¶
func KubectlApplyKustomize ¶
func KubectlDeleteF ¶
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
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
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 ¶
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.