utils

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CreateEventFilter is the predicate for CreateEvent only.
	CreateEventFilter = predicate.Funcs{
		CreateFunc: func(event event.CreateEvent) bool {
			return true
		},
		DeleteFunc: func(event event.DeleteEvent) bool {
			return false
		},
		UpdateFunc: func(event event.UpdateEvent) bool {
			return false
		},
		GenericFunc: func(event event.GenericEvent) bool {
			return false
		},
	}

	// DeleteEventFilter is the predicate for DeleteEvent only.
	DeleteEventFilter = predicate.Funcs{
		CreateFunc: func(event event.CreateEvent) bool {
			return false
		},
		DeleteFunc: func(event event.DeleteEvent) bool {
			return true
		},
		UpdateFunc: func(event event.UpdateEvent) bool {
			return false
		},
		GenericFunc: func(event event.GenericEvent) bool {
			return false
		},
	}

	// UpdateEventFilter is the predicate for UpdateEvent only.
	UpdateEventFilter = predicate.Funcs{
		CreateFunc: func(event event.CreateEvent) bool {
			return false
		},
		DeleteFunc: func(event event.DeleteEvent) bool {
			return false
		},
		UpdateFunc: func(event event.UpdateEvent) bool {
			return true
		},
		GenericFunc: func(event event.GenericEvent) bool {
			return false
		},
	}

	// GenericEventFilter is the predicate for GenericEvent only.
	GenericEventFilter = predicate.Funcs{
		CreateFunc: func(event event.CreateEvent) bool {
			return false
		},
		DeleteFunc: func(event event.DeleteEvent) bool {
			return false
		},
		UpdateFunc: func(event event.UpdateEvent) bool {
			return false
		},
		GenericFunc: func(event event.GenericEvent) bool {
			return true
		},
	}
)

Functions

func Date added in v0.8.0

func Date(year, month, day int) time.Time

Date returns a time.Time object with the given year, month, and day.

func DependsOn added in v0.2.5

func DependsOn(a, b corev1.EnvVar) bool

DependsOn tells if a depends on b.

func GetContainerFromPod added in v0.2.6

func GetContainerFromPod(pod *corev1.Pod, name string) *corev1.Container

GetContainerFromPod gets a pointer to the container with the same name. Nil is returned when the container isn't found.

func GetCustomResourceDefinition

func GetCustomResourceDefinition(ctx context.Context, client client.Reader, gk metav1.GroupKind) (*apiextensionsv1.CustomResourceDefinition, error)

GetCustomResourceDefinition is the helper function to get the CRD for the given group kind.

func GetNamespacedName

func GetNamespacedName(obj client.Object) types.NamespacedName

GetNamespacedName returns the NamespacedName of the given object.

func GetPortFromContainer added in v0.2.6

func GetPortFromContainer(container *corev1.Container, name string) (int32, bool)

GetPortFromContainer gets the specified port from the container. If the port's not found, it returns a false.

func GetVersionFromImage added in v0.2.6

func GetVersionFromImage(image string) string

GetVersionFromImage return the version from spec.image.

func IsAdvancedStatefulSetRolledOut added in v0.2.4

func IsAdvancedStatefulSetRolledOut(statefulSet *kruiseappsv1beta1.StatefulSet) bool

IsAdvancedStatefulSetRolledOut returns true when the OpenKruise StatefulSet is rolled out.

func IsCloneSetRolledOut added in v0.2.4

func IsCloneSetRolledOut(cloneSet *kruiseappsv1alpha1.CloneSet) bool

IsCloneSetRolledOut returns true when the OpenKruise CloneSet is rolled out.

func IsDeleted

func IsDeleted(obj client.Object) bool

IsDeleted returns true when object's deletion timestamp isn't null.

func IsDeploymentRolledOut

func IsDeploymentRolledOut(deploy *appsv1.Deployment) bool

IsDeploymentRolledOut returns true when the Deployment is rolled out.

func IsNightlyVersionAfter added in v0.8.0

func IsNightlyVersionAfter(version string, format string, date time.Time) bool

IsNightlyVersionAfter checks if the version is a nightly version and is after the given date.

func IsPodRunning added in v0.3.0

func IsPodRunning(pod *corev1.Pod) bool

IsPodRunning returns true when Pod's phase is Running.

func IsRisingWaveNightlyVersionAfter added in v0.8.0

func IsRisingWaveNightlyVersionAfter(version string, date time.Time) bool

IsRisingWaveNightlyVersionAfter checks if the version is a nightly version and is after the given date.

func IsStatefulSetRolledOut

func IsStatefulSetRolledOut(statefulSet *appsv1.StatefulSet) bool

IsStatefulSetRolledOut returns true when the StatefulSet is rolled out.

func IsVersionServingInCustomResourceDefinition

func IsVersionServingInCustomResourceDefinition(crd *apiextensionsv1.CustomResourceDefinition, version string) bool

IsVersionServingInCustomResourceDefinition returns true when the CRD serves the given version.

func MapObjectsToNames added in v0.5.4

func MapObjectsToNames[T any, TP ptrAsObject[T]](objects []T) []string

MapObjectsToNames converts a list of k8s objects to their names.

func RandomHex added in v0.8.3

func RandomHex(n int) (string, error)

RandomHex generates a random hex string of n bytes.

func TopologicalSort added in v0.2.5

func TopologicalSort(e []corev1.EnvVar)

TopologicalSort runs a topological sort on given env vars.

Types

type VolumeDeviceSlice

type VolumeDeviceSlice []corev1.VolumeDevice

VolumeDeviceSlice is a wrapper of []corev1.VolumeDevice that implements the sort.Interface.

func (VolumeDeviceSlice) Len

func (s VolumeDeviceSlice) Len() int

Len implements sort.Interface.

func (VolumeDeviceSlice) Less

func (s VolumeDeviceSlice) Less(i, j int) bool

Less implements sort.Interface.

func (VolumeDeviceSlice) Swap

func (s VolumeDeviceSlice) Swap(i, j int)

Swap implements sort.Interface.

type VolumeMountSlice

type VolumeMountSlice []corev1.VolumeMount

VolumeMountSlice is a wrapper of []corev1.VolumeMount that implements the sort.Interface.

func (VolumeMountSlice) Len

func (s VolumeMountSlice) Len() int

Len implements sort.Interface.

func (VolumeMountSlice) Less

func (s VolumeMountSlice) Less(i, j int) bool

Less implements sort.Interface.

func (VolumeMountSlice) Swap

func (s VolumeMountSlice) Swap(i, j int)

Swap implements sort.Interface.

type VolumeSlice

type VolumeSlice []corev1.Volume

VolumeSlice is a wrapper of []corev1.Volume that implements the sort.Interface.

func (VolumeSlice) Len

func (s VolumeSlice) Len() int

Len implements sort.Interface.

func (VolumeSlice) Less

func (s VolumeSlice) Less(i, j int) bool

Less implements sort.Interface.

func (VolumeSlice) Swap

func (s VolumeSlice) Swap(i, j int)

Swap implements sort.Interface.

type WebhookType added in v0.2.2

type WebhookType string

WebhookType defines an immutable type for a webhook. Use NewWebhookType to instantiate.

const (
	ValidatingWebhookType WebhookType = "validating"
	MutatingWebhookType   WebhookType = "mutating"
)

Valid webhook types.

func (WebhookType) IsMutating added in v0.2.2

func (wt WebhookType) IsMutating() bool

IsMutating is true if wt is a mutating webhook, else false.

func (WebhookType) IsValidating added in v0.2.2

func (wt WebhookType) IsValidating() bool

IsValidating is true if wt is a validating webhook, else false.

func (WebhookType) String added in v0.2.2

func (wt WebhookType) String() string

Jump to

Keyboard shortcuts

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