k8s

package
v0.0.0-...-6231fe6 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 29 Imported by: 34

Documentation

Index

Constants

View Source
const PodCompletedReason = "PodCompleted"

PodCompletedReason is present in ready condition, when the pod completed successfully.

Variables

View Source
var ErrWaitingForServiceEndpoints = errors.New("waiting for service endpoints")

ErrWaitingForServiceEndpoints if waiting for service endpoints failed.

View Source
var ErrWaitingForServiceReady = errors.New("waiting for service ready")

ErrWaitingForServiceReady if waiting for service ready failed.

View Source
var (
	// WaitForPodRunningOrFail waits for pods to be ready.
	// Deprecated, use WaitForPodReadyOrSucceededOrFail
	WaitForPodRunningOrFail = WaitForPodReadyOrSucceededOrFail
)

Functions

func Address

Address attempts to resolve an Addressable address into a URL. If the resource is found but not Addressable, Address will return (nil, nil).

func GetFirstTerminationMessage

func GetFirstTerminationMessage(pod *corev1.Pod) string

func GetJobPod

func GetJobPod(ctx context.Context, kubeClientset kubernetes.Interface, namespace, uid, operation string) (*corev1.Pod, error)

GetJobPod will find the Pod that belongs to the resource that created it. Uses label ""controller-uid as the label selector. So, your job should tag the job with that label as the UID of the resource that's needing it. For example, if you create a storage object that requires us to create a notification for it, the controller should set the label on the Job responsible for creating the Notification for it with the label "controller-uid" set to the uid of the storage CR.

func GetJobPodByJobName

func GetJobPodByJobName(ctx context.Context, jobName string) (*corev1.Pod, error)

GetJobPodByJobName will find the Pods that belong to that job. Each pod for a given job will have label called: "job-name" set to the job that it belongs to, so just filter by that.

func GetOperationsResult

func GetOperationsResult(ctx context.Context, pod *corev1.Pod, result interface{}) error

func IsAddressable

func IsAddressable(gvr schema.GroupVersionResource, name string, timing ...time.Duration) feature.StepFn

IsAddressable tests to see if a resource becomes Addressable within the time given. Timing is optional but if provided is [interval, timeout].

func IsJobComplete

func IsJobComplete(job *batchv1.Job) bool

func IsJobFailed

func IsJobFailed(job *batchv1.Job) bool

func IsJobSucceeded

func IsJobSucceeded(job *batchv1.Job) bool

func IsNotReady

func IsNotReady(gvr schema.GroupVersionResource, name string, timing ...time.Duration) feature.StepFn

IsNotReady returns a reusable feature.StepFn to assert if a resource is not ready within the time given. Timing is optional but if provided is [interval, timeout].

func IsReady

func IsReady(gvr schema.GroupVersionResource, name string, timing ...time.Duration) feature.StepFn

IsReady returns a reusable feature.StepFn to assert if a resource is ready within the time given. Timing is optional but if provided is [interval, timeout].

func JobFailedMessage

func JobFailedMessage(job *batchv1.Job) string

func LogsFor

func LogsFor(client kubernetes.Interface, namespace, name string, gvr schema.GroupVersionResource) (string, error)

func PodLogs

func PodLogs(ctx context.Context, podName, containerName, namespace string) ([]byte, error)

PodLogs returns Pod logs for given Pod and Container in the namespace

func PollTimings

func PollTimings(ctx context.Context, timings []time.Duration) (time.Duration, time.Duration)

PollTimings will find the correct timings based on priority: - passed timing slice [interval, timeout]. - values from from context. - defaults.

func WaitForAddress

func WaitForAddress(ctx context.Context, gvr schema.GroupVersionResource, name string, timing ...time.Duration) (*duckv1.Addressable, error)

WaitForAddress waits until a resource has an address. Timing is optional but if provided is [interval, timeout].

func WaitForJobCondition

func WaitForJobCondition(ctx context.Context, t feature.T, name string, isConditionFunc func(job *batchv1.Job) bool, timing ...time.Duration) error

func WaitForJobTerminationMessage

func WaitForJobTerminationMessage(ctx context.Context, t feature.T, name string, timing ...time.Duration) (string, error)

WaitForJobTerminationMessage waits for a job to end and then collects the termination message. Timing is optional but if provided is [interval, timeout].

func WaitForPodReadyOrSucceededOrFail

func WaitForPodReadyOrSucceededOrFail(ctx context.Context, t feature.T, podName string)

WaitForPodReadyOrSucceededOrFail waits for the given pod to be in running state.

func WaitForReadyOrDone

func WaitForReadyOrDone(ctx context.Context, t feature.T, ref corev1.ObjectReference, timing ...time.Duration) error

WaitForReadyOrDone will wait for a resource to become ready or succeed. Timing is optional but if provided is [interval, timeout].

func WaitForReadyOrDoneOrFail

func WaitForReadyOrDoneOrFail(ctx context.Context, t feature.T, ref corev1.ObjectReference, timing ...time.Duration)

WaitForReadyOrDoneOrFail will call WaitForReadyOrDone and fail if the resource is not ready.

func WaitForResourceCondition

func WaitForResourceCondition(ctx context.Context, t feature.T, namespace, name string, gvr schema.GroupVersionResource, condition ConditionFunc, timing ...time.Duration) error

WaitForResourceCondition waits until the specified resource in the given namespace satisfies a given condition. Timing is optional but if provided is [interval, timeout].

func WaitForResourceNotReady

func WaitForResourceNotReady(ctx context.Context, t feature.T, namespace, name string, gvr schema.GroupVersionResource, timing ...time.Duration) error

WaitForResourceNotReady waits until the specified resource in the given namespace is not ready. Only the top level ready condition is considered (internal `happy` condition of knative.dev/pkg). Timing is optional but if provided is [interval, timeout].

func WaitForResourceReady

func WaitForResourceReady(ctx context.Context, t feature.T, namespace, name string, gvr schema.GroupVersionResource, timing ...time.Duration) error

WaitForResourceReady waits until the specified resource in the given namespace are ready or completed successfully. Timing is optional but if provided is [interval, timeout].

func WaitForServiceEndpoints

func WaitForServiceEndpoints(ctx context.Context, t feature.T, name string, numberOfExpectedEndpoints int) error

WaitForServiceEndpoints polls the status of the specified Service every interval until number of service endpoints >= numOfEndpoints.

func WaitForServiceEndpointsOrFail

func WaitForServiceEndpointsOrFail(ctx context.Context, t feature.T, name string, numberOfExpectedEndpoints int)

WaitForServiceEndpointsOrFail polls the status of the specified Service every interval until number of service endpoints >= numOfEndpoints.

func WaitForServiceReady

func WaitForServiceReady(ctx context.Context, t feature.T, name string, readinessPath string) error

WaitForServiceReady will deploy a job that will try to invoke a service using readiness path. This makes sure the service is ready to serve traffic, from other components. See: https://stackoverflow.com/a/59713538/844449

func WaitForServiceReadyOrFail

func WaitForServiceReadyOrFail(ctx context.Context, t feature.T, name string, readinessPath string)

WaitForServiceReadyOrFail will call WaitForServiceReady and fail if error is returned.

func WaitUntilJobDone

func WaitUntilJobDone(ctx context.Context, t feature.T, name string, timing ...time.Duration) error

WaitUntilJobDone waits until a job has finished. Timing is optional but if provided is [interval, timeout].

func WaitUntilJobFailed

func WaitUntilJobFailed(ctx context.Context, t feature.T, name string, timing ...time.Duration) error

WaitUntilJobFailed waits until a job has failed. Timing is optional but if provided is [interval, timeout].

func WaitUntilJobSucceeded

func WaitUntilJobSucceeded(ctx context.Context, t feature.T, name string, timing ...time.Duration) error

WaitUntilJobSucceeded waits until a job has succeeded. Timing is optional but if provided is [interval, timeout].

func WithDefaultPodSecurityContext

func WithDefaultPodSecurityContext(cfg map[string]interface{})

func WithEventListener

func WithEventListener(ctx context.Context, env environment.Environment) (context.Context, error)

Types

type ConditionFunc

type ConditionFunc func(resource duckv1.KResource) bool

ConditionFunc is a function that determines whether a condition on a resource is satisfied.

type EventHandler

type EventHandler interface {
	Handle(event *corev1.Event)
}

EventHandler is the callback type for the EventListener

type EventListener

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

EventListener is a type that broadcasts new k8s events to subscribed EventHandler The scope of EventListener should be global in the Environment lifecycle

func EventListenerFromContext

func EventListenerFromContext(ctx context.Context) *EventListener

func (*EventListener) AddHandler

func (el *EventListener) AddHandler(name string, handler EventHandler) int

func (*EventListener) GetHandler

func (el *EventListener) GetHandler(name string) EventHandler

func (*EventListener) Stop

func (el *EventListener) Stop()

Jump to

Keyboard shortcuts

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