Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: reference page for KeptnTaskDefinition #1083

Closed
wants to merge 77 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
e089a5d
k8s doc references on landing page
StackScribe Mar 2, 2023
3246ac6
process go.mod file
StackScribe Mar 2, 2023
4c4ef1d
Merge branch 'main' of github.com:keptn/lifecycle-toolkit
StackScribe Mar 8, 2023
84bc148
Merge branch 'main' of github.com:keptn/lifecycle-toolkit
StackScribe Mar 9, 2023
9937c95
Merge branch 'main' of github.com:keptn/lifecycle-toolkit
StackScribe Mar 17, 2023
3350da4
Merge branch 'main' of github.com:keptn/lifecycle-toolkit
StackScribe Mar 21, 2023
35b6026
docs: KeptnTaskDefinition yaml CRD ref page
StackScribe Mar 22, 2023
d7ee06f
fix broken xref to API Ref
StackScribe Mar 22, 2023
7558599
fix some markdown-linter errors
StackScribe Mar 22, 2023
3623ee1
markdownlint auto fixes
StackScribe Mar 23, 2023
74d49ed
Merge branch 'main' of github.com:keptn/lifecycle-toolkit
StackScribe Mar 23, 2023
b97cc28
Merge branch 'main' of github.com:keptn/lifecycle-toolkit
StackScribe Mar 24, 2023
9f93537
Pull in all info from old write-tasks
StackScribe Mar 27, 2023
8894aca
force rebuild
StackScribe Mar 27, 2023
71b5eea
update
StackScribe Mar 27, 2023
f2e4b50
Mo comments
StackScribe Mar 27, 2023
4ba83f5
Mo comments -- description
StackScribe Mar 27, 2023
d3e58ce
Mo CRD -> Resource
StackScribe Mar 27, 2023
45be10d
Mo format for code
StackScribe Mar 27, 2023
94d01e2
Mo -- show full URL
StackScribe Mar 27, 2023
7f2a183
Mo - KeptnTaskDefinition (singular)
StackScribe Mar 27, 2023
9c3ff2e
Mo - fix code formatting
StackScribe Mar 27, 2023
bcceba7
Mo fix code formatting
StackScribe Mar 27, 2023
cc81eda
Mo use latest API version
StackScribe Mar 27, 2023
ae06ae0
Mo -- latest API version
StackScribe Mar 27, 2023
3b108db
full-fletched -> full-fledged
StackScribe Mar 27, 2023
5203666
Use v1alpha3
StackScribe Mar 27, 2023
48b2e44
v1alpha3
StackScribe Mar 27, 2023
83171e7
remove extraneous .
StackScribe Mar 27, 2023
fbdfa72
v1alpha3
StackScribe Mar 27, 2023
47ad95b
YAML files that create...
StackScribe Mar 27, 2023
f79b16a
Mo rewording of CRD explanation
StackScribe Mar 27, 2023
c09b380
remove promise of alternatives to Deno scripts
StackScribe Mar 27, 2023
beb7d5b
Merge branch '0321-task-ref' of github.com:StackScribe/lifecycle-tool…
StackScribe Mar 27, 2023
570dc7a
add link to config/samples directory
StackScribe Mar 28, 2023
0333070
library -> API
StackScribe Mar 28, 2023
507c89f
library -> version of lifecycle API group
StackScribe Mar 28, 2023
60d67f9
removed link to examples directory until we sort that out
StackScribe Mar 29, 2023
8ee834d
Merge branch '0321-task-ref' of github.com:StackScribe/lifecycle-tool…
StackScribe Mar 29, 2023
5f77bf6
crd-ref -> api-ref for autogenerated ref pages
StackScribe Mar 29, 2023
ee060e2
modify scripts to generate API docs
StackScribe Mar 29, 2023
3ee14f6
tried to fix autogenerate script
StackScribe Mar 29, 2023
91dac8e
Merge branch 'main' of github.com:keptn/lifecycle-toolkit
StackScribe Mar 30, 2023
761d3da
docs: KeptnTaskDefinition yaml CRD ref page
StackScribe Mar 22, 2023
9c57488
fix broken xref to API Ref
StackScribe Mar 22, 2023
0d1316c
fix some markdown-linter errors
StackScribe Mar 22, 2023
8d25ac7
markdownlint auto fixes
StackScribe Mar 23, 2023
b62c1d0
Pull in all info from old write-tasks
StackScribe Mar 27, 2023
b58f8e3
force rebuild
StackScribe Mar 27, 2023
0b61c87
update
StackScribe Mar 27, 2023
990b6a4
remove promise of alternatives to Deno scripts
StackScribe Mar 27, 2023
d0c450b
Mo comments
StackScribe Mar 27, 2023
cdce62a
Mo comments -- description
StackScribe Mar 27, 2023
3b496ab
Mo CRD -> Resource
StackScribe Mar 27, 2023
71e6300
Mo format for code
StackScribe Mar 27, 2023
1619de9
Mo -- show full URL
StackScribe Mar 27, 2023
6f6cc7c
Mo - KeptnTaskDefinition (singular)
StackScribe Mar 27, 2023
9cbcdc1
Mo - fix code formatting
StackScribe Mar 27, 2023
bb50730
Mo fix code formatting
StackScribe Mar 27, 2023
203d14e
Mo use latest API version
StackScribe Mar 27, 2023
08e831b
Mo -- latest API version
StackScribe Mar 27, 2023
3143757
full-fletched -> full-fledged
StackScribe Mar 27, 2023
f74171e
Use v1alpha3
StackScribe Mar 27, 2023
0f0e86d
v1alpha3
StackScribe Mar 27, 2023
ef27b42
remove extraneous .
StackScribe Mar 27, 2023
5c3828d
v1alpha3
StackScribe Mar 27, 2023
716ed9a
YAML files that create...
StackScribe Mar 27, 2023
906c9a4
Mo rewording of CRD explanation
StackScribe Mar 27, 2023
6f6e542
add link to config/samples directory
StackScribe Mar 28, 2023
1ef6bcb
removed link to examples directory until we sort that out
StackScribe Mar 29, 2023
9074553
library -> API
StackScribe Mar 30, 2023
95475a7
library -> version of lifecycle API group
StackScribe Mar 28, 2023
f60b150
crd-ref -> api-ref for autogenerated ref pages
StackScribe Mar 30, 2023
a993edb
modify scripts to generate API docs
StackScribe Mar 29, 2023
b5c75ad
tried to fix autogenerate script
StackScribe Mar 30, 2023
5b91097
no colon after inline
StackScribe Mar 30, 2023
c8d1daf
Merge branch '0321-task-ref' of github.com:StackScribe/lifecycle-tool…
StackScribe Mar 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/content/en/docs/api-ref/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: API Reference
description: Reference information about the KLT CRDs
weight: 100
hidechildren: false # this flag hides all sub-pages in the sidebar-multicard.html
---

This section provides comprehensive reference information about the
[Custom Resource Definitions (CRDs)](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/)
that are defined for the Keptn Lifecycle Toolkit.

> **Note**
This section is under development.
Information that is published here has been reviewed for technical accuracy
but the format and content is still evolving.
We welcome your input!**

Each CRD is an object of an API library.
Keptn APIs follow the Kubernetes API versioning scheme.
and are themselves composed of objects and sub-objects.
By introducing CRDs, Keptn is extending the base Kubernetes API with new objects and functionality.
Keptn APIs follow API versioning conventions recommended by Kubernetes.
StackScribe marked this conversation as resolved.
Show resolved Hide resolved

For more information, see the Kubernetes documentation:

* [API Overview](https://kubernetes.io/docs/reference/using-api/)
* [Custom Resources](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/)
* [API versioning](https://kubernetes.io/docs/reference/using-api/#api-versioning)
* [Understanding Kubernetes Objects](https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/)
4 changes: 4 additions & 0 deletions docs/content/en/docs/api-ref/lifecycle/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Lifecycle API
description: Reference information about the Lifecycle API
StackScribe marked this conversation as resolved.
Show resolved Hide resolved
---
279 changes: 279 additions & 0 deletions docs/content/en/docs/crd-ref/TaskDefinition/index.md
mowies marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
---
title: KeptnTaskDefinition
description: Define tasks that can be run pre- or post-deployment
weight: 89
---

A `KeptnTaskDefinition` defines tasks
that are run by the Keptn Lifecycle Toolkit
as part of the pre- and post-deployment phases of a `KeptnApp`.

## Yaml Synopsis

```yaml
apiVersion: <lifecycle.keptn.sh/v?alpha?>
kind: KeptnTaskDefinition
metadata:
name: <task-name>
spec:
function:
inline: | httpRef | functionRef
StackScribe marked this conversation as resolved.
Show resolved Hide resolved
[parameters:
map:
textMessage: "This is my configuration"]
[secureParameters:
secret: slack-token]
```
mowies marked this conversation as resolved.
Show resolved Hide resolved

## Fields

* **apiVersion** -- API version being used.
`
* **kind** -- CRD type. Must be set to `KeptnTaskDefinition`
StackScribe marked this conversation as resolved.
Show resolved Hide resolved

* **name** -- Unique name of this task.
* Must be an alphanumeric string and, by convention, is all lowercase.
* Can include the special characters `_`, `-`, <what others>.
* Should not include spaces.

* **function** -- Code to be executed,
expressed as a [Deno](https://deno.land/) script.
Refer to [function runtime](https://github.com/keptn/lifecycle-toolkit/tree/main/functions-runtime)
for more information about the runtime.
In the future, we intend to support additional runtimes,
especially running a container image directly.
StackScribe marked this conversation as resolved.
Show resolved Hide resolved

The `function` can be defined as one of the following:

* **inline** - Include the actual executable code to execute.
This can be written as a full-fledged Deno script
that is included in this file.
For example:

```function:
inline:
code: |
console.log("Deployment Task has been executed");
```
StackScribe marked this conversation as resolved.
Show resolved Hide resolved

* **httpRef** - Specify a Deno script to be executed at runtime
from the remote webserver that is specified.
For example:

```yaml
name: hello-keptn-http
spec:
function:
httpRef:
url: <url>
StackScribe marked this conversation as resolved.
Show resolved Hide resolved
```

* **functionRef** -- Execute another `KeptnTaskDefinition` that has been defined.
Populate this field with the value of the `name` field
for the `KeptnTaskDefinition` to be called.
This is commonly used to call a general function
that is used in multiple places, possibly with different parameters.
An example is:

```yaml
spec:
function:
functionRef:
name: slack-notification
```

This can also be used to group a set of tasks
into a single `KeptnTaskDefinitions`,
StackScribe marked this conversation as resolved.
Show resolved Hide resolved
such as defining a `KeptnTaskDefinition` for testing.
In this case, it other, existing `KeptnTaskDefinition`s
for each type of test to be run,
specifying each by the value of the `name` field.
Comment on lines +87 to +89
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence doesn't really make sense...


* **parameters** - An optional field to supply input parameters to a function.
The Lifecycle Toolkit passes the values defined inside the `map` field
as a JSON object.
For example:

```spec:
parameters:
map:
textMessage: "This is my configuration"
```
StackScribe marked this conversation as resolved.
Show resolved Hide resolved

The JSON object can be read
through the `DATA` environment variable using `Deno.env.get("DATA");`.

Multi-level maps are not supported at this time.

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")`.
See [Context](#context) for details.
Comment on lines +107 to +110
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be moved into the secure parameters section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaving it where it is for now but think we may want to move this into a guide chapter rather than having it on the reference page.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I mean this doesn't belong to the parameters section in the YAML but to the secureParameters, so this paragraph should also be under the secure parameters headline.


* **secureParameters** -- An optional field used to pass a Kubernetes secret.
The `secret` value is the Kubernetes secret name
that is mounted into the runtime and made available to functions
using the `SECURE_DATA` environment variable.
For example:

```yaml
secureParameters:
secret: slack-token
```
StackScribe marked this conversation as resolved.
Show resolved Hide resolved

See [Create secret text](#create-secret-text) for details.

## Usage

A Task is responsible for executing the TaskDefinition of a workload.
The execution is done by spawning a Kubernetes Job to handle a single Task.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add an x-ref here to the relevant k8s docs page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in new PR

In its state, it tracks the current status of this Kubernetes Job.

### Context

A context environment variable is available via `Deno.env.get("CONTEXT")`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the content of the context variable is defined by us, we should also include that in the reference above.
Especially, what data the user actually has available in the 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;
}
```

### Create secret text

```yaml
# kubectl create secret generic my-secret --from-literal=SECURE_DATA=foo

apiVersion: lifecycle.keptn.sh/v1alpha1
StackScribe marked this conversation as resolved.
Show resolved Hide resolved
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 Kubernetes 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
StackScribe marked this conversation as resolved.
Show resolved Hide resolved
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"
```

## Examples

**Example 1** defines a full-fletched Deno script
StackScribe marked this conversation as resolved.
Show resolved Hide resolved
within the `KeptnTaskDefinition` YAML file:

```yaml
apiVersion: lifecycle.keptn.sh/v1alpha2
StackScribe marked this conversation as resolved.
Show resolved Hide resolved
kind: KeptnTaskDefinition
metadata:
name: hello-keptn-inline
spec:
function:
inline:
code: |
let text = Deno.env.get("DATA");
let data;
let name;
data = JSON.parse(text);

name = data.name
console.log("Hello, " + name + " new");
```

**Example 2** fetches the Deno script from a remote webserver at runtime:

```yaml
apiVersion: lifecycle.keptn.sh/v1alpha2
StackScribe marked this conversation as resolved.
Show resolved Hide resolved
kind: KeptnTaskDefinition
metadata:
name: hello-keptn-http
spec:
function:
httpRef:
url: <url>
```

See the
[sample-app/version-1](https://github.com/keptn-sandbox/lifecycle-toolkit-examples/blob/main/sample-app/version-1/app-pre-deploy.yaml).
StackScribe marked this conversation as resolved.
Show resolved Hide resolved
PodtatoHead example for a more complete example.

**Example 3** calls another defined task,
illustrating how one `KeptnTaskDefinition` can build
on top of other `KeptnTaskDefinition`s.
In this case, it calls `slack-notification-dev`,
passing `parameters` and `secureParameters` to that other task:

```yaml
apiVersion: lifecycle.keptn.sh/v1alpha2
StackScribe marked this conversation as resolved.
Show resolved Hide resolved
kind: KeptnTaskDefinition
metadata:
name: slack-notification-dev
spec:
function:
functionRef:
name: slack-notification
parameters:
map:
textMessage: "This is my configuration"
secureParameters:
secret: slack-token
```

## Files

API Reference:

* [KeptnTaskDefinition](../../api-ref/lifecycle/v1alpha3/#keptntaskdefinition)
* [KeptnTaskDefinitionList](../../api-ref/lifecycle/v1alpha3/#keptntaskdefinitionlist)
* [KeptnTaskDefinitionSpec](../../api-ref/lifecycle/v1alpha3/#keptntaskdefinitionspec)
* [FunctionReference](../../api-ref/lifecycle/v1alpha3/#functionreference)
* [FunctionSpec](../../api-ref/lifecycle/v1alpha3/#functionspec)
* [FunctionStatus](../../api-ref/lifecycle/v1alpha3/#functionstatus)
* [HttpReference](../../api-ref/lifecycle/v1alpha3/#httpreference)
* [Inline](../../api-ref/lifecycle/v1alpha3/#inline)

## Differences between versions

The `KeptnTaskDefinition` is the same for
all `v1alpha?` library versions.

## See also

* Link to "use-case" guide pages that do something interesting with this CRD
* Link to reference pages for any related CRDs
8 changes: 5 additions & 3 deletions docs/content/en/docs/crd-ref/_index.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
title: API Reference
title: CRD Reference
description: Reference information about the KLT CRDs
weight: 100
weight: 200
hidechildren: false # this flag hides all sub-pages in the sidebar-multicard.html
---

This section provides comprehensive reference information about the
YAML files that create the
StackScribe marked this conversation as resolved.
Show resolved Hide resolved
[Custom Resource Definitions (CRDs)](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/)
that are defined for the Keptn Lifecycle Toolkit.

Expand All @@ -15,7 +16,8 @@ Information that is published here has been reviewed for technical accuracy
but the format and content is still evolving.
We welcome your input!**

Each CRD is an object of an API library.
Each CRD is an object of an
[API library](../../docs/api-ref/)
Keptn APIs follow the Kubernetes API versioning scheme.
and are themselves composed of objects and sub-objects.
By introducing CRDs, Keptn is extending the base Kubernetes API with new objects and functionality.
StackScribe marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
33 changes: 33 additions & 0 deletions docs/content/en/docs/crd-ref/crd-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: <crd-template>
description: <one-line description of CRD>
weight: <assign weight to create alphabetical order>
hidden: true
---

Copy this template to create a new CRD reference page.

1. Replace the variable text in metadata with information for this page
1. Delete the `hidden: true` line
1. Delete these instructions from your file
1. Populate the page with appropriate content

## Synopsis

## Fields

<!-- Detailed description of each field-->

## Usage

<!-- How this CRD is "activated". For example, which event uses this CRD -->
<!-- Instructions and guidelines for when and how to customize a CRD -->

## Examples

## Files

## Differences between versions

## See also

Loading