From 5f38aeebc6d2d901ec907a3408af6d903f7f5640 Mon Sep 17 00:00:00 2001 From: arik Date: Tue, 11 Jan 2022 17:51:04 +0200 Subject: [PATCH 1/3] K8s labels filters (#149) * Add severity and investigate link * Add severity and investigate link * cli eula enhancement * k8s labels filters * CR changes Co-authored-by: Robusta Runner --- docs/catalog/triggers/kubernetes.rst | 27 + scripts/generate_kubernetes_code.py | 10 +- .../kubernetes/autogenerated/events.py | 563 ++++------------ .../kubernetes/autogenerated/models.py | 7 +- .../kubernetes/autogenerated/triggers.py | 604 +++++++++++------- .../kubernetes/autogenerated/v1/models.py | 30 +- .../autogenerated/v2beta1/models.py | 30 +- .../autogenerated/v2beta2/models.py | 30 +- .../integrations/kubernetes/base_triggers.py | 25 +- 9 files changed, 609 insertions(+), 717 deletions(-) diff --git a/docs/catalog/triggers/kubernetes.rst b/docs/catalog/triggers/kubernetes.rst index 758261afd..b774a3ede 100644 --- a/docs/catalog/triggers/kubernetes.rst +++ b/docs/catalog/triggers/kubernetes.rst @@ -1,6 +1,24 @@ Kubernetes ############################ +Robusta can run playbooks in response to Kubernetes API Server events. + +When a ``Pod`` is created, or when a ``Deployment`` is changed, we can trigger Robusta actions. + +Configuration example +^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: yaml + + - triggers: + - on_deployment_update: + name_prefix: my-app-name + namespace_prefix: ns1 + labels_selector: app=my-app + actions: + - add_deployment_lines_to_grafana: + grafana_url: .... + Basic triggers ---------------- Most Kubernetes resources can be used to trigger playbooks. The trigger will fire when the resource changes. For example: @@ -46,3 +64,12 @@ The following wildcard triggers will fire for any supported Kubernetes resource: * on_kubernetes_any_resource_update * on_kubernetes_any_resource_delete * on_kubernetes_any_resource_all_changes + +Supported filters +-------------------- + +All Kubernetes triggers support the following filters: + +* ``name_prefix`` - Name prefix to match resources. +* ``namespace_prefix`` - Namespace prefix to match resources. +* ``labels_selector`` - Match resources with these labels. The format is: ``label1=value1,label2=value2``. If more than one labels is provided, **all** need to match. diff --git a/scripts/generate_kubernetes_code.py b/scripts/generate_kubernetes_code.py index e65cddbdb..75fd7d878 100755 --- a/scripts/generate_kubernetes_code.py +++ b/scripts/generate_kubernetes_code.py @@ -321,12 +321,13 @@ def autogenerate_triggers(f: TextIO): f"""\ class {resource}{get_trigger_class_name(trigger_name)}Trigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( kind=\"{resource}\", operation={operation_type}, name_prefix=name_prefix, - namespace_prefix=namespace_prefix + namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -351,12 +352,13 @@ def get_execution_event_type() -> type: f"""\ class KubernetesAny{get_trigger_class_name(trigger_name)}Trigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( kind=\"Any\", operation={operation_type}, name_prefix=name_prefix, - namespace_prefix=namespace_prefix + namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod diff --git a/src/robusta/integrations/kubernetes/autogenerated/events.py b/src/robusta/integrations/kubernetes/autogenerated/events.py index 7250ef9d7..34f98024a 100644 --- a/src/robusta/integrations/kubernetes/autogenerated/events.py +++ b/src/robusta/integrations/kubernetes/autogenerated/events.py @@ -4,100 +4,72 @@ import traceback from dataclasses import dataclass from abc import abstractmethod -from hikaru.model import ( - Pod, - ReplicaSet, - DaemonSet, - Deployment, - StatefulSet, - Service, - Event, - HorizontalPodAutoscaler, - Node, - ClusterRole, - ClusterRoleBinding, - Job, - Namespace, - ServiceAccount, -) +from hikaru.model import Pod,ReplicaSet,DaemonSet,Deployment,StatefulSet,Service,Event,HorizontalPodAutoscaler,Node,ClusterRole,ClusterRoleBinding,Job,Namespace,ServiceAccount from hikaru.utils import Response from pydantic import BaseModel from typing import Union, Optional, List from ..base_event import K8sBaseChangeEvent from ....core.model.events import ExecutionBaseEvent, ExecutionEventBaseParams -from ..custom_models import RobustaPod, RobustaDeployment, RobustaJob -from hikaru.model.rel_1_16.v1 import ClusterRole as v1ClusterRole -from hikaru.model.rel_1_16.v1 import ClusterRoleBinding as v1ClusterRoleBinding -from hikaru.model.rel_1_16.v1 import DaemonSet as v1DaemonSet -from hikaru.model.rel_1_16.v1 import Deployment as v1Deployment -from hikaru.model.rel_1_16.v1 import Event as v1Event -from hikaru.model.rel_1_16.v1 import ( - HorizontalPodAutoscaler as v1HorizontalPodAutoscaler, -) -from hikaru.model.rel_1_16.v1 import Job as v1Job -from hikaru.model.rel_1_16.v1 import Namespace as v1Namespace -from hikaru.model.rel_1_16.v1 import Node as v1Node -from hikaru.model.rel_1_16.v1 import Pod as v1Pod -from hikaru.model.rel_1_16.v1 import ReplicaSet as v1ReplicaSet -from hikaru.model.rel_1_16.v1 import Service as v1Service -from hikaru.model.rel_1_16.v1 import ServiceAccount as v1ServiceAccount -from hikaru.model.rel_1_16.v1 import StatefulSet as v1StatefulSet -from hikaru.model.rel_1_16.v2beta1 import ClusterRole as v2beta1ClusterRole -from hikaru.model.rel_1_16.v2beta1 import ( - ClusterRoleBinding as v2beta1ClusterRoleBinding, -) -from hikaru.model.rel_1_16.v2beta1 import DaemonSet as v2beta1DaemonSet -from hikaru.model.rel_1_16.v2beta1 import Deployment as v2beta1Deployment -from hikaru.model.rel_1_16.v2beta1 import Event as v2beta1Event -from hikaru.model.rel_1_16.v2beta1 import ( - HorizontalPodAutoscaler as v2beta1HorizontalPodAutoscaler, -) -from hikaru.model.rel_1_16.v2beta1 import Job as v2beta1Job -from hikaru.model.rel_1_16.v2beta1 import Namespace as v2beta1Namespace -from hikaru.model.rel_1_16.v2beta1 import Node as v2beta1Node -from hikaru.model.rel_1_16.v2beta1 import Pod as v2beta1Pod -from hikaru.model.rel_1_16.v2beta1 import ReplicaSet as v2beta1ReplicaSet -from hikaru.model.rel_1_16.v2beta1 import Service as v2beta1Service -from hikaru.model.rel_1_16.v2beta1 import ServiceAccount as v2beta1ServiceAccount -from hikaru.model.rel_1_16.v2beta1 import StatefulSet as v2beta1StatefulSet -from hikaru.model.rel_1_16.v2beta2 import ClusterRole as v2beta2ClusterRole -from hikaru.model.rel_1_16.v2beta2 import ( - ClusterRoleBinding as v2beta2ClusterRoleBinding, -) -from hikaru.model.rel_1_16.v2beta2 import DaemonSet as v2beta2DaemonSet -from hikaru.model.rel_1_16.v2beta2 import Deployment as v2beta2Deployment -from hikaru.model.rel_1_16.v2beta2 import Event as v2beta2Event -from hikaru.model.rel_1_16.v2beta2 import ( - HorizontalPodAutoscaler as v2beta2HorizontalPodAutoscaler, -) -from hikaru.model.rel_1_16.v2beta2 import Job as v2beta2Job -from hikaru.model.rel_1_16.v2beta2 import Namespace as v2beta2Namespace -from hikaru.model.rel_1_16.v2beta2 import Node as v2beta2Node -from hikaru.model.rel_1_16.v2beta2 import Pod as v2beta2Pod -from hikaru.model.rel_1_16.v2beta2 import ReplicaSet as v2beta2ReplicaSet -from hikaru.model.rel_1_16.v2beta2 import Service as v2beta2Service -from hikaru.model.rel_1_16.v2beta2 import ServiceAccount as v2beta2ServiceAccount -from hikaru.model.rel_1_16.v2beta2 import StatefulSet as v2beta2StatefulSet +from ..custom_models import RobustaPod,RobustaDeployment,RobustaJob +from hikaru.model.rel_1_16.v1 import ClusterRole as v1ClusterRole +from hikaru.model.rel_1_16.v1 import ClusterRoleBinding as v1ClusterRoleBinding +from hikaru.model.rel_1_16.v1 import DaemonSet as v1DaemonSet +from hikaru.model.rel_1_16.v1 import Deployment as v1Deployment +from hikaru.model.rel_1_16.v1 import Event as v1Event +from hikaru.model.rel_1_16.v1 import HorizontalPodAutoscaler as v1HorizontalPodAutoscaler +from hikaru.model.rel_1_16.v1 import Job as v1Job +from hikaru.model.rel_1_16.v1 import Namespace as v1Namespace +from hikaru.model.rel_1_16.v1 import Node as v1Node +from hikaru.model.rel_1_16.v1 import Pod as v1Pod +from hikaru.model.rel_1_16.v1 import ReplicaSet as v1ReplicaSet +from hikaru.model.rel_1_16.v1 import Service as v1Service +from hikaru.model.rel_1_16.v1 import ServiceAccount as v1ServiceAccount +from hikaru.model.rel_1_16.v1 import StatefulSet as v1StatefulSet +from hikaru.model.rel_1_16.v2beta1 import ClusterRole as v2beta1ClusterRole +from hikaru.model.rel_1_16.v2beta1 import ClusterRoleBinding as v2beta1ClusterRoleBinding +from hikaru.model.rel_1_16.v2beta1 import DaemonSet as v2beta1DaemonSet +from hikaru.model.rel_1_16.v2beta1 import Deployment as v2beta1Deployment +from hikaru.model.rel_1_16.v2beta1 import Event as v2beta1Event +from hikaru.model.rel_1_16.v2beta1 import HorizontalPodAutoscaler as v2beta1HorizontalPodAutoscaler +from hikaru.model.rel_1_16.v2beta1 import Job as v2beta1Job +from hikaru.model.rel_1_16.v2beta1 import Namespace as v2beta1Namespace +from hikaru.model.rel_1_16.v2beta1 import Node as v2beta1Node +from hikaru.model.rel_1_16.v2beta1 import Pod as v2beta1Pod +from hikaru.model.rel_1_16.v2beta1 import ReplicaSet as v2beta1ReplicaSet +from hikaru.model.rel_1_16.v2beta1 import Service as v2beta1Service +from hikaru.model.rel_1_16.v2beta1 import ServiceAccount as v2beta1ServiceAccount +from hikaru.model.rel_1_16.v2beta1 import StatefulSet as v2beta1StatefulSet +from hikaru.model.rel_1_16.v2beta2 import ClusterRole as v2beta2ClusterRole +from hikaru.model.rel_1_16.v2beta2 import ClusterRoleBinding as v2beta2ClusterRoleBinding +from hikaru.model.rel_1_16.v2beta2 import DaemonSet as v2beta2DaemonSet +from hikaru.model.rel_1_16.v2beta2 import Deployment as v2beta2Deployment +from hikaru.model.rel_1_16.v2beta2 import Event as v2beta2Event +from hikaru.model.rel_1_16.v2beta2 import HorizontalPodAutoscaler as v2beta2HorizontalPodAutoscaler +from hikaru.model.rel_1_16.v2beta2 import Job as v2beta2Job +from hikaru.model.rel_1_16.v2beta2 import Namespace as v2beta2Namespace +from hikaru.model.rel_1_16.v2beta2 import Node as v2beta2Node +from hikaru.model.rel_1_16.v2beta2 import Pod as v2beta2Pod +from hikaru.model.rel_1_16.v2beta2 import ReplicaSet as v2beta2ReplicaSet +from hikaru.model.rel_1_16.v2beta2 import Service as v2beta2Service +from hikaru.model.rel_1_16.v2beta2 import ServiceAccount as v2beta2ServiceAccount +from hikaru.model.rel_1_16.v2beta2 import StatefulSet as v2beta2StatefulSet LOADERS_MAPPINGS = { - "pod": (True, RobustaPod.readNamespacedPod), - "replicaset": (True, ReplicaSet.readNamespacedReplicaSet), - "daemonset": (True, DaemonSet.readNamespacedDaemonSet), - "deployment": (True, RobustaDeployment.readNamespacedDeployment), - "statefulset": (True, StatefulSet.readNamespacedStatefulSet), - "service": (True, Service.readNamespacedService), - "event": (True, Event.readNamespacedEvent), - "horizontalpodautoscaler": ( - True, - HorizontalPodAutoscaler.readNamespacedHorizontalPodAutoscaler, - ), - "node": (False, Node.readNode), - "clusterrole": (False, ClusterRole.readClusterRole), - "clusterrolebinding": (False, ClusterRoleBinding.readClusterRoleBinding), - "job": (True, RobustaJob.readNamespacedJob), - "namespace": (False, Namespace.readNamespace), - "serviceaccount": (True, ServiceAccount.readNamespacedServiceAccount), + 'pod': (True, RobustaPod.readNamespacedPod), + 'replicaset': (True, ReplicaSet.readNamespacedReplicaSet), + 'daemonset': (True, DaemonSet.readNamespacedDaemonSet), + 'deployment': (True, RobustaDeployment.readNamespacedDeployment), + 'statefulset': (True, StatefulSet.readNamespacedStatefulSet), + 'service': (True, Service.readNamespacedService), + 'event': (True, Event.readNamespacedEvent), + 'horizontalpodautoscaler': (True, HorizontalPodAutoscaler.readNamespacedHorizontalPodAutoscaler), + 'node': (False, Node.readNode), + 'clusterrole': (False, ClusterRole.readClusterRole), + 'clusterrolebinding': (False, ClusterRoleBinding.readClusterRoleBinding), + 'job': (True, RobustaJob.readNamespacedJob), + 'namespace': (False, Namespace.readNamespace), + 'serviceaccount': (True, ServiceAccount.readNamespacedServiceAccount), } @@ -122,75 +94,22 @@ class ResourceAttributes(ExecutionEventBaseParams): @dataclass class KubernetesResourceEvent(ExecutionBaseEvent): - _obj: Optional[ - Union[ - RobustaPod, - ReplicaSet, - DaemonSet, - RobustaDeployment, - StatefulSet, - Service, - Event, - HorizontalPodAutoscaler, - Node, - ClusterRole, - ClusterRoleBinding, - RobustaJob, - Namespace, - ServiceAccount, - ] - ] = None - - def __init__( - self, - obj: Union[ - RobustaPod, - ReplicaSet, - DaemonSet, - RobustaDeployment, - StatefulSet, - Service, - Event, - HorizontalPodAutoscaler, - Node, - ClusterRole, - ClusterRoleBinding, - RobustaJob, - Namespace, - ServiceAccount, - ], - named_sinks: List[str], - ): + _obj: Optional[Union[RobustaPod,ReplicaSet,DaemonSet,RobustaDeployment,StatefulSet,Service,Event,HorizontalPodAutoscaler,Node,ClusterRole,ClusterRoleBinding,RobustaJob,Namespace,ServiceAccount]] = None + + def __init__(self, obj: Union[RobustaPod,ReplicaSet,DaemonSet,RobustaDeployment,StatefulSet,Service,Event,HorizontalPodAutoscaler,Node,ClusterRole,ClusterRoleBinding,RobustaJob,Namespace,ServiceAccount], named_sinks: List[str]): super().__init__(named_sinks=named_sinks) self._obj = obj - def get_resource( - self, - ) -> Optional[ - Union[ - RobustaPod, - ReplicaSet, - DaemonSet, - RobustaDeployment, - StatefulSet, - Service, - Event, - HorizontalPodAutoscaler, - Node, - ClusterRole, - ClusterRoleBinding, - RobustaJob, - Namespace, - ServiceAccount, - ] - ]: + def get_resource(self) -> Optional[Union[RobustaPod,ReplicaSet,DaemonSet,RobustaDeployment,StatefulSet,Service,Event,HorizontalPodAutoscaler,Node,ClusterRole,ClusterRoleBinding,RobustaJob,Namespace,ServiceAccount]]: return self._obj @staticmethod def from_params(params: ResourceAttributes) -> Optional["KubernetesResourceEvent"]: try: obj = ResourceLoader.read_resource( - kind=params.kind, name=params.name, namespace=params.namespace + kind=params.kind, + name=params.name, + namespace=params.namespace ).obj except Exception: logging.error(f"Could not load resource {params}", exc_info=True) @@ -200,129 +119,10 @@ def from_params(params: ResourceAttributes) -> Optional["KubernetesResourceEvent @dataclass class KubernetesAnyChangeEvent(K8sBaseChangeEvent): - obj: Optional[ - Union[ - RobustaDeployment, - RobustaJob, - RobustaPod, - v1ClusterRole, - v1ClusterRoleBinding, - v1DaemonSet, - v1Event, - v1HorizontalPodAutoscaler, - v1Namespace, - v1Node, - v1ReplicaSet, - v1Service, - v1ServiceAccount, - v1StatefulSet, - v2beta1ClusterRole, - v2beta1ClusterRoleBinding, - v2beta1DaemonSet, - v2beta1Event, - v2beta1HorizontalPodAutoscaler, - v2beta1Namespace, - v2beta1Node, - v2beta1ReplicaSet, - v2beta1Service, - v2beta1ServiceAccount, - v2beta1StatefulSet, - v2beta2ClusterRole, - v2beta2ClusterRoleBinding, - v2beta2DaemonSet, - v2beta2Event, - v2beta2HorizontalPodAutoscaler, - v2beta2Namespace, - v2beta2Node, - v2beta2ReplicaSet, - v2beta2Service, - v2beta2ServiceAccount, - v2beta2StatefulSet, - ] - ] = None - old_obj: Optional[ - Union[ - RobustaDeployment, - RobustaJob, - RobustaPod, - v1ClusterRole, - v1ClusterRoleBinding, - v1DaemonSet, - v1Event, - v1HorizontalPodAutoscaler, - v1Namespace, - v1Node, - v1ReplicaSet, - v1Service, - v1ServiceAccount, - v1StatefulSet, - v2beta1ClusterRole, - v2beta1ClusterRoleBinding, - v2beta1DaemonSet, - v2beta1Event, - v2beta1HorizontalPodAutoscaler, - v2beta1Namespace, - v2beta1Node, - v2beta1ReplicaSet, - v2beta1Service, - v2beta1ServiceAccount, - v2beta1StatefulSet, - v2beta2ClusterRole, - v2beta2ClusterRoleBinding, - v2beta2DaemonSet, - v2beta2Event, - v2beta2HorizontalPodAutoscaler, - v2beta2Namespace, - v2beta2Node, - v2beta2ReplicaSet, - v2beta2Service, - v2beta2ServiceAccount, - v2beta2StatefulSet, - ] - ] = None - - def get_resource( - self, - ) -> Optional[ - Union[ - RobustaDeployment, - RobustaJob, - RobustaPod, - v1ClusterRole, - v1ClusterRoleBinding, - v1DaemonSet, - v1Event, - v1HorizontalPodAutoscaler, - v1Namespace, - v1Node, - v1ReplicaSet, - v1Service, - v1ServiceAccount, - v1StatefulSet, - v2beta1ClusterRole, - v2beta1ClusterRoleBinding, - v2beta1DaemonSet, - v2beta1Event, - v2beta1HorizontalPodAutoscaler, - v2beta1Namespace, - v2beta1Node, - v2beta1ReplicaSet, - v2beta1Service, - v2beta1ServiceAccount, - v2beta1StatefulSet, - v2beta2ClusterRole, - v2beta2ClusterRoleBinding, - v2beta2DaemonSet, - v2beta2Event, - v2beta2HorizontalPodAutoscaler, - v2beta2Namespace, - v2beta2Node, - v2beta2ReplicaSet, - v2beta2Service, - v2beta2ServiceAccount, - v2beta2StatefulSet, - ] - ]: + obj: Optional[Union[RobustaDeployment,RobustaJob,RobustaPod,v1ClusterRole,v1ClusterRoleBinding,v1DaemonSet,v1Event,v1HorizontalPodAutoscaler,v1Namespace,v1Node,v1ReplicaSet,v1Service,v1ServiceAccount,v1StatefulSet,v2beta1ClusterRole,v2beta1ClusterRoleBinding,v2beta1DaemonSet,v2beta1Event,v2beta1HorizontalPodAutoscaler,v2beta1Namespace,v2beta1Node,v2beta1ReplicaSet,v2beta1Service,v2beta1ServiceAccount,v2beta1StatefulSet,v2beta2ClusterRole,v2beta2ClusterRoleBinding,v2beta2DaemonSet,v2beta2Event,v2beta2HorizontalPodAutoscaler,v2beta2Namespace,v2beta2Node,v2beta2ReplicaSet,v2beta2Service,v2beta2ServiceAccount,v2beta2StatefulSet]] = None + old_obj: Optional[Union[RobustaDeployment,RobustaJob,RobustaPod,v1ClusterRole,v1ClusterRoleBinding,v1DaemonSet,v1Event,v1HorizontalPodAutoscaler,v1Namespace,v1Node,v1ReplicaSet,v1Service,v1ServiceAccount,v1StatefulSet,v2beta1ClusterRole,v2beta1ClusterRoleBinding,v2beta1DaemonSet,v2beta1Event,v2beta1HorizontalPodAutoscaler,v2beta1Namespace,v2beta1Node,v2beta1ReplicaSet,v2beta1Service,v2beta1ServiceAccount,v2beta1StatefulSet,v2beta2ClusterRole,v2beta2ClusterRoleBinding,v2beta2DaemonSet,v2beta2Event,v2beta2HorizontalPodAutoscaler,v2beta2Namespace,v2beta2Node,v2beta2ReplicaSet,v2beta2Service,v2beta2ServiceAccount,v2beta2StatefulSet]] = None + + def get_resource(self) -> Optional[Union[RobustaDeployment,RobustaJob,RobustaPod,v1ClusterRole,v1ClusterRoleBinding,v1DaemonSet,v1Event,v1HorizontalPodAutoscaler,v1Namespace,v1Node,v1ReplicaSet,v1Service,v1ServiceAccount,v1StatefulSet,v2beta1ClusterRole,v2beta1ClusterRoleBinding,v2beta1DaemonSet,v2beta1Event,v2beta1HorizontalPodAutoscaler,v2beta1Namespace,v2beta1Node,v2beta1ReplicaSet,v2beta1Service,v2beta1ServiceAccount,v2beta1StatefulSet,v2beta2ClusterRole,v2beta2ClusterRoleBinding,v2beta2DaemonSet,v2beta2Event,v2beta2HorizontalPodAutoscaler,v2beta2Namespace,v2beta2Node,v2beta2ReplicaSet,v2beta2Service,v2beta2ServiceAccount,v2beta2StatefulSet]]: return self.obj @@ -342,9 +142,7 @@ def get_pod(self) -> Optional[RobustaPod]: @staticmethod def from_params(params: PodAttributes) -> Optional["PodEvent"]: try: - obj = RobustaPod.readNamespacedPod( - name=params.name, namespace=params.namespace - ).obj + obj = RobustaPod.readNamespacedPod(name=params.name, namespace=params.namespace).obj except Exception: logging.error(f"Could not load Pod {params}", exc_info=True) return None @@ -376,9 +174,7 @@ def get_replicaset(self) -> Optional[ReplicaSet]: @staticmethod def from_params(params: ReplicaSetAttributes) -> Optional["ReplicaSetEvent"]: try: - obj = ReplicaSet.readNamespacedReplicaSet( - name=params.name, namespace=params.namespace - ).obj + obj = ReplicaSet.readNamespacedReplicaSet(name=params.name, namespace=params.namespace).obj except Exception: logging.error(f"Could not load ReplicaSet {params}", exc_info=True) return None @@ -387,12 +183,10 @@ def from_params(params: ReplicaSetAttributes) -> Optional["ReplicaSetEvent"]: @dataclass class ReplicaSetChangeEvent(ReplicaSetEvent, KubernetesAnyChangeEvent): - obj: Optional[Union[v1ReplicaSet, v2beta1ReplicaSet, v2beta2ReplicaSet]] = None - old_obj: Optional[Union[v1ReplicaSet, v2beta1ReplicaSet, v2beta2ReplicaSet]] = None + obj: Optional[Union[v1ReplicaSet,v2beta1ReplicaSet,v2beta2ReplicaSet]] = None + old_obj: Optional[Union[v1ReplicaSet,v2beta1ReplicaSet,v2beta2ReplicaSet]] = None - def get_replicaset( - self, - ) -> Optional[Union[v1ReplicaSet, v2beta1ReplicaSet, v2beta2ReplicaSet]]: + def get_replicaset(self) -> Optional[Union[v1ReplicaSet,v2beta1ReplicaSet,v2beta2ReplicaSet]]: return self.obj @@ -412,9 +206,7 @@ def get_daemonset(self) -> Optional[DaemonSet]: @staticmethod def from_params(params: DaemonSetAttributes) -> Optional["DaemonSetEvent"]: try: - obj = DaemonSet.readNamespacedDaemonSet( - name=params.name, namespace=params.namespace - ).obj + obj = DaemonSet.readNamespacedDaemonSet(name=params.name, namespace=params.namespace).obj except Exception: logging.error(f"Could not load DaemonSet {params}", exc_info=True) return None @@ -423,12 +215,10 @@ def from_params(params: DaemonSetAttributes) -> Optional["DaemonSetEvent"]: @dataclass class DaemonSetChangeEvent(DaemonSetEvent, KubernetesAnyChangeEvent): - obj: Optional[Union[v1DaemonSet, v2beta1DaemonSet, v2beta2DaemonSet]] = None - old_obj: Optional[Union[v1DaemonSet, v2beta1DaemonSet, v2beta2DaemonSet]] = None + obj: Optional[Union[v1DaemonSet,v2beta1DaemonSet,v2beta2DaemonSet]] = None + old_obj: Optional[Union[v1DaemonSet,v2beta1DaemonSet,v2beta2DaemonSet]] = None - def get_daemonset( - self, - ) -> Optional[Union[v1DaemonSet, v2beta1DaemonSet, v2beta2DaemonSet]]: + def get_daemonset(self) -> Optional[Union[v1DaemonSet,v2beta1DaemonSet,v2beta2DaemonSet]]: return self.obj @@ -448,9 +238,7 @@ def get_deployment(self) -> Optional[RobustaDeployment]: @staticmethod def from_params(params: DeploymentAttributes) -> Optional["DeploymentEvent"]: try: - obj = RobustaDeployment.readNamespacedDeployment( - name=params.name, namespace=params.namespace - ).obj + obj = RobustaDeployment.readNamespacedDeployment(name=params.name, namespace=params.namespace).obj except Exception: logging.error(f"Could not load Deployment {params}", exc_info=True) return None @@ -482,9 +270,7 @@ def get_statefulset(self) -> Optional[StatefulSet]: @staticmethod def from_params(params: StatefulSetAttributes) -> Optional["StatefulSetEvent"]: try: - obj = StatefulSet.readNamespacedStatefulSet( - name=params.name, namespace=params.namespace - ).obj + obj = StatefulSet.readNamespacedStatefulSet(name=params.name, namespace=params.namespace).obj except Exception: logging.error(f"Could not load StatefulSet {params}", exc_info=True) return None @@ -493,14 +279,10 @@ def from_params(params: StatefulSetAttributes) -> Optional["StatefulSetEvent"]: @dataclass class StatefulSetChangeEvent(StatefulSetEvent, KubernetesAnyChangeEvent): - obj: Optional[Union[v1StatefulSet, v2beta1StatefulSet, v2beta2StatefulSet]] = None - old_obj: Optional[ - Union[v1StatefulSet, v2beta1StatefulSet, v2beta2StatefulSet] - ] = None - - def get_statefulset( - self, - ) -> Optional[Union[v1StatefulSet, v2beta1StatefulSet, v2beta2StatefulSet]]: + obj: Optional[Union[v1StatefulSet,v2beta1StatefulSet,v2beta2StatefulSet]] = None + old_obj: Optional[Union[v1StatefulSet,v2beta1StatefulSet,v2beta2StatefulSet]] = None + + def get_statefulset(self) -> Optional[Union[v1StatefulSet,v2beta1StatefulSet,v2beta2StatefulSet]]: return self.obj @@ -520,9 +302,7 @@ def get_service(self) -> Optional[Service]: @staticmethod def from_params(params: ServiceAttributes) -> Optional["ServiceEvent"]: try: - obj = Service.readNamespacedService( - name=params.name, namespace=params.namespace - ).obj + obj = Service.readNamespacedService(name=params.name, namespace=params.namespace).obj except Exception: logging.error(f"Could not load Service {params}", exc_info=True) return None @@ -531,10 +311,10 @@ def from_params(params: ServiceAttributes) -> Optional["ServiceEvent"]: @dataclass class ServiceChangeEvent(ServiceEvent, KubernetesAnyChangeEvent): - obj: Optional[Union[v1Service, v2beta1Service, v2beta2Service]] = None - old_obj: Optional[Union[v1Service, v2beta1Service, v2beta2Service]] = None + obj: Optional[Union[v1Service,v2beta1Service,v2beta2Service]] = None + old_obj: Optional[Union[v1Service,v2beta1Service,v2beta2Service]] = None - def get_service(self) -> Optional[Union[v1Service, v2beta1Service, v2beta2Service]]: + def get_service(self) -> Optional[Union[v1Service,v2beta1Service,v2beta2Service]]: return self.obj @@ -554,9 +334,7 @@ def get_event(self) -> Optional[Event]: @staticmethod def from_params(params: EventAttributes) -> Optional["EventEvent"]: try: - obj = Event.readNamespacedEvent( - name=params.name, namespace=params.namespace - ).obj + obj = Event.readNamespacedEvent(name=params.name, namespace=params.namespace).obj except Exception: logging.error(f"Could not load Event {params}", exc_info=True) return None @@ -565,10 +343,10 @@ def from_params(params: EventAttributes) -> Optional["EventEvent"]: @dataclass class EventChangeEvent(EventEvent, KubernetesAnyChangeEvent): - obj: Optional[Union[v1Event, v2beta1Event, v2beta2Event]] = None - old_obj: Optional[Union[v1Event, v2beta1Event, v2beta2Event]] = None + obj: Optional[Union[v1Event,v2beta1Event,v2beta2Event]] = None + old_obj: Optional[Union[v1Event,v2beta1Event,v2beta2Event]] = None - def get_event(self) -> Optional[Union[v1Event, v2beta1Event, v2beta2Event]]: + def get_event(self) -> Optional[Union[v1Event,v2beta1Event,v2beta2Event]]: return self.obj @@ -586,49 +364,21 @@ def get_horizontalpodautoscaler(self) -> Optional[HorizontalPodAutoscaler]: return self._obj @staticmethod - def from_params( - params: HorizontalPodAutoscalerAttributes, - ) -> Optional["HorizontalPodAutoscalerEvent"]: + def from_params(params: HorizontalPodAutoscalerAttributes) -> Optional["HorizontalPodAutoscalerEvent"]: try: - obj = HorizontalPodAutoscaler.readNamespacedHorizontalPodAutoscaler( - name=params.name, namespace=params.namespace - ).obj + obj = HorizontalPodAutoscaler.readNamespacedHorizontalPodAutoscaler(name=params.name, namespace=params.namespace).obj except Exception: - logging.error( - f"Could not load HorizontalPodAutoscaler {params}", exc_info=True - ) + logging.error(f"Could not load HorizontalPodAutoscaler {params}", exc_info=True) return None return HorizontalPodAutoscalerEvent(obj=obj, named_sinks=params.named_sinks) @dataclass -class HorizontalPodAutoscalerChangeEvent( - HorizontalPodAutoscalerEvent, KubernetesAnyChangeEvent -): - obj: Optional[ - Union[ - v1HorizontalPodAutoscaler, - v2beta1HorizontalPodAutoscaler, - v2beta2HorizontalPodAutoscaler, - ] - ] = None - old_obj: Optional[ - Union[ - v1HorizontalPodAutoscaler, - v2beta1HorizontalPodAutoscaler, - v2beta2HorizontalPodAutoscaler, - ] - ] = None - - def get_horizontalpodautoscaler( - self, - ) -> Optional[ - Union[ - v1HorizontalPodAutoscaler, - v2beta1HorizontalPodAutoscaler, - v2beta2HorizontalPodAutoscaler, - ] - ]: +class HorizontalPodAutoscalerChangeEvent(HorizontalPodAutoscalerEvent, KubernetesAnyChangeEvent): + obj: Optional[Union[v1HorizontalPodAutoscaler,v2beta1HorizontalPodAutoscaler,v2beta2HorizontalPodAutoscaler]] = None + old_obj: Optional[Union[v1HorizontalPodAutoscaler,v2beta1HorizontalPodAutoscaler,v2beta2HorizontalPodAutoscaler]] = None + + def get_horizontalpodautoscaler(self) -> Optional[Union[v1HorizontalPodAutoscaler,v2beta1HorizontalPodAutoscaler,v2beta2HorizontalPodAutoscaler]]: return self.obj @@ -636,6 +386,7 @@ class NodeAttributes(ExecutionEventBaseParams): name: str + @dataclass class NodeEvent(KubernetesResourceEvent): def __init__(self, obj: Node, named_sinks: List[str]): @@ -656,10 +407,10 @@ def from_params(params: NodeAttributes) -> Optional["NodeEvent"]: @dataclass class NodeChangeEvent(NodeEvent, KubernetesAnyChangeEvent): - obj: Optional[Union[v1Node, v2beta1Node, v2beta2Node]] = None - old_obj: Optional[Union[v1Node, v2beta1Node, v2beta2Node]] = None + obj: Optional[Union[v1Node,v2beta1Node,v2beta2Node]] = None + old_obj: Optional[Union[v1Node,v2beta1Node,v2beta2Node]] = None - def get_node(self) -> Optional[Union[v1Node, v2beta1Node, v2beta2Node]]: + def get_node(self) -> Optional[Union[v1Node,v2beta1Node,v2beta2Node]]: return self.obj @@ -667,6 +418,7 @@ class ClusterRoleAttributes(ExecutionEventBaseParams): name: str + @dataclass class ClusterRoleEvent(KubernetesResourceEvent): def __init__(self, obj: ClusterRole, named_sinks: List[str]): @@ -687,14 +439,10 @@ def from_params(params: ClusterRoleAttributes) -> Optional["ClusterRoleEvent"]: @dataclass class ClusterRoleChangeEvent(ClusterRoleEvent, KubernetesAnyChangeEvent): - obj: Optional[Union[v1ClusterRole, v2beta1ClusterRole, v2beta2ClusterRole]] = None - old_obj: Optional[ - Union[v1ClusterRole, v2beta1ClusterRole, v2beta2ClusterRole] - ] = None - - def get_clusterrole( - self, - ) -> Optional[Union[v1ClusterRole, v2beta1ClusterRole, v2beta2ClusterRole]]: + obj: Optional[Union[v1ClusterRole,v2beta1ClusterRole,v2beta2ClusterRole]] = None + old_obj: Optional[Union[v1ClusterRole,v2beta1ClusterRole,v2beta2ClusterRole]] = None + + def get_clusterrole(self) -> Optional[Union[v1ClusterRole,v2beta1ClusterRole,v2beta2ClusterRole]]: return self.obj @@ -702,6 +450,7 @@ class ClusterRoleBindingAttributes(ExecutionEventBaseParams): name: str + @dataclass class ClusterRoleBindingEvent(KubernetesResourceEvent): def __init__(self, obj: ClusterRoleBinding, named_sinks: List[str]): @@ -711,9 +460,7 @@ def get_clusterrolebinding(self) -> Optional[ClusterRoleBinding]: return self._obj @staticmethod - def from_params( - params: ClusterRoleBindingAttributes, - ) -> Optional["ClusterRoleBindingEvent"]: + def from_params(params: ClusterRoleBindingAttributes) -> Optional["ClusterRoleBindingEvent"]: try: obj = ClusterRoleBinding.readClusterRoleBinding(name=params.name).obj except Exception: @@ -724,24 +471,10 @@ def from_params( @dataclass class ClusterRoleBindingChangeEvent(ClusterRoleBindingEvent, KubernetesAnyChangeEvent): - obj: Optional[ - Union[ - v1ClusterRoleBinding, v2beta1ClusterRoleBinding, v2beta2ClusterRoleBinding - ] - ] = None - old_obj: Optional[ - Union[ - v1ClusterRoleBinding, v2beta1ClusterRoleBinding, v2beta2ClusterRoleBinding - ] - ] = None - - def get_clusterrolebinding( - self, - ) -> Optional[ - Union[ - v1ClusterRoleBinding, v2beta1ClusterRoleBinding, v2beta2ClusterRoleBinding - ] - ]: + obj: Optional[Union[v1ClusterRoleBinding,v2beta1ClusterRoleBinding,v2beta2ClusterRoleBinding]] = None + old_obj: Optional[Union[v1ClusterRoleBinding,v2beta1ClusterRoleBinding,v2beta2ClusterRoleBinding]] = None + + def get_clusterrolebinding(self) -> Optional[Union[v1ClusterRoleBinding,v2beta1ClusterRoleBinding,v2beta2ClusterRoleBinding]]: return self.obj @@ -761,9 +494,7 @@ def get_job(self) -> Optional[RobustaJob]: @staticmethod def from_params(params: JobAttributes) -> Optional["JobEvent"]: try: - obj = RobustaJob.readNamespacedJob( - name=params.name, namespace=params.namespace - ).obj + obj = RobustaJob.readNamespacedJob(name=params.name, namespace=params.namespace).obj except Exception: logging.error(f"Could not load Job {params}", exc_info=True) return None @@ -783,6 +514,7 @@ class NamespaceAttributes(ExecutionEventBaseParams): name: str + @dataclass class NamespaceEvent(KubernetesResourceEvent): def __init__(self, obj: Namespace, named_sinks: List[str]): @@ -803,12 +535,10 @@ def from_params(params: NamespaceAttributes) -> Optional["NamespaceEvent"]: @dataclass class NamespaceChangeEvent(NamespaceEvent, KubernetesAnyChangeEvent): - obj: Optional[Union[v1Namespace, v2beta1Namespace, v2beta2Namespace]] = None - old_obj: Optional[Union[v1Namespace, v2beta1Namespace, v2beta2Namespace]] = None + obj: Optional[Union[v1Namespace,v2beta1Namespace,v2beta2Namespace]] = None + old_obj: Optional[Union[v1Namespace,v2beta1Namespace,v2beta2Namespace]] = None - def get_namespace( - self, - ) -> Optional[Union[v1Namespace, v2beta1Namespace, v2beta2Namespace]]: + def get_namespace(self) -> Optional[Union[v1Namespace,v2beta1Namespace,v2beta2Namespace]]: return self.obj @@ -826,13 +556,9 @@ def get_serviceaccount(self) -> Optional[ServiceAccount]: return self._obj @staticmethod - def from_params( - params: ServiceAccountAttributes, - ) -> Optional["ServiceAccountEvent"]: + def from_params(params: ServiceAccountAttributes) -> Optional["ServiceAccountEvent"]: try: - obj = ServiceAccount.readNamespacedServiceAccount( - name=params.name, namespace=params.namespace - ).obj + obj = ServiceAccount.readNamespacedServiceAccount(name=params.name, namespace=params.namespace).obj except Exception: logging.error(f"Could not load ServiceAccount {params}", exc_info=True) return None @@ -841,34 +567,27 @@ def from_params( @dataclass class ServiceAccountChangeEvent(ServiceAccountEvent, KubernetesAnyChangeEvent): - obj: Optional[ - Union[v1ServiceAccount, v2beta1ServiceAccount, v2beta2ServiceAccount] - ] = None - old_obj: Optional[ - Union[v1ServiceAccount, v2beta1ServiceAccount, v2beta2ServiceAccount] - ] = None - - def get_serviceaccount( - self, - ) -> Optional[ - Union[v1ServiceAccount, v2beta1ServiceAccount, v2beta2ServiceAccount] - ]: + obj: Optional[Union[v1ServiceAccount,v2beta1ServiceAccount,v2beta2ServiceAccount]] = None + old_obj: Optional[Union[v1ServiceAccount,v2beta1ServiceAccount,v2beta2ServiceAccount]] = None + + def get_serviceaccount(self) -> Optional[Union[v1ServiceAccount,v2beta1ServiceAccount,v2beta2ServiceAccount]]: return self.obj + KIND_TO_EVENT_CLASS = { - "pod": PodChangeEvent, - "replicaset": ReplicaSetChangeEvent, - "daemonset": DaemonSetChangeEvent, - "deployment": DeploymentChangeEvent, - "statefulset": StatefulSetChangeEvent, - "service": ServiceChangeEvent, - "event": EventChangeEvent, - "horizontalpodautoscaler": HorizontalPodAutoscalerChangeEvent, - "node": NodeChangeEvent, - "clusterrole": ClusterRoleChangeEvent, - "clusterrolebinding": ClusterRoleBindingChangeEvent, - "job": JobChangeEvent, - "namespace": NamespaceChangeEvent, - "serviceaccount": ServiceAccountChangeEvent, + 'pod': PodChangeEvent, + 'replicaset': ReplicaSetChangeEvent, + 'daemonset': DaemonSetChangeEvent, + 'deployment': DeploymentChangeEvent, + 'statefulset': StatefulSetChangeEvent, + 'service': ServiceChangeEvent, + 'event': EventChangeEvent, + 'horizontalpodautoscaler': HorizontalPodAutoscalerChangeEvent, + 'node': NodeChangeEvent, + 'clusterrole': ClusterRoleChangeEvent, + 'clusterrolebinding': ClusterRoleBindingChangeEvent, + 'job': JobChangeEvent, + 'namespace': NamespaceChangeEvent, + 'serviceaccount': ServiceAccountChangeEvent } diff --git a/src/robusta/integrations/kubernetes/autogenerated/models.py b/src/robusta/integrations/kubernetes/autogenerated/models.py index d099fac4e..7462dd0a3 100644 --- a/src/robusta/integrations/kubernetes/autogenerated/models.py +++ b/src/robusta/integrations/kubernetes/autogenerated/models.py @@ -3,8 +3,11 @@ from .v1.models import KIND_TO_MODEL_CLASS as v1 from .v2beta1.models import KIND_TO_MODEL_CLASS as v2beta1 from .v2beta2.models import KIND_TO_MODEL_CLASS as v2beta2 - -VERSION_KIND_TO_MODEL_CLASS = {"v1": v1, "v2beta1": v2beta1, "v2beta2": v2beta2} +VERSION_KIND_TO_MODEL_CLASS = { + 'v1': v1, + 'v2beta1': v2beta1, + 'v2beta2': v2beta2 +} def get_api_version(apiVersion: str): diff --git a/src/robusta/integrations/kubernetes/autogenerated/triggers.py b/src/robusta/integrations/kubernetes/autogenerated/triggers.py index b64aa1147..b1bb52b82 100644 --- a/src/robusta/integrations/kubernetes/autogenerated/triggers.py +++ b/src/robusta/integrations/kubernetes/autogenerated/triggers.py @@ -9,12 +9,14 @@ # Pod Triggers class PodAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Pod", - operation=None, - name_prefix=name_prefix, + kind="Pod", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -23,12 +25,14 @@ def get_execution_event_type() -> type: class PodCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Pod", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="Pod", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -37,12 +41,14 @@ def get_execution_event_type() -> type: class PodDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Pod", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="Pod", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -51,12 +57,14 @@ def get_execution_event_type() -> type: class PodUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Pod", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="Pod", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -66,12 +74,14 @@ def get_execution_event_type() -> type: # ReplicaSet Triggers class ReplicaSetAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ReplicaSet", - operation=None, - name_prefix=name_prefix, + kind="ReplicaSet", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -80,12 +90,14 @@ def get_execution_event_type() -> type: class ReplicaSetCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ReplicaSet", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="ReplicaSet", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -94,12 +106,14 @@ def get_execution_event_type() -> type: class ReplicaSetDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ReplicaSet", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="ReplicaSet", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -108,12 +122,14 @@ def get_execution_event_type() -> type: class ReplicaSetUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ReplicaSet", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="ReplicaSet", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -123,12 +139,14 @@ def get_execution_event_type() -> type: # DaemonSet Triggers class DaemonSetAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="DaemonSet", - operation=None, - name_prefix=name_prefix, + kind="DaemonSet", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -137,12 +155,14 @@ def get_execution_event_type() -> type: class DaemonSetCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="DaemonSet", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="DaemonSet", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -151,12 +171,14 @@ def get_execution_event_type() -> type: class DaemonSetDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="DaemonSet", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="DaemonSet", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -165,12 +187,14 @@ def get_execution_event_type() -> type: class DaemonSetUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="DaemonSet", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="DaemonSet", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -180,12 +204,14 @@ def get_execution_event_type() -> type: # Deployment Triggers class DeploymentAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Deployment", - operation=None, - name_prefix=name_prefix, + kind="Deployment", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -194,12 +220,14 @@ def get_execution_event_type() -> type: class DeploymentCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Deployment", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="Deployment", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -208,12 +236,14 @@ def get_execution_event_type() -> type: class DeploymentDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Deployment", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="Deployment", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -222,12 +252,14 @@ def get_execution_event_type() -> type: class DeploymentUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Deployment", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="Deployment", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -237,12 +269,14 @@ def get_execution_event_type() -> type: # StatefulSet Triggers class StatefulSetAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="StatefulSet", - operation=None, - name_prefix=name_prefix, + kind="StatefulSet", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -251,12 +285,14 @@ def get_execution_event_type() -> type: class StatefulSetCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="StatefulSet", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="StatefulSet", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -265,12 +301,14 @@ def get_execution_event_type() -> type: class StatefulSetDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="StatefulSet", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="StatefulSet", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -279,12 +317,14 @@ def get_execution_event_type() -> type: class StatefulSetUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="StatefulSet", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="StatefulSet", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -294,12 +334,14 @@ def get_execution_event_type() -> type: # Service Triggers class ServiceAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Service", - operation=None, - name_prefix=name_prefix, + kind="Service", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -308,12 +350,14 @@ def get_execution_event_type() -> type: class ServiceCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Service", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="Service", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -322,12 +366,14 @@ def get_execution_event_type() -> type: class ServiceDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Service", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="Service", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -336,12 +382,14 @@ def get_execution_event_type() -> type: class ServiceUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Service", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="Service", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -351,12 +399,14 @@ def get_execution_event_type() -> type: # Event Triggers class EventAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Event", - operation=None, - name_prefix=name_prefix, + kind="Event", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -365,12 +415,14 @@ def get_execution_event_type() -> type: class EventCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Event", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="Event", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -379,12 +431,14 @@ def get_execution_event_type() -> type: class EventDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Event", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="Event", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -393,12 +447,14 @@ def get_execution_event_type() -> type: class EventUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Event", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="Event", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -408,12 +464,14 @@ def get_execution_event_type() -> type: # HorizontalPodAutoscaler Triggers class HorizontalPodAutoscalerAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="HorizontalPodAutoscaler", - operation=None, - name_prefix=name_prefix, + kind="HorizontalPodAutoscaler", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -422,12 +480,14 @@ def get_execution_event_type() -> type: class HorizontalPodAutoscalerCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="HorizontalPodAutoscaler", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="HorizontalPodAutoscaler", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -436,12 +496,14 @@ def get_execution_event_type() -> type: class HorizontalPodAutoscalerDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="HorizontalPodAutoscaler", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="HorizontalPodAutoscaler", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -450,12 +512,14 @@ def get_execution_event_type() -> type: class HorizontalPodAutoscalerUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="HorizontalPodAutoscaler", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="HorizontalPodAutoscaler", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -465,12 +529,14 @@ def get_execution_event_type() -> type: # Node Triggers class NodeAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Node", - operation=None, - name_prefix=name_prefix, + kind="Node", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -479,12 +545,14 @@ def get_execution_event_type() -> type: class NodeCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Node", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="Node", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -493,12 +561,14 @@ def get_execution_event_type() -> type: class NodeDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Node", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="Node", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -507,12 +577,14 @@ def get_execution_event_type() -> type: class NodeUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Node", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="Node", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -522,12 +594,14 @@ def get_execution_event_type() -> type: # ClusterRole Triggers class ClusterRoleAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ClusterRole", - operation=None, - name_prefix=name_prefix, + kind="ClusterRole", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -536,12 +610,14 @@ def get_execution_event_type() -> type: class ClusterRoleCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ClusterRole", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="ClusterRole", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -550,12 +626,14 @@ def get_execution_event_type() -> type: class ClusterRoleDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ClusterRole", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="ClusterRole", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -564,12 +642,14 @@ def get_execution_event_type() -> type: class ClusterRoleUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ClusterRole", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="ClusterRole", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -579,12 +659,14 @@ def get_execution_event_type() -> type: # ClusterRoleBinding Triggers class ClusterRoleBindingAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ClusterRoleBinding", - operation=None, - name_prefix=name_prefix, + kind="ClusterRoleBinding", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -593,12 +675,14 @@ def get_execution_event_type() -> type: class ClusterRoleBindingCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ClusterRoleBinding", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="ClusterRoleBinding", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -607,12 +691,14 @@ def get_execution_event_type() -> type: class ClusterRoleBindingDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ClusterRoleBinding", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="ClusterRoleBinding", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -621,12 +707,14 @@ def get_execution_event_type() -> type: class ClusterRoleBindingUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ClusterRoleBinding", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="ClusterRoleBinding", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -636,12 +724,14 @@ def get_execution_event_type() -> type: # Job Triggers class JobAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Job", - operation=None, - name_prefix=name_prefix, + kind="Job", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -650,12 +740,14 @@ def get_execution_event_type() -> type: class JobCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Job", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="Job", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -664,12 +756,14 @@ def get_execution_event_type() -> type: class JobDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Job", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="Job", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -678,12 +772,14 @@ def get_execution_event_type() -> type: class JobUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Job", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="Job", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -693,12 +789,14 @@ def get_execution_event_type() -> type: # Namespace Triggers class NamespaceAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Namespace", - operation=None, - name_prefix=name_prefix, + kind="Namespace", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -707,12 +805,14 @@ def get_execution_event_type() -> type: class NamespaceCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Namespace", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="Namespace", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -721,12 +821,14 @@ def get_execution_event_type() -> type: class NamespaceDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Namespace", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="Namespace", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -735,12 +837,14 @@ def get_execution_event_type() -> type: class NamespaceUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Namespace", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="Namespace", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -750,12 +854,14 @@ def get_execution_event_type() -> type: # ServiceAccount Triggers class ServiceAccountAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ServiceAccount", - operation=None, - name_prefix=name_prefix, + kind="ServiceAccount", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -764,12 +870,14 @@ def get_execution_event_type() -> type: class ServiceAccountCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ServiceAccount", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="ServiceAccount", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -778,12 +886,14 @@ def get_execution_event_type() -> type: class ServiceAccountDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ServiceAccount", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="ServiceAccount", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -792,12 +902,14 @@ def get_execution_event_type() -> type: class ServiceAccountUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="ServiceAccount", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="ServiceAccount", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -807,12 +919,14 @@ def get_execution_event_type() -> type: # Kubernetes Any Triggers class KubernetesAnyAllChangesTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Any", - operation=None, - name_prefix=name_prefix, + kind="Any", + operation=None, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -821,12 +935,14 @@ def get_execution_event_type() -> type: class KubernetesAnyCreateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Any", - operation=K8sOperationType.CREATE, - name_prefix=name_prefix, + kind="Any", + operation=K8sOperationType.CREATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -835,12 +951,14 @@ def get_execution_event_type() -> type: class KubernetesAnyDeleteTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Any", - operation=K8sOperationType.DELETE, - name_prefix=name_prefix, + kind="Any", + operation=K8sOperationType.DELETE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -849,12 +967,14 @@ def get_execution_event_type() -> type: class KubernetesAnyUpdateTrigger(K8sBaseTrigger): - def __init__(self, name_prefix: str = None, namespace_prefix: str = None): + + def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): super().__init__( - kind="Any", - operation=K8sOperationType.UPDATE, - name_prefix=name_prefix, + kind="Any", + operation=K8sOperationType.UPDATE, + name_prefix=name_prefix, namespace_prefix=namespace_prefix, + labels_selector=labels_selector, ) @staticmethod @@ -885,9 +1005,7 @@ class K8sTriggers(BaseModel): on_event_create: Optional[EventCreateTrigger] on_event_delete: Optional[EventDeleteTrigger] on_event_update: Optional[EventUpdateTrigger] - on_horizontalpodautoscaler_all_changes: Optional[ - HorizontalPodAutoscalerAllChangesTrigger - ] + on_horizontalpodautoscaler_all_changes: Optional[HorizontalPodAutoscalerAllChangesTrigger] on_horizontalpodautoscaler_create: Optional[HorizontalPodAutoscalerCreateTrigger] on_horizontalpodautoscaler_delete: Optional[HorizontalPodAutoscalerDeleteTrigger] on_horizontalpodautoscaler_update: Optional[HorizontalPodAutoscalerUpdateTrigger] diff --git a/src/robusta/integrations/kubernetes/autogenerated/v1/models.py b/src/robusta/integrations/kubernetes/autogenerated/v1/models.py index 48cffb11c..c3b814426 100644 --- a/src/robusta/integrations/kubernetes/autogenerated/v1/models.py +++ b/src/robusta/integrations/kubernetes/autogenerated/v1/models.py @@ -1,22 +1,22 @@ # This file was autogenerated. Do not edit. from hikaru.model.rel_1_16.v1 import * -from ...custom_models import RobustaPod, RobustaDeployment, RobustaJob +from ...custom_models import RobustaPod,RobustaDeployment,RobustaJob KIND_TO_MODEL_CLASS = { - "Pod": RobustaPod, - "ReplicaSet": ReplicaSet, - "DaemonSet": DaemonSet, - "Deployment": RobustaDeployment, - "StatefulSet": StatefulSet, - "Service": Service, - "Event": Event, - "HorizontalPodAutoscaler": HorizontalPodAutoscaler, - "Node": Node, - "ClusterRole": ClusterRole, - "ClusterRoleBinding": ClusterRoleBinding, - "Job": RobustaJob, - "Namespace": Namespace, - "ServiceAccount": ServiceAccount, + 'Pod': RobustaPod, + 'ReplicaSet': ReplicaSet, + 'DaemonSet': DaemonSet, + 'Deployment': RobustaDeployment, + 'StatefulSet': StatefulSet, + 'Service': Service, + 'Event': Event, + 'HorizontalPodAutoscaler': HorizontalPodAutoscaler, + 'Node': Node, + 'ClusterRole': ClusterRole, + 'ClusterRoleBinding': ClusterRoleBinding, + 'Job': RobustaJob, + 'Namespace': Namespace, + 'ServiceAccount': ServiceAccount } diff --git a/src/robusta/integrations/kubernetes/autogenerated/v2beta1/models.py b/src/robusta/integrations/kubernetes/autogenerated/v2beta1/models.py index 8aa7cd48b..a0383558d 100644 --- a/src/robusta/integrations/kubernetes/autogenerated/v2beta1/models.py +++ b/src/robusta/integrations/kubernetes/autogenerated/v2beta1/models.py @@ -1,22 +1,22 @@ # This file was autogenerated. Do not edit. from hikaru.model.rel_1_16.v2beta1 import * -from ...custom_models import RobustaPod, RobustaDeployment, RobustaJob +from ...custom_models import RobustaPod,RobustaDeployment,RobustaJob KIND_TO_MODEL_CLASS = { - "Pod": RobustaPod, - "ReplicaSet": ReplicaSet, - "DaemonSet": DaemonSet, - "Deployment": RobustaDeployment, - "StatefulSet": StatefulSet, - "Service": Service, - "Event": Event, - "HorizontalPodAutoscaler": HorizontalPodAutoscaler, - "Node": Node, - "ClusterRole": ClusterRole, - "ClusterRoleBinding": ClusterRoleBinding, - "Job": RobustaJob, - "Namespace": Namespace, - "ServiceAccount": ServiceAccount, + 'Pod': RobustaPod, + 'ReplicaSet': ReplicaSet, + 'DaemonSet': DaemonSet, + 'Deployment': RobustaDeployment, + 'StatefulSet': StatefulSet, + 'Service': Service, + 'Event': Event, + 'HorizontalPodAutoscaler': HorizontalPodAutoscaler, + 'Node': Node, + 'ClusterRole': ClusterRole, + 'ClusterRoleBinding': ClusterRoleBinding, + 'Job': RobustaJob, + 'Namespace': Namespace, + 'ServiceAccount': ServiceAccount } diff --git a/src/robusta/integrations/kubernetes/autogenerated/v2beta2/models.py b/src/robusta/integrations/kubernetes/autogenerated/v2beta2/models.py index f6712bf55..62ee1ebaa 100644 --- a/src/robusta/integrations/kubernetes/autogenerated/v2beta2/models.py +++ b/src/robusta/integrations/kubernetes/autogenerated/v2beta2/models.py @@ -1,22 +1,22 @@ # This file was autogenerated. Do not edit. from hikaru.model.rel_1_16.v2beta2 import * -from ...custom_models import RobustaPod, RobustaDeployment, RobustaJob +from ...custom_models import RobustaPod,RobustaDeployment,RobustaJob KIND_TO_MODEL_CLASS = { - "Pod": RobustaPod, - "ReplicaSet": ReplicaSet, - "DaemonSet": DaemonSet, - "Deployment": RobustaDeployment, - "StatefulSet": StatefulSet, - "Service": Service, - "Event": Event, - "HorizontalPodAutoscaler": HorizontalPodAutoscaler, - "Node": Node, - "ClusterRole": ClusterRole, - "ClusterRoleBinding": ClusterRoleBinding, - "Job": RobustaJob, - "Namespace": Namespace, - "ServiceAccount": ServiceAccount, + 'Pod': RobustaPod, + 'ReplicaSet': ReplicaSet, + 'DaemonSet': DaemonSet, + 'Deployment': RobustaDeployment, + 'StatefulSet': StatefulSet, + 'Service': Service, + 'Event': Event, + 'HorizontalPodAutoscaler': HorizontalPodAutoscaler, + 'Node': Node, + 'ClusterRole': ClusterRole, + 'ClusterRoleBinding': ClusterRoleBinding, + 'Job': RobustaJob, + 'Namespace': Namespace, + 'ServiceAccount': ServiceAccount } diff --git a/src/robusta/integrations/kubernetes/base_triggers.py b/src/robusta/integrations/kubernetes/base_triggers.py index 0e96e701b..c4c95f90f 100644 --- a/src/robusta/integrations/kubernetes/base_triggers.py +++ b/src/robusta/integrations/kubernetes/base_triggers.py @@ -1,7 +1,7 @@ import logging import hikaru from typing import Dict, Any, Optional -from pydantic import BaseModel +from pydantic import BaseModel, PrivateAttr from .autogenerated.events import KIND_TO_EVENT_CLASS from .autogenerated.models import get_api_version @@ -40,6 +40,22 @@ class K8sBaseTrigger(BaseTrigger): operation: K8sOperationType = None name_prefix: str = None namespace_prefix: str = None + labels_selector: str = None + _labels_map: Dict = PrivateAttr() + + def __init__(self, *args, **data): + super().__init__(*args, **data) + if self.labels_selector: + labels = self.labels_selector.split(",") + self._labels_map = {} + for label in labels: + label_parts = label.split("=") + if len(label_parts) != 2: + msg = f"Illegal label selector {label}" + logging.error(msg) + raise Exception(msg) + + self._labels_map[label_parts[0].strip()] = label_parts[1].strip() def get_trigger_event(self): return K8sTriggerEvent.__name__ @@ -63,6 +79,13 @@ def should_fire(self, event: TriggerEvent): if not prefix_match(self.namespace_prefix, meta.get("namespace", "")): return False + labels_map = getattr(self, "_labels_map", None) + if labels_map: + obj_labels = meta.get("labels", {}) + for label_key, label_value in labels_map.items(): + if label_value != obj_labels.get(label_key, ""): + return False + return True @classmethod From e73025143ae6cbedf7aa413b305d2bc252130a88 Mon Sep 17 00:00:00 2001 From: Shahar Lev Date: Tue, 11 Jan 2022 18:29:04 +0200 Subject: [PATCH 2/3] ssh keyscan for bitbucket too (#144) --- src/robusta/integrations/git/git_repo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/robusta/integrations/git/git_repo.py b/src/robusta/integrations/git/git_repo.py index f23dfbec7..e4dc51520 100644 --- a/src/robusta/integrations/git/git_repo.py +++ b/src/robusta/integrations/git/git_repo.py @@ -86,7 +86,7 @@ def init_key(self, git_key): os.chmod(key_file_name, 0o400) if not os.path.exists(SSH_ROOT_DIR): os.mkdir(SSH_ROOT_DIR) - os.system(f"ssh-keyscan -H github.com >> {SSH_ROOT_DIR}/known_hosts") + os.system(f"ssh-keyscan -H github.com bitbucket.org >> {SSH_ROOT_DIR}/known_hosts") return key_file_name @staticmethod From 9ba34384831386be34fc7032b11ad3e1887b97a4 Mon Sep 17 00:00:00 2001 From: Robusta Runner Date: Tue, 11 Jan 2022 19:13:48 +0200 Subject: [PATCH 3/3] docs fix --- docs/catalog/triggers/kubernetes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/catalog/triggers/kubernetes.rst b/docs/catalog/triggers/kubernetes.rst index b774a3ede..143ed5386 100644 --- a/docs/catalog/triggers/kubernetes.rst +++ b/docs/catalog/triggers/kubernetes.rst @@ -3,7 +3,7 @@ Kubernetes Robusta can run playbooks in response to Kubernetes API Server events. -When a ``Pod`` is created, or when a ``Deployment`` is changed, we can trigger Robusta actions. +For example, when a ``Pod`` is created, or when a ``Deployment`` is changed, we can trigger Robusta actions. Configuration example ^^^^^^^^^^^^^^^^^^^^^^