k8sutil

package
v0.0.0-...-a7b7215 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: UPL-1.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const APIServerBurst = 150
View Source
const APIServerQPS = 100
View Source
const EnvVarKubeConfig = "KUBECONFIG"

EnvVarKubeConfig Name of Environment Variable for KUBECONFIG

View Source
const EnvVarTestKubeConfig = "TEST_KUBECONFIG"

EnvVarTestKubeConfig Name of Environment Variable for test KUBECONFIG

Variables

View Source
var GetAPIExtV1ClientFunc = GetAPIExtV1Client

GetAPIExtV1ClientFunc is the function to return the ApiextensionsV1Interface

View Source
var GetAppsV1Func = GetAppsV1Client

GetAppsV1Func is the function the AppsV1Interface

View Source
var GetCoreV1Func = GetCoreV1Client

GetCoreV1Func is the function to return the CoreV1Interface

View Source
var GetDynamicClientFunc = GetDynamicClient

GetDynamicClientFunc is the function to return the Dynamic Interface

NewPodExecutor is to be overridden during unit tests

Functions

func BuildKubeConfig

func BuildKubeConfig(kubeconfig string) (*rest.Config, error)

func CheckCRDsExist

func CheckCRDsExist(crdNames []string) (bool, error)

func ClearFakeClient

func ClearFakeClient()

ClearFakeClient for unit tests

func ErrorIfDeploymentExists

func ErrorIfDeploymentExists(namespace string, names ...string) error

ErrorIfDeploymentExists reports error if any of the Deployments exists

func ErrorIfServiceExists

func ErrorIfServiceExists(namespace string, names ...string) error

ErrorIfServiceExists reports error if any of the Services exists

func ExecPod

func ExecPod(client kubernetes.Interface, cfg *rest.Config, pod *v1.Pod, container string, command []string) (string, string, error)

ExecPod runs a remote command a pod, returning the stdout and stderr of the command.

func ExecPodNoTty

func ExecPodNoTty(client kubernetes.Interface, cfg *rest.Config, pod *v1.Pod, container string, command []string) (string, string, error)

ExecPodNoTty runs a remote command a pod, returning the stdout and stderr of the command.

func GetAPIExtGoClient

func GetAPIExtGoClient() (apiextv1Client.Interface, error)

GetAPIExtGoClient returns an API Extensions go-client

func GetAPIExtV1Client

func GetAPIExtV1Client() (apiextv1.ApiextensionsV1Interface, error)

GetAPIExtV1Client returns the ApiextensionsV1Interface

func GetAppsV1Client

func GetAppsV1Client(log ...vzlog.VerrazzanoLogger) (appsv1.AppsV1Interface, error)

GetAppsV1Client returns the AppsV1Interface

func GetConfigFromController

func GetConfigFromController() (*rest.Config, error)

GetConfigFromController get the config from the Controller Runtime and set the default QPS and burst.

func GetConfigOrDieFromController

func GetConfigOrDieFromController() *rest.Config

GetConfigOrDieFromController get the config from the Controller Runtime and set the default QPS and burst.

func GetCoreV1Client

func GetCoreV1Client(log ...vzlog.VerrazzanoLogger) (corev1.CoreV1Interface, error)

GetCoreV1Client returns the CoreV1Interface

func GetDynamicClient

func GetDynamicClient() (dynamic.Interface, error)

GetDynamicClient returns the Dynamic Interface

func GetDynamicClientInCluster

func GetDynamicClientInCluster(kubeconfigPath string) (dynamic.Interface, error)

GetDynamicClientInCluster returns a dynamic client needed to access Unstructured data

func GetGoClient

func GetGoClient(log ...vzlog.VerrazzanoLogger) (kubernetes.Interface, error)

GetGoClient returns a go-client

func GetKubeConfig

func GetKubeConfig() (*rest.Config, error)

GetKubeConfig Returns kubeconfig from KUBECONFIG env var if set Else from default location ~/.kube/config

func GetKubeConfigGivenPath

func GetKubeConfigGivenPath(kubeconfigPath string) (*rest.Config, error)

GetKubeConfigGivenPath GetKubeConfig will get the kubeconfig from the given kubeconfigPath

func GetKubeConfigGivenPathAndContext

func GetKubeConfigGivenPathAndContext(kubeConfigPath string, kubeContext string) (*rest.Config, error)

GetKubeConfigGivenPathAndContext returns a rest.Config given a kubeConfig and kubeContext.

func GetKubeConfigLocation

func GetKubeConfigLocation() (string, error)

GetKubeConfigLocation Helper function to obtain the default kubeConfig location

func GetKubernetesClientset

func GetKubernetesClientset() (*kubernetes.Clientset, error)

GetKubernetesClientset returns the Kubernetes clientset for the cluster set in the environment

func GetKubernetesClientsetOrDie

func GetKubernetesClientsetOrDie() *kubernetes.Clientset

GetKubernetesClientsetOrDie returns the kubernetes clientset, panic if it cannot be created.

func GetKubernetesClientsetWithConfig

func GetKubernetesClientsetWithConfig(config *rest.Config) (*kubernetes.Clientset, error)

GetKubernetesClientsetWithConfig returns the Kubernetes clientset for the given configuration

func GetKubernetesVersion

func GetKubernetesVersion() (string, error)

GetKubernetesVersion returns the version of Kubernetes cluster in which operator is deployed

func GetRunningPodForLabel

func GetRunningPodForLabel(c client.Client, label string, namespace string, log ...vzlog.VerrazzanoLogger) (*v1.Pod, error)

GetRunningPodForLabel returns the reference of a running pod that matches the given label

func GetURLForIngress

func GetURLForIngress(client client.Client, name string, namespace string, scheme string) (string, error)

GetURLForIngress returns the url for an Ingress

func IsMinimumk8sVersion

func IsMinimumk8sVersion(expectedK8sVersion string) (bool, error)

func Marshal

func Marshal(objs []unstructured.Unstructured) ([]byte, error)

Marshal a list of unstructured objects as YAML to a byte array

func MkDep

func MkDep(ns, name string) *appsv1.Deployment

func MkSvc

func MkSvc(ns, name string) *corev1.Service

func MockDynamicClient

func MockDynamicClient(objects ...runtime.Object) func() (dynamic.Interface, error)

MockDynamicClient mocks GetDynamicClient function

func MockGetAppsV1

func MockGetAppsV1(objects ...runtime.Object) func(_ ...vzlog.VerrazzanoLogger) (appsv1Cli.AppsV1Interface, error)

MockGetAppsV1 mocks GetAppsV1Client function

func MockGetCoreV1

func MockGetCoreV1(objects ...runtime.Object) func(_ ...vzlog.VerrazzanoLogger) (corev1Cli.CoreV1Interface, error)

MockGetCoreV1 mocks GetCoreV1Client function

func NewControllerRuntimeClient

func NewControllerRuntimeClient(opts client.Options) (client.Client, error)

NewControllerRuntimeClient Create a new controller runtime client

func ResetGetAPIExtV1ClientFunc

func ResetGetAPIExtV1ClientFunc()

ResetGetAPIExtV1ClientFunc for unit testing, to reset any overrides to GetAPIExtV1ClientFunc

func SetFakeClient

func SetFakeClient(client kubernetes.Interface)

SetFakeClient for unit tests

func Unmarshall

func Unmarshall(reader *bufio.Reader) ([]unstructured.Unstructured, error)

Unmarshall a reader containing YAML to a list of unstructured objects

Types

type ClientConfigFunc

type ClientConfigFunc func() (*rest.Config, kubernetes.Interface, error)
var ClientConfig ClientConfigFunc = func() (*rest.Config, kubernetes.Interface, error) {
	cfg, err := GetConfigFromController()
	if err != nil {
		return nil, nil, err
	}
	c, err := kubernetes.NewForConfig(cfg)
	if err != nil {
		return nil, nil, err
	}
	return cfg, c, nil
}

type YAMLApplier

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

func NewYAMLApplier

func NewYAMLApplier(client crtpkg.Client, namespaceOverride string) *YAMLApplier

func (*YAMLApplier) ApplyD

func (y *YAMLApplier) ApplyD(directory string) error

ApplyD applies all YAML files in a directory to Kubernetes

func (*YAMLApplier) ApplyDT

func (y *YAMLApplier) ApplyDT(directory string, args map[string]interface{}) error

ApplyDT applies a directory of file templates to Kubernetes

func (*YAMLApplier) ApplyF

func (y *YAMLApplier) ApplyF(filePath string) error

ApplyF applies a file spec to Kubernetes

func (*YAMLApplier) ApplyFT

func (y *YAMLApplier) ApplyFT(filePath string, args map[string]interface{}) error

ApplyFT applies a file template spec (go text.template) to Kubernetes

func (*YAMLApplier) ApplyFTDefaultConfig

func (y *YAMLApplier) ApplyFTDefaultConfig(filePath string, args map[string]interface{}) error

ApplyFTDefaultConfig calls ApplyFT with rest client from the default config

func (*YAMLApplier) DeleteAll

func (y *YAMLApplier) DeleteAll() error

DeleteAll deletes all objects created by the applier If you are using a YAMLApplier in a temporary context, please use defer y.DeleteAll() to clean up resources when you are done.

func (*YAMLApplier) DeleteF

func (y *YAMLApplier) DeleteF(filePath string) error

DeleteF deletes a file spec from Kubernetes

func (*YAMLApplier) DeleteFT

func (y *YAMLApplier) DeleteFT(filePath string, args map[string]interface{}) error

DeleteFT deletes a file template spec (go text.template) to Kubernetes

func (*YAMLApplier) DeleteFTDefaultConfig

func (y *YAMLApplier) DeleteFTDefaultConfig(filePath string, args map[string]interface{}) error

DeleteFTDefaultConfig calls deleteFT with rest client from the default config

func (*YAMLApplier) ObjectResultMsgs

func (y *YAMLApplier) ObjectResultMsgs() []string

ObjectResultMsgs is the list of object result messages using the ApplyX methods

func (*YAMLApplier) Objects

func (y *YAMLApplier) Objects() []unstructured.Unstructured

Objects is the list of objects created using the ApplyX methods

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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