predicate

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InNamespace = func(namespace string) predicate.Predicate {
	return predicate.NewPredicateFuncs(func(obj client.Object) bool {
		return namespace == obj.GetNamespace()
	})
}

InNamespace is a predicate.Predicate that returns true if the specified client.Object is in the desired namespace.

View Source
var InstallModePredicate = func(config etc.Config) (predicate.Predicate, error) {
	mode, operatorNamespace, targetNamespaces, err := config.ResolveInstallMode()
	if err != nil {
		return nil, err
	}
	return predicate.NewPredicateFuncs(func(obj client.Object) bool {
		if mode == etc.SingleNamespace {
			return targetNamespaces[0] == obj.GetNamespace() &&
				operatorNamespace != obj.GetNamespace()
		}

		if mode == etc.MultiNamespace {
			return ext.SliceContainsString(targetNamespaces, obj.GetNamespace())
		}

		return true
	}), nil
}

InstallModePredicate is a predicate.Predicate that determines whether to reconcile the specified client.Object based on the give etc.InstallMode.

In the etc.SingleNamespace install mode we're configuring client.Client cache to watch the operator namespace, in which the operator runs scan jobs. However, we do not want to scan the workloads that might run in the operator namespace.

Similarly, in the etc.MultiNamespace install mode we're configuring client.Client cache to watch the operator namespace, in which the operator runs scan jobs. However, we do not want to scan the workloads that might run in the operator namespace unless the operator namespace is added to the list of target namespaces.

View Source
var IsConfigAuditReportScan = predicate.NewPredicateFuncs(func(obj client.Object) bool {
	if _, ok := obj.GetLabels()[kube.LabelConfigAuditReportScan]; ok {
		return true
	}
	return false
})
View Source
var IsVulnerabilityReportScan = predicate.NewPredicateFuncs(func(obj client.Object) bool {
	if _, ok := obj.GetLabels()[kube.LabelVulnerabilityReportScan]; ok {
		return true
	}
	return false
})
View Source
var JobHasAnyCondition = predicate.NewPredicateFuncs(func(obj client.Object) bool {
	if job, ok := obj.(*batchv1.Job); ok {
		return len(job.Status.Conditions) > 0
	}
	return false
})

JobHasConditions is a predicate.Predicate that returns true if the specified client.Object is a batchv1.Job with any batchv1.JobConditionType.

View Source
var ManagedByStarboardOperator = predicate.NewPredicateFuncs(func(obj client.Object) bool {
	if managedBy, ok := obj.GetLabels()["app.kubernetes.io/managed-by"]; ok {
		return managedBy == "starboard-operator"
	}
	return false
})

ManagedByStarboardOperator is a predicate.Predicate that returns true if the specified client.Object is managed by the Starboard Operator.

For example, pods controlled by jobs scheduled by Starboard Operator are labeled with `app.kubernetes.io/managed-by=starboard-operator`.

View Source
var PodBeingTerminated = predicate.NewPredicateFuncs(func(obj client.Object) bool {
	if pod, ok := obj.(*corev1.Pod); ok {
		return pod.DeletionTimestamp != nil
	}
	return false
})

PodBeingTerminated is a predicate.Predicate that returns true if the specified client.Object is a corev1.Pod that is being terminated, i.e. its DeletionTimestamp property is set to non nil value.

View Source
var PodHasContainersReadyCondition = predicate.NewPredicateFuncs(func(obj client.Object) bool {
	if pod, ok := obj.(*corev1.Pod); ok {
		for _, condition := range pod.Status.Conditions {
			if condition.Type == corev1.ContainersReady {
				return true
			}
		}
	}
	return false
})

PodHasContainersReadyCondition is a predicate.Predicate that returns true if the specified client.Object is a corev1.Pod with corev1.ContainersReady condition.

Functions

Types

This section is empty.

Jump to

Keyboard shortcuts

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