Skip to content

Commit

Permalink
docs: add context, update secret wording (#781)
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Schrottner <simon.schrottner@gmail.com>
  • Loading branch information
agardnerIT and aepfli committed Feb 7, 2023
1 parent 1a79def commit 29b00cb
Showing 1 changed file with 64 additions and 1 deletion.
65 changes: 64 additions & 1 deletion docs/content/en/docs/concepts/tasks/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,76 @@ spec:
secret: slack-token
```

## Context

A context environment variable is available via `Deno.env.get("CONTEXT")`. It can be used like this:

```javascript
let context = Deno.env.get("CONTEXT");
if (contextdata.objectType == "Application") {
let application_name = contextdata.appName;
let application_version = contextdata.appVersion;
}
if (contextdata.objectType == "Workload") {
let application_name = contextdata.appName;
let workload_name = contextdata.workloadName;
let workload_version = contextdata.workloadVersion;
}
```
## Input Parameters and Secret Handling

As you might have noticed, Task Definitions also have the possibility to use input parameters.
The Lifecycle Toolkit passes the values defined inside the `map` field as a JSON object.
At the moment, multi-level maps are not supported.
The JSON object can be read through the environment variable `DATA` using `Deno.env.get("DATA");`.
K8s secrets can also be passed to the function using the `secureParameters` field.
Here, the `secret` value is the K8s secret name that will be mounted into the runtime and made available to the function via the environment variable `SECURE_DATA`.
Currently only one secret can be passed. The secret must have a `key` called `SECURE_DATA`.
It can be accessed via the environment variable `Deno.env.get("SECURE_DATA")`.

For example:

```yaml
# kubectl create secret generic my-secret --from-literal=SECURE_DATA=foo
apiVersion: lifecycle.keptn.sh/v1alpha1
kind: KeptnTaskDefinition
metadata:
name: dummy-task
namespace: "default"
spec:
function:
secureParameters:
secret: my-secret
inline:
code: |
let secret_text = Deno.env.get("SECURE_DATA");
// secret_text = "foo"
```

This methodology supports multiple variables by creating a K8s secret with a JSON string:

```yaml
# kubectl create secret generic my-secret \
# --from-literal=SECURE_DATA="{\"foo\": \"bar\", \"foo2\": \"bar2\"}"
apiVersion: lifecycle.keptn.sh/v1alpha1
kind: KeptnTaskDefinition
metadata:
name: dummy-task
namespace: "default"
spec:
function:
secureParameters:
secret: my-secret
inline:
code: |
let secret_text = Deno.env.get("SECURE_DATA");
let secret_text_obj = JSON.parse(secret_text);
// secret_text_obj["foo"] = "bar"
// secret_text_obj["foo2"] = "bar2"
```

### Keptn Task

Expand Down

0 comments on commit 29b00cb

Please sign in to comment.