Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/robusta-dev/robusta
Browse files Browse the repository at this point in the history
  • Loading branch information
aantn committed Jan 12, 2022
2 parents dc6e680 + 9ba3438 commit 4afb338
Show file tree
Hide file tree
Showing 10 changed files with 610 additions and 718 deletions.
27 changes: 27 additions & 0 deletions docs/catalog/triggers/kubernetes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
Kubernetes
############################

Robusta can run playbooks in response to Kubernetes API Server events.

For example, 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:
Expand Down Expand Up @@ -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.
10 changes: 6 additions & 4 deletions scripts/generate_kubernetes_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/robusta/integrations/git/git_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 4afb338

Please sign in to comment.