Documentation
¶
Overview ¶
Package testutil provides shared test helpers for building bootc CRD objects with functional options. It's used by both envtests and e2e tests.
Index ¶
- Constants
- func ControlPlaneLabels() map[string]string
- func DaemonPodsOnNode(ctx context.Context, c client.Client, nodeName string) func() ([]corev1.Pod, error)
- func FilterEventsByObject(items []eventsv1.Event, kind, name string, uid types.UID) []eventsv1.Event
- func NewK8sNode(name string, labels map[string]string, opts ...K8sNodeOption) *corev1.Node
- func NewNode(name, desiredImage string, opts ...NodeOption) *bootcv1alpha1.BootcNode
- func NewPool(name, imageRef string, opts ...PoolOption) *bootcv1alpha1.BootcNodePool
- func RestartOperator(t *testing.T, g gomega.Gomega, ctx context.Context, c client.Client, ...)
- func ShortDigest(digest string) string
- func StagePausedUpdate(t *testing.T, g gomega.Gomega, ctx context.Context, c client.Client, ...)
- func WaitForNodeIdle(t *testing.T, g gomega.Gomega, ctx context.Context, c client.Client, ...)
- func WorkerLabels() map[string]string
- type K8sNodeOption
- type NodeOption
- func WithBootedDigest(digest string) NodeOption
- func WithDesiredImageState(state bootcv1alpha1.DesiredImageState) NodeOption
- func WithNodeAnnotation(key, value string) NodeOption
- func WithNodeCondition(condType string, status metav1.ConditionStatus, reason string) NodeOption
- func WithNodeConditionAt(condType string, status metav1.ConditionStatus, reason string, at time.Time) NodeOption
- func WithNodePullSecret(name, namespace string) NodeOption
- func WithNodeRebootPolicy(p bootcv1alpha1.RebootPolicy) NodeOption
- type PoolOption
- func WithDrainTimeoutSeconds(seconds int32) PoolOption
- func WithLabel(key, value string) PoolOption
- func WithMaxUnavailable(v intstr.IntOrString) PoolOption
- func WithNodeSelector(labels map[string]string) PoolOption
- func WithPaused(paused bool) PoolOption
- func WithPullSecret(name, namespace string) PoolOption
- func WithRebootPolicy(p bootcv1alpha1.RebootPolicy) PoolOption
- func WithRebootTimeoutSeconds(seconds int32) PoolOption
- func WithWorkerSelector() PoolOption
Constants ¶
const ( ImageRepo = "quay.io/example/myos" ImageTaggedRef = ImageRepo + ":latest" DigestA = "sha256:06f961b802bc46ee168555f066d28f4f0e9afdf3f88174c1ee6f9de004fc30a0" DigestB = "sha256:c0cde77fa8fef97d476c10aad3d2d54fcc2f336140d073651c2dcccf1e379fd6" DigestC = "sha256:12f37a8a84034d3e623d726fe10e5031f4df997ac13f4d5571b5a90c41fb84fe" ImageDigestRefA = ImageRepo + "@" + DigestA ImageDigestRefB = ImageRepo + "@" + DigestB ImageDigestRefC = ImageRepo + "@" + DigestC OperatorNamespaceName = "bootc-operator" )
Test fixture values. These are not helpers per se that are any use for e2e tests, but it's a convenient global spot for now. Should probably be moved to a separate envtest-specific package.
Variables ¶
This section is empty.
Functions ¶
func ControlPlaneLabels ¶
ControlPlaneLabels returns the conventional control-plane node label map.
func DaemonPodsOnNode ¶ added in v0.2.0
func DaemonPodsOnNode( ctx context.Context, c client.Client, nodeName string, ) func() ([]corev1.Pod, error)
DaemonPodsOnNode returns a poll function listing the operator daemon pods scheduled on the given node.
func FilterEventsByObject ¶
func FilterEventsByObject( items []eventsv1.Event, kind, name string, uid types.UID, ) []eventsv1.Event
FilterEventsByObject returns events regarding the identified object.
func NewK8sNode ¶
NewK8sNode creates a corev1.Node with the given name and labels. This is strictly used by envtests since there are no nodes there.
func NewNode ¶
func NewNode(name, desiredImage string, opts ...NodeOption) *bootcv1alpha1.BootcNode
NewNode creates a BootcNode with the given name and desired image. DesiredImageState defaults to Staged. Override fields via functional options.
func NewPool ¶
func NewPool(name, imageRef string, opts ...PoolOption) *bootcv1alpha1.BootcNodePool
NewPool creates a BootcNodePool with the given name and image ref. A nodeSelector must be provided via WithNodeSelector or WithWorkerSelector. Override fields via functional options.
func RestartOperator ¶ added in v0.2.0
func RestartOperator( t *testing.T, g gomega.Gomega, ctx context.Context, c client.Client, nodeName string, )
RestartOperator deletes all operator pods (both the controller Deployment and the DaemonSet), simulating a crash or upgrade. Kubernetes recreates them as it would after an image bump. It waits for a fresh controller pod and a fresh daemon pod on the given node to be Running before returning.
func ShortDigest ¶
ShortDigest abbreviates a "sha256:<hex>" digest the same way the controller does when rendering event notes ("sha256:" plus 12 hex characters).
func StagePausedUpdate ¶ added in v0.2.0
func StagePausedUpdate( t *testing.T, g gomega.Gomega, ctx context.Context, c client.Client, pool *bootcv1alpha1.BootcNodePool, nodeName, targetRef, targetDigest, originalDigest string, )
StagePausedUpdate patches pool to targetRef with the rollout paused, then waits until nodeName has staged targetDigest while still booted on originalDigest. Pausing exposes zero reboot slots, so the controller still propagates the target and the daemon stages it, but the node parks at Staged and cannot reboot on its own — a deterministic pre-reboot window for interrupting the controller or daemon mid-rollout.
func WaitForNodeIdle ¶ added in v0.2.0
func WaitForNodeIdle( t *testing.T, g gomega.Gomega, ctx context.Context, c client.Client, nodeName string, timeout time.Duration, extraMatchers ...types.GomegaMatcher, )
WaitForNodeIdle polls a BootcNode until it reaches Idle state with Booted not nil. Extra matchers are ANDed with the base assertions, allowing callers to add checks like ImageDigest or Image.
func WorkerLabels ¶
WorkerLabels returns the conventional worker node label map.
Types ¶
type NodeOption ¶
type NodeOption func(*bootcv1alpha1.BootcNode)
NodeOption configures a BootcNode.
func WithBootedDigest ¶
func WithBootedDigest(digest string) NodeOption
WithBootedDigest sets the booted image digest in the node's status.
func WithDesiredImageState ¶
func WithDesiredImageState(state bootcv1alpha1.DesiredImageState) NodeOption
WithDesiredImageState overrides the default DesiredImageState on a node.
func WithNodeAnnotation ¶
func WithNodeAnnotation(key, value string) NodeOption
WithNodeAnnotation sets a single annotation on the node.
func WithNodeCondition ¶
func WithNodeCondition(condType string, status metav1.ConditionStatus, reason string) NodeOption
WithNodeCondition appends a condition to the node's status.
func WithNodeConditionAt ¶
func WithNodeConditionAt( condType string, status metav1.ConditionStatus, reason string, at time.Time, ) NodeOption
WithNodeConditionAt appends a condition with an explicit LastTransitionTime. Useful for exercising time-based logic such as reboot timeouts.
func WithNodePullSecret ¶
func WithNodePullSecret(name, namespace string) NodeOption
WithNodePullSecret sets the pull secret reference on a node.
func WithNodeRebootPolicy ¶ added in v0.2.0
func WithNodeRebootPolicy(p bootcv1alpha1.RebootPolicy) NodeOption
WithNodeRebootPolicy sets the reboot policy on a BootcNode.
type PoolOption ¶
type PoolOption func(*bootcv1alpha1.BootcNodePool)
PoolOption configures a BootcNodePool.
func WithDrainTimeoutSeconds ¶
func WithDrainTimeoutSeconds(seconds int32) PoolOption
WithDrainTimeoutSeconds sets the rollout drain timeout in seconds.
func WithLabel ¶
func WithLabel(key, value string) PoolOption
WithLabel sets a metadata label on the pool.
func WithMaxUnavailable ¶
func WithMaxUnavailable(v intstr.IntOrString) PoolOption
WithMaxUnavailable sets the rollout max unavailable field.
func WithNodeSelector ¶
func WithNodeSelector(labels map[string]string) PoolOption
WithNodeSelector sets the nodeSelector on a pool.
func WithPullSecret ¶
func WithPullSecret(name, namespace string) PoolOption
WithPullSecret sets the pull secret reference on a pool.
func WithRebootPolicy ¶
func WithRebootPolicy(p bootcv1alpha1.RebootPolicy) PoolOption
WithRebootPolicy sets the disruption reboot policy.
func WithRebootTimeoutSeconds ¶
func WithRebootTimeoutSeconds(seconds int32) PoolOption
WithRebootTimeoutSeconds sets the rollout reboot timeout in seconds.
func WithWorkerSelector ¶
func WithWorkerSelector() PoolOption
WithWorkerSelector sets the nodeSelector to the conventional worker node label.