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

feat: First Version of Function Execution #35

Merged
merged 17 commits into from
Sep 26, 2022
Merged
25 changes: 25 additions & 0 deletions examples/taskonly-hello-keptn/README.md
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
thschue marked this conversation as resolved.
Show resolved Hide resolved

* Edit task.yaml and add your name to `spec.parameters.map.name`
* Navigate to the corresponding folder
* Apply the manifests: `kubectl apply -f .`

## Outcome
thschue marked this conversation as resolved.
Show resolved Hide resolved

* 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
```
7 changes: 7 additions & 0 deletions examples/taskonly-hello-keptn/http/hello-keptn.ts
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);
12 changes: 12 additions & 0 deletions examples/taskonly-hello-keptn/http/task.yaml
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"
10 changes: 10 additions & 0 deletions examples/taskonly-hello-keptn/http/taskdefinition.yaml
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


12 changes: 12 additions & 0 deletions examples/taskonly-hello-keptn/inline/task.yaml
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"
16 changes: 16 additions & 0 deletions examples/taskonly-hello-keptn/inline/taskdefinition.yaml
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");

7 changes: 7 additions & 0 deletions examples/taskonly-hello-keptn/upstream/hello-keptn.ts
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);
9 changes: 9 additions & 0 deletions examples/taskonly-hello-keptn/upstream/task.yaml
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 examples/taskonly-hello-keptn/upstream/taskdefinition.yaml
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"


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"

18 changes: 18 additions & 0 deletions operator/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,22 @@ resources:
kind: ServiceRun
path: github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: keptn.sh
group: lifecycle
kind: KeptnTaskDefinition
path: github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: keptn.sh
group: lifecycle
kind: KeptnTask
path: github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1
version: v1alpha1
version: "3"
93 changes: 93 additions & 0 deletions operator/api/v1alpha1/keptntask_types.go
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"`
bacherfl marked this conversation as resolved.
Show resolved Hide resolved
}

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{})
}
95 changes: 95 additions & 0 deletions operator/api/v1alpha1/keptntaskdefinition_types.go
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{})
}