scenarios

package
v0.57.4 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultKwokMarker = "kwok.x-k8s.io/node"
	KwokMarkerValue   = "fake"
)

Variables

This section is empty.

Functions

func Deployment added in v0.57.2

func Deployment(name string) *appsv1.Deployment

Deployment creates a deployment that can run on kwok nodes in the default namespace.

func DeploymentWithStuckPDB

func DeploymentWithStuckPDB(deploymentName string) (*appsv1.Deployment, *policyv1.PodDisruptionBudget)

DeploymentWithStuckPDB creates a 1-replica deployment with "stuck PDB" that is never satisfiable, i.e. no pods can be evicted. Deployment cannot run in reality, it uses fake container. Deployment deploys on kwok fake nodes by default.

func NewKwokNode

func NewKwokNode(cfg KwokConfig, nodeName string) *corev1.Node

NewKwokNode creates a fake node with reasonable defaults. Can be customized but the marker label/annotation must be present. Tainted by default with DefaultKwokMarker to avoid running real pods on it. Requires that a kwok-controller is running to actually simulate the node on apply.

func Pod added in v0.57.2

func Pod(name string) *corev1.Pod

Pod returns a pod that can run on kwok nodes in the default namespace.

func RunScenario

func RunScenario(
	ctx context.Context,
	scenario TestScenario,
	actioner ActionExecutor,
	logger *slog.Logger,
	clientset kubernetes.Interface,
) error

func WaitUntil

func WaitUntil(ctx context.Context, duration time.Duration, condition func(ctx context.Context) bool) bool

func WoopCR added in v0.57.2

func WoopCR(namespace, name string) *unstructured.Unstructured

WoopCR creates an instance of the CRD from WoopCRD.

func WoopCRD added in v0.57.2

WoopCRD is a stub CRD similar to workload autoscaler's one.

func WoopGVR added in v0.57.2

func WoopGVR() *schema.GroupVersionResource

WoopGVR returns the GVR for the CRD from WoopCRD.

Types

type ActionExecutor

type ActionExecutor interface {
	// ExecuteActions is expected to execute all actions and wait for ack before returning; otherwise cleanups might run too early.
	ExecuteActions(ctx context.Context, actions []castai.ClusterAction)
}

type KwokConfig

type KwokConfig struct {
	// Label should match what kwok is configured to use via --manage-nodes-with-label-selector
	// Default is DefaultKwokMarker. Value is always KwokMarkerValue.
	Label string

	// Annotation should match what kwok is configured to use via --manage-nodes-with-annotation-selector
	// Default is DefaultKwokMarker. Value is always KwokMarkerValue.
	Annotation string
}

type TestScenario

type TestScenario interface {
	Name() string
	// Preparation should create any necessary resources in the cluster for the test so it runs in realistic env.
	Preparation(ctx context.Context, namespace string, clientset kubernetes.Interface) error
	// Cleanup should delete any items created by the preparation or the test itself.
	// It might be called even if Preparation or Run did not complete so it should handle those cases gracefully.
	// The scenario's namespace is deleted at the end but ideally scenarios delete their resources as well,
	// otherwise namespace deletion can take very long to propagate.
	Cleanup(ctx context.Context, namespace string, clientset kubernetes.Interface) error
	Run(ctx context.Context, namespace string, clientset kubernetes.Interface, executor ActionExecutor) error
}

func CheckNodeDeletedStuck added in v0.57.2

func CheckNodeDeletedStuck(nodeCount int, log *slog.Logger) TestScenario

CheckNodeDeletedStuck simulates a case where the node is not deleted so the checker gets stuck.

func CheckNodeStatus added in v0.57.2

func CheckNodeStatus(nodeCount int, log *slog.Logger) TestScenario

func CreateResource added in v0.57.2

func CreateResource(count int, dynamicClient dynamic.Interface, apiextensions apiextensionsclientset.Interface, log *slog.Logger) TestScenario

CreateResource will simulate creating/patching N custom resources (ala workload autoscaler flow).

func DeleteNode added in v0.57.2

func DeleteNode(nodeCount, deploymentReplicas int, log *slog.Logger) TestScenario

func DeleteResource added in v0.57.2

func DeleteResource(count int, dynamicClient dynamic.Interface, apiextensions apiextensionsclientset.Interface, log *slog.Logger) TestScenario

DeleteResource will simulate deleting N custom resources (ala workload autoscaler flow).

func DrainNode added in v0.57.2

func DrainNode(nodeCount, deploymentReplicas int, log *slog.Logger) TestScenario

DrainNode simulates draining of nodes that passes successfully (as opposed to StuckDrain).

func EvictPod added in v0.57.2

func EvictPod(count int, log *slog.Logger) TestScenario

func PatchNode added in v0.57.2

func PatchNode(nodeCount int, log *slog.Logger) TestScenario

func PatchResource added in v0.57.2

func PatchResource(count int, dynamicClient dynamic.Interface, apiextensions apiextensionsclientset.Interface, log *slog.Logger) TestScenario

PatchResource will simulate patching N custom resources (ala workload autoscaler flow).

func PodEvents

func PodEvents(count int, log *slog.Logger) TestScenario

func StuckDrain

func StuckDrain(nodeCount, deploymentReplicas int, log *slog.Logger) TestScenario

Jump to

Keyboard shortcuts

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