Events#

Class for formatting Kubernetes event messages.

class kubespawner.events.EventFormatter(*args: t.Any, **kwargs: t.Any)#
class kubespawner.events.BasicEventFormatter(*args: t.Any, **kwargs: t.Any)#
class kubespawner.events.RuleEventFormatter(*args: t.Any, **kwargs: t.Any)#
extra_rules c.RuleEventFormatter.extra_rules = Union()#

List or dictionary of additional event formatter rules on top of RuleEventFormatter.rules. These rules are merged with RuleEventFormatter.rules. Where extra_rules is a dict, the name of each rule can be chosen to override a base rule.

See also

RuleEventFormatter.rules for information on fields available in template strings.

rules c.RuleEventFormatter.rules = Union()#

List or dictionary of event formatter rules.

A “rule” is an object that consists of two required fields:

  • match — an object containing regular expression patterns (strings or compiled regular expressions) that match similarly named Event fields. Any named capture groups will be made available to the template. Supported fields are reportingComponent, fieldPath, reason, message, and type.

  • template — a string, or a callable that will be used to build a formatted event message. If a string, the .format method will be invoked with any named capture group results as keyword arguments. If a callable, the same named capture groups will be directly passed as keyword arguments. Missing named capture groups are provided as empty strings.

If provided as a list, each item should be an aforementioned “rule” object. If provided as a dictionary, the keys can be any descriptive name and the values should be the aforementioned “rule” objects. The items will be sorted lexicographically by the dictionary keys, and the sorted values will be used to build the list of rules. .. admonition:: Example

collapsible:

closed

Here is an example of two rules that are defined by default in the RuleEventFormatter.

c.RuleEventFormatter.rules =
  [
      {
          "match": {
              "reportingComponent": r"kubelet",
              "fieldPath": r"spec\.(initContainers|containers)\{(?P<container>[^}]+)\}",
              "reason": r"(?P<action>Pulling|Pulled)",
              "message": r'.*image\s*"(?P<image>[^"]+)\:(?P<tag>[^"]+)"',
          },
          "template": "{action} image {image}:{tag} for the {container} container",
      },
      {
          "match": {
              "reportingComponent": r"kubelet",
              "fieldPath": r"spec\.(initContainers|containers)\{(?P<container>[^}]+)\}",
              "reason": r"(?P<action>Started|Killing|Created|Stopped)",
          },
          "template": '{action} the container "{container}"',
      }
  ]

When set to None, a default ruleset is used.

Ref:

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#event-v1-core

kubespawner.events.decorate_plain_message(message: str, event: dict) str#

Build a plain-text message from a plain-text message body and an Event object.

Ref:

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#event-v1-core

kubespawner.events.decorate_html_message(message: str, event: dict) str#

Build a full HTML message from a plain-text message body and an Event object.

Ref:

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#event-v1-core