Skip to content

Commit

Permalink
fix: remove space
Browse files Browse the repository at this point in the history
Signed-off-by: realanna <anna.reale@dynatrace.com>
  • Loading branch information
RealAnna committed Jun 13, 2023
1 parent 643c858 commit 5faae63
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
27 changes: 25 additions & 2 deletions docs/content/en/docs/implementing/tasks/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,36 @@ hidechildren: false # this flag hides all sub-pages in the sidebar-multicard.htm
resource. A task definition can use a python runtime to specify a task that runs python3 code.
The python code can be specified as:
- inline
- an HTTP script
- an HTTP reference to a script
- another `KeptnTaskDefinition`
- a [ConfigMap](https://kubernetes.io/docs/concepts/configuration/configmap/)
resource that is populated with the code to execute

## Inline
You can embed python code directly in the taskDefinition.
Consider the following example, where we print data stored in the parameters map:
{{< readfile file="/yaml/python_execution/taskdefinition_pyfunction_inline.yaml" code="true" lang="yaml" >}}

## Http reference
You can refer to a code stored online, for instance we have a few examples available [here](https://github.com/keptn/lifecycle-toolkit/tree/main/python-runtime/samples)
Consider the following:
{{< readfile file="/yaml/python_execution/taskdefinition_pyfunction_configmap.yaml" code="true" lang="yaml" >}}

## Refer to another TaskDefinition
You can refer to an existing taskDefinition. Consider the following example, this will call the inline example but will override the data printed with what is specified in the task:
{{< readfile file="/yaml/python_execution/taskdefinition_pyfunction_recursive.yaml" code="true" lang="yaml" >}}

## Config Map

Consider the following example:
{{< readfile file="/yaml/python_ execution/taskdefinition_pyfunction_configmap.yaml" code="true" lang="yaml" >}}
{{< readfile file="/yaml/python_execution/taskdefinition_pyfunction_configmap.yaml" code="true" lang="yaml" >}}

## Allowed libraries for the Python runtime
The following example shows how to use few of the allowed packages, namely: requests, json, git, yaml
{{< readfile file="/yaml/python_execution/taskdefinition_pyfunction_inline_printargs_py.yaml" code="true" lang="yaml" >}}

## Passing secrets, env vars and modifying the python command
In the following examples you can see how to pass data inside the parameter map, how to load a secret in your code and finally how to modify the python command.
In this case the container will run with the option -h which will print the help of the python3 command.

{{< readfile file="/yaml/python_execution/taskdefinition_pyfunction_use_envvars.yaml" code="true" lang="yaml" >}}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: lifecycle.keptn.sh/v1alpha3
kind: KeptnTaskDefinition
metadata:
name: scheduled-deployment
name: scheduled-deployment-inline
spec:
python:
parameters:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: lifecycle.keptn.sh/v1alpha3
kind: KeptnTaskDefinition
metadata:
name: scheduled-deployment-2
spec:
python:
parameters:
map:
mydata: "my-other-data"
functionRef:
name: scheduled-deployment-inline
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
SECURE_DATA: dG9rZW46IG15dG9rZW4=
---
apiVersion: lifecycle.keptn.sh/v1alpha3
kind: KeptnTaskDefinition
metadata:
name: pre-deployment-hello
annotations:
python: test
spec:
python:
parameters:
map:
user: "myuser"
secureParameters:
secret: mysecret
cmdParameters: "-h"
inline:
code: |
import os
import yaml
data = os.getenv('DATA')
dct = yaml.safe_load(data)
USER= dct['user']
PASSWORD = os.environ.get('SECURE_DATA')
print(USER,PASSWORD)

0 comments on commit 5faae63

Please sign in to comment.