-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into json-change-tracker
- Loading branch information
Showing
9 changed files
with
131 additions
and
53 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,16 @@ name: Test robusta with pytest | |
on: [push, pull_request, workflow_dispatch] | ||
|
||
jobs: | ||
check: | ||
name: Pre-commit checks | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
- uses: pre-commit/[email protected] | ||
|
||
run_tests: | ||
needs: check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import logging | ||
import os | ||
import uuid | ||
|
||
from hikaru.model.rel_1_26 import Container, PodSpec | ||
from robusta.api import ( | ||
RUNNER_SERVICE_ACCOUNT, | ||
ExecutionBaseEvent, | ||
FileBlock, | ||
MarkdownBlock, | ||
PodRunningParams, | ||
RobustaJob, | ||
action, | ||
) | ||
from robusta.utils.parsing import format_event_templated_string | ||
|
||
IMAGE: str = os.getenv("KUBECTL_IMAGE_OVERRIDE", f"bitnami/kubectl:latest") | ||
|
||
|
||
class KubectlParams(PodRunningParams): | ||
""" | ||
:var kubectl_command: The full kubectl command to run, formatted as a shell command string. | ||
:var description: A description of the command ran. | ||
:var timeout: The maximum time (in seconds) to wait for the kubectl command to complete. Default is 3600 seconds. | ||
""" | ||
|
||
command: str = None | ||
description: str = None | ||
timeout: int = 3600 | ||
|
||
|
||
@action | ||
def kubectl_command(event: ExecutionBaseEvent, params: KubectlParams): | ||
""" | ||
Runs a custom kubectl command inside a Kubernetes pod using a Job. | ||
""" | ||
|
||
subject = event.get_subject() | ||
formatted_kubectl_command = format_event_templated_string(subject, params.command) | ||
logging.info(f"kubectl_command running '{params.description}'") | ||
logging.debug(f"kubectl_command: '{formatted_kubectl_command}'") | ||
|
||
spec = PodSpec( | ||
serviceAccountName=RUNNER_SERVICE_ACCOUNT, | ||
containers=[ | ||
Container( | ||
name="kubectl", | ||
image=IMAGE, | ||
imagePullPolicy="Always", | ||
command=["/bin/sh", "-c"], | ||
args=[formatted_kubectl_command] | ||
) | ||
], | ||
restartPolicy="Never", | ||
) | ||
|
||
try: | ||
kubectl_response = RobustaJob.run_simple_job_spec( | ||
spec, | ||
f"robusta-kubectl-command-{str(uuid.uuid4())}", | ||
params.timeout, | ||
custom_annotations=params.custom_annotations, | ||
ttl_seconds_after_finished=43200, # 12 hours | ||
delete_job_post_execution=True, | ||
process_name=False, | ||
) | ||
descriptiont_text = params.description if params.description else "Kubectl Command" | ||
event.add_enrichment( | ||
[ | ||
MarkdownBlock(f"*{formatted_kubectl_command}*"), | ||
FileBlock(f"kubectl.txt", kubectl_response.encode()), | ||
], title=descriptiont_text | ||
) | ||
except Exception: | ||
logging.exception("Error running kubectl command") | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters