-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: First Version of Function Execution (#35)
Signed-off-by: Thomas Schuetz <[email protected]> Signed-off-by: Thomas Schuetz <[email protected]> Co-authored-by: Giovanni Liva <[email protected]>
- Loading branch information
Showing
47 changed files
with
1,783 additions
and
4 deletions.
There are no files selected for viewing
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,25 @@ | ||
# Hello, Keptn! | ||
|
||
## Goal | ||
This example shows how to define an inline function and pass over parameters to its execution. | ||
|
||
## Variants | ||
* `inline` - shows how to specify a function directly in the `KeptnTaskDefinition` | ||
* `http` - fetches the Script from the Web | ||
* `upstream` - shows how functions could be reused | ||
|
||
## Usage | ||
|
||
* Edit task.yaml and add your name to `spec.parameters.map.name` | ||
* Navigate to the corresponding folder | ||
* Apply the manifests: `kubectl apply -f .` | ||
|
||
## Outcome | ||
|
||
* A KeptnTaskDefinition `hello-keptn-<variant>` should be created | ||
* A KeptnTask `hello-developer` should be created | ||
* You can track the state of the job with `kubectl get KeptnTask hello-developer` | ||
``` | ||
NAME APPLICATION WORKLOAD VERSION JOB NAME STATUS | ||
hello-developer my-app my-workload 1.0 klc-my-app-my-workload-1.0-57692 Succeeded | ||
``` |
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,7 @@ | ||
let text = Deno.env.get("DATA"); | ||
let data; | ||
let name; | ||
data = JSON.parse(text); | ||
|
||
name = data.name | ||
console.log("Hello, " + name); |
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,12 @@ | ||
apiVersion: lifecycle.keptn.sh/v1alpha1 | ||
kind: KeptnTask | ||
metadata: | ||
name: hello-developer-http | ||
spec: | ||
taskDefinition: hello-keptn-http | ||
workload: my-workload | ||
workloadVersion: "1.0" | ||
application: my-app | ||
parameters: | ||
map: | ||
name: "Keptn-Developer" |
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,10 @@ | ||
apiVersion: lifecycle.keptn.sh/v1alpha1 | ||
kind: KeptnTaskDefinition | ||
metadata: | ||
name: hello-keptn-http | ||
spec: | ||
function: | ||
httpRef: | ||
url: https://raw.githubusercontent.com/keptn-sandbox/lifecycle-controller/main/examples/taskonly-hello-keptn/http/hello-keptn.ts | ||
|
||
|
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,12 @@ | ||
apiVersion: lifecycle.keptn.sh/v1alpha1 | ||
kind: KeptnTask | ||
metadata: | ||
name: hello-developer-inline | ||
spec: | ||
taskDefinition: hello-keptn-inline | ||
workload: my-workload | ||
workloadVersion: "1.0" | ||
application: my-app | ||
parameters: | ||
map: | ||
name: "Keptn Developer 1" |
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,16 @@ | ||
apiVersion: lifecycle.keptn.sh/v1alpha1 | ||
kind: KeptnTaskDefinition | ||
metadata: | ||
name: hello-keptn-inline | ||
spec: | ||
function: | ||
inlineRef: | ||
code: | | ||
let text = Deno.env.get("DATA"); | ||
let data; | ||
let name; | ||
data = JSON.parse(text); | ||
name = data.name | ||
console.log("Hello, " + name + " new"); | ||
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,7 @@ | ||
let text = Deno.env.get("DATA"); | ||
let data; | ||
let name; | ||
data = JSON.parse(text); | ||
|
||
name = data.name | ||
console.log("Hello, " + name); |
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,9 @@ | ||
apiVersion: lifecycle.keptn.sh/v1alpha1 | ||
kind: KeptnTask | ||
metadata: | ||
name: hello-developer-upstream | ||
spec: | ||
taskDefinition: hello-keptn-upstream | ||
workload: my-workload | ||
workloadVersion: "1.0" | ||
application: my-app |
13 changes: 13 additions & 0 deletions
13
examples/taskonly-hello-keptn/upstream/taskdefinition.yaml
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,13 @@ | ||
apiVersion: lifecycle.keptn.sh/v1alpha1 | ||
kind: KeptnTaskDefinition | ||
metadata: | ||
name: hello-keptn-upstream | ||
spec: | ||
function: | ||
functionRef: | ||
name: hello-keptn-upstream-parent | ||
parameters: | ||
map: | ||
name: "Developer" | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
examples/taskonly-hello-keptn/upstream/taskdefinition_upstream.yaml
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,12 @@ | ||
apiVersion: lifecycle.keptn.sh/v1alpha1 | ||
kind: KeptnTaskDefinition | ||
metadata: | ||
name: hello-keptn-upstream-parent | ||
spec: | ||
function: | ||
httpRef: | ||
url: https://raw.githubusercontent.com/keptn-sandbox/lifecycle-controller/main/examples/taskonly-hello-keptn/http/hello-keptn.ts | ||
parameters: | ||
map: | ||
name: "Parent Developer" | ||
|
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,93 @@ | ||
/* | ||
Copyright 2022. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! | ||
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. | ||
|
||
// KeptnTaskSpec defines the desired state of KeptnTask | ||
type KeptnTaskSpec struct { | ||
Workload string `json:"workload"` | ||
WorkloadVersion string `json:"workloadVersion"` | ||
Application string `json:"application"` | ||
TaskDefinition string `json:"taskDefinition"` | ||
Parameters TaskParameters `json:"parameters,omitempty"` | ||
SecureParameters SecureParameters `json:"secureParameters,omitempty"` | ||
} | ||
|
||
type KeptnTaskPhase string | ||
|
||
const ( | ||
// TaskPending means the task has been accepted by the system, but the corresponding Job did not start | ||
TaskPending KeptnTaskPhase = "Pending" | ||
// TaskRunning means that the Job has been started. | ||
TaskRunning KeptnTaskPhase = "Running" | ||
// TaskFailed means that the Job failed | ||
TaskFailed KeptnTaskPhase = "Failed" | ||
// TaskSucceeded means that the Job has finished successfully | ||
TaskSucceeded KeptnTaskPhase = "Succeeded" | ||
) | ||
|
||
type TaskParameters struct { | ||
Inline map[string]string `json:"map,omitempty"` | ||
} | ||
|
||
type SecureParameters struct { | ||
Secret string `json:"secret,omitempty"` | ||
} | ||
|
||
// KeptnTaskStatus defines the observed state of KeptnTask | ||
type KeptnTaskStatus struct { | ||
JobName string `json:"jobName,omitempty"` | ||
Status KeptnTaskPhase `json:"status,omitempty"` | ||
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
// +kubebuilder:printcolumn:name="Application",type=string,JSONPath=`.spec.application` | ||
// +kubebuilder:printcolumn:name="Workload",type=string,JSONPath=`.spec.workload` | ||
// +kubebuilder:printcolumn:name="Version",type=string,JSONPath=`.spec.workloadVersion` | ||
// +kubebuilder:printcolumn:name="Job Name",type=string,JSONPath=`.status.jobName` | ||
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.status` | ||
|
||
// KeptnTask is the Schema for the keptntasks API | ||
type KeptnTask struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec KeptnTaskSpec `json:"spec,omitempty"` | ||
Status KeptnTaskStatus `json:"status,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// KeptnTaskList contains a list of KeptnTask | ||
type KeptnTaskList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []KeptnTask `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&KeptnTask{}, &KeptnTaskList{}) | ||
} |
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,95 @@ | ||
/* | ||
Copyright 2022. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! | ||
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. | ||
|
||
// KeptnTaskDefinitionSpec defines the desired state of KeptnTaskDefinition | ||
type KeptnTaskDefinitionSpec struct { | ||
Function FunctionSpec `json:"function,omitempty"` | ||
} | ||
|
||
type FunctionSpec struct { | ||
FunctionReference *FunctionReference `json:"functionRef,omitempty"` | ||
Inline *Inline `json:"inline,omitempty"` | ||
HttpReference *HttpReference `json:"httpRef,omitempty"` | ||
ConfigMapReference *ConfigMapReference `json:"configMapRef,omitempty"` | ||
Parameters TaskParameters `json:"parameters,omitempty"` | ||
SecureParameters SecureParameters `json:"secureParameters,omitempty"` | ||
} | ||
|
||
type ConfigMapReference struct { | ||
Name string `json:"name,omitempty"` | ||
} | ||
|
||
type FunctionReference struct { | ||
Name string `json:"name,omitempty"` | ||
} | ||
|
||
type Inline struct { | ||
Code string `json:"code,omitempty"` | ||
} | ||
|
||
type HttpReference struct { | ||
Url string `json:"url,omitempty"` | ||
} | ||
|
||
type ContainerSpec struct { | ||
} | ||
|
||
// KeptnTaskDefinitionStatus defines the observed state of KeptnTaskDefinition | ||
type KeptnTaskDefinitionStatus struct { | ||
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
Function FunctionStatus `json:"function,omitempty"` | ||
} | ||
|
||
type FunctionStatus struct { | ||
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
ConfigMap string `json:"configMap,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
|
||
// KeptnTaskDefinition is the Schema for the keptntaskdefinitions API | ||
type KeptnTaskDefinition struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec KeptnTaskDefinitionSpec `json:"spec,omitempty"` | ||
Status KeptnTaskDefinitionStatus `json:"status,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// KeptnTaskDefinitionList contains a list of KeptnTaskDefinition | ||
type KeptnTaskDefinitionList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []KeptnTaskDefinition `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&KeptnTaskDefinition{}, &KeptnTaskDefinitionList{}) | ||
} |
Oops, something went wrong.