kubernetes

package
v0.0.0-...-546eec4 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// WatchNamespaceEnvVar is the constant for env variable WATCH_NAMESPACE
	// which is the namespace where the watch activity happens.
	// this value is empty if the operator is running with clusterScope.
	WatchNamespaceEnvVar = "WATCH_NAMESPACE"
	// PodNameEnvVar is the constant for env variable POD_NAME
	// which is the name of the current pod.
	PodNameEnvVar = "POD_NAME"
)
View Source
const (
	EventReasonResourceNotReady = "ResourceNotReady"
)

Variables

View Source
var ErrNoNamespace = fmt.Errorf("namespace not found for current environment")

ErrNoNamespace indicates that a namespace could not be found for the current environment

View Source
var ErrRunLocal = fmt.Errorf("operator run mode forced to local")

ErrRunLocal indicates that the operator is set to run in local mode (this error is returned by functions that only work on operators running in cluster mode)

View Source
var ForceRunModeEnv = "OSDK_FORCE_RUN_MODE"

ForceRunModeEnv indicates if the operator should be forced to run in either local or cluster mode (currently only used for local mode)

Functions

func AreAllPodsReady

func AreAllPodsReady(podList *corev1.PodList) bool

func ArePodIPsReady

func ArePodIPsReady(pods *corev1.PodList) bool

func ContainerIndex

func ContainerIndex(containers []corev1.Container, name string) int

func FilterPodsByOwnerUID

func FilterPodsByOwnerUID(podList *corev1.PodList, ownerId types.UID)

FilterPodsByOwnerUID Remove pods from podList not owned by the provided UID

func FindKubeConfig

func FindKubeConfig() string

FindKubeConfig returns local Kubernetes configuration

func GetContainer

func GetContainer(name string, spec *corev1.PodSpec) *corev1.Container

func GetEnvVarIndex

func GetEnvVarIndex(envVarName string, env *[]corev1.EnvVar) int

func GetOperatorImage

func GetOperatorImage(ctx context.Context, client crclient.Client) (string, error)

func GetOperatorNamespace

func GetOperatorNamespace() (string, error)

func GetOperatorPodName

func GetOperatorPodName() string

func GetOperatorPodOwnerRef

func GetOperatorPodOwnerRef(ns string, client crclient.Client, ctx context.Context) (*metav1.OwnerReference, error)

func GetPod

func GetPod(ctx context.Context, client crclient.Client, ns string) (*corev1.Pod, error)

GetPod returns a Pod object that corresponds to the pod in which the code is currently running. It expects the environment variable POD_NAME to be set by the downwards API.

func GetPodMaxMemoryUnboundedBytes

func GetPodMaxMemoryUnboundedBytes(container, podName, namespace string, kube *Kubernetes) (uint64, error)

func GetPodMemoryLimitBytes

func GetPodMemoryLimitBytes(container, podName, namespace string, kube *Kubernetes) (uint64, error)

func GetWatchNamespace

func GetWatchNamespace() (string, error)

GetWatchNamespace returns the namespace the operator should be watching for changes

func InitContainerFailed

func InitContainerFailed(containerStatuses []corev1.ContainerStatus) bool

func IsControlledByGVK

func IsControlledByGVK(refs []metav1.OwnerReference, gvk schema.GroupVersionKind) bool

func IsInitContainersEqual

func IsInitContainersEqual(srcContainer, destContainer []corev1.Container) bool

func IsOwnedBy

func IsOwnedBy(obj, owner crclient.Object) bool

func IsPodReady

func IsPodReady(pod corev1.Pod) bool

func LookupResource

func LookupResource(name, namespace string, resource, caller client.Object, client client.Client, logger logr.Logger, eventRec record.EventRecorder, ctx context.Context) (*reconcile.Result, error)

LookupResource lookup for resource to be created by separate resource controller

func SetConfigDefaults

func SetConfigDefaults(config *rest.Config, scheme *runtime.Scheme) *rest.Config

Types

type ExecOptions

type ExecOptions struct {
	Container string
	Command   []string
	Namespace string
	PodName   string
}

ExecOptions specify execution options

type Kubernetes

type Kubernetes struct {
	Client     client.Client
	RestClient rest.Interface
	RestConfig *rest.Config
}

Kubernetes abstracts interaction with a Kubernetes cluster

func NewKubernetesFromConfig

func NewKubernetesFromConfig(config *rest.Config, scheme *runtime.Scheme) (*Kubernetes, error)

NewKubernetesFromConfig creates a new Kubernetes from the Kubernetes master URL to connect to

func NewKubernetesFromController

func NewKubernetesFromController(mgr manager.Manager) *Kubernetes

NewKubernetesFromController creates a new Kubernetes instance from controller runtime Manager

func (Kubernetes) ExecWithOptions

func (k Kubernetes) ExecWithOptions(options ExecOptions) (bytes.Buffer, error)

ExecWithOptions executes command on pod command example { "/usr/bin/ls", "folderName" }

func (Kubernetes) GetExternalAddress

func (k Kubernetes) GetExternalAddress(route *corev1.Service) string

GetExternalAddress extract LoadBalancer Hostname (typically for AWS load-balancers) or IP (typically for GCE or OpenStack load-balancers) address

func (Kubernetes) GetKubernetesRESTConfig

func (k Kubernetes) GetKubernetesRESTConfig(masterURL, secretName, namespace string, logger logr.Logger, ctx context.Context) (*rest.Config, error)

func (Kubernetes) GetNodeHost

func (k Kubernetes) GetNodeHost(logger logr.Logger, ctx context.Context) (string, error)

func (Kubernetes) GetOpenShiftRESTConfig

func (k Kubernetes) GetOpenShiftRESTConfig(masterURL, secretName, namespace string, logger logr.Logger, ctx context.Context) (*rest.Config, error)

func (Kubernetes) GetSecret

func (k Kubernetes) GetSecret(secretName, namespace string, ctx context.Context) (*corev1.Secret, error)

GetSecret returns secret associated with given secret name

func (Kubernetes) GetServingCertsMode

func (k Kubernetes) GetServingCertsMode(ctx context.Context) string

GetServingCertsMode returns a label that identify the kind of serving certs service is available. Returns 'openshift.io' for service-ca on openshift

func (Kubernetes) IsGroupVersionKindSupported

func (k Kubernetes) IsGroupVersionKindSupported(gvk schema.GroupVersionKind) (bool, error)

func (Kubernetes) IsGroupVersionSupported

func (k Kubernetes) IsGroupVersionSupported(groupVersion string, kind string) (bool, error)

func (Kubernetes) Logs

func (k Kubernetes) Logs(pod, namespace string, previous bool, ctx context.Context) (logs string, err error)

func (Kubernetes) ResourcesList

func (k Kubernetes) ResourcesList(namespace string, set labels.Set, list runtime.Object, ctx context.Context) error

ResourcesList returns a typed list of resource associated with the cluster

func (Kubernetes) ResourcesListByField

func (k Kubernetes) ResourcesListByField(namespace, fieldName, fieldValue string, list runtime.Object, ctx context.Context) error

type RunModeType

type RunModeType string
const (
	LocalRunMode   RunModeType = "local"
	ClusterRunMode RunModeType = "cluster"
)

Jump to

Keyboard shortcuts

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