actionPod

terminate_pods

Terminate a pod gracefully

Activity as code

Below are the details and signature of the activity Python module.

Typeaction
Modulechaosk8s.pod.actions
Nameterminate_pods
ReturnNone

Usage

JSON

{
  "name": "terminate-pods",
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosk8s.pod.actions",
    "func": "terminate_pods"
  }
}

YAML

name: terminate-pods
provider:
  func: terminate_pods
  module: chaosk8s.pod.actions
  type: python
type: action

Arguments

NameTypeDefaultRequiredTitleDescription
nsstring“default”YesNamespace
label_selectorstringnullYesLabel SelectorSelectors to target the appropriate pods
qtyinteger1NoNumber of Pods to TerminateThe number of pods to terminate
modestring“fixed”NoQuantity Selection ModeEither fixed or percentage. With fixed, the quantity is used as the number of pods. With percentage terminates a volume of pods between 1 and 100
allbooleanfalseNoSelect All PodsTerminate all pods matching the selector
randbooleanfalseNoRandom SelectionTerminate the number of pods defined by quantity at random within the selected pool of pods
orderstring“alphabetic”NoLabel SelectorHow candidate pods are selected: alphabetic or oldest
grace_periodinteger-1NoGrace PeriodGrace period for pods to complete their shutdown. Leave -1 for the default behavior

Select the appropriate pods by label and/or name patterns. Whenever a pattern is provided for the name, all pods retrieved will be filtered out if their name does not match the given pattern.

If neither label_selector nor name_pattern is provided, all pods in the namespace will be selected for termination.

If all is set to True, all matching pods will be terminated.

The value of qty varies based on mode.

If mode is set to fixed, then qty refers to the number of pods to be terminated. If mode is set to percentage, then qty refers to the percentage of pods, from 1 to 100, to be terminated.

The default mode is fixed and the default qty is 1.

If order is set to oldest, the retrieved pods will be ordered by the pods creation_timestamp, with the oldest pod first in the list.

If rand is set to True, n random pods will be terminated. Otherwise, the first retrieved n pods will be terminated.

If grace_period is greater than or equal to 0, it will be used as the grace period (in seconds) to terminate the pods. Otherwise, the default pod’s grace period will be used.

Signature

def terminate_pods(label_selector: str = None,
                   name_pattern: str = None,
                   all: bool = False,
                   rand: bool = False,
                   mode: str = 'fixed',
                   qty: int = 1,
                   grace_period: int = -1,
                   ns: str = 'default',
                   order: str = 'alphabetic',
                   secrets: Dict[str, Dict[str, str]] = None):
    pass