-
Notifications
You must be signed in to change notification settings - Fork 109
/
keptntaskdefinition_types.go
176 lines (155 loc) · 6.66 KB
/
keptntaskdefinition_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
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 v1alpha3
import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// KeptnTaskDefinitionSpec defines the desired state of KeptnTaskDefinition
type KeptnTaskDefinitionSpec struct {
// Deprecated
// Function contains the definition for the function that is to be executed in KeptnTasks.
// +optional
Function *RuntimeSpec `json:"function,omitempty"`
// Python contains the definition for the python function that is to be executed in KeptnTasks.
// +optional
Python *RuntimeSpec `json:"python,omitempty"`
// Deno contains the definition for the Deno function that is to be executed in KeptnTasks.
// +optional
Deno *RuntimeSpec `json:"deno,omitempty"`
// Container contains the definition for the container that is to be used in Job.
// +optional
Container *ContainerSpec `json:"container,omitempty"`
// Retries specifies how many times a job executing the KeptnTaskDefinition should be restarted in the case
// of an unsuccessful attempt.
// +kubebuilder:default:=10
// +optional
Retries *int32 `json:"retries,omitempty"`
// Timeout specifies the maximum time to wait for the task to be completed successfully.
// If the task does not complete successfully within this time frame, it will be
// considered to be failed.
// +kubebuilder:default:="5m"
// +kubebuilder:validation:Pattern="^0|([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
// +kubebuilder:validation:Type:=string
// +optional
Timeout metav1.Duration `json:"timeout,omitempty"`
// ServiceAccount specifies the service account to be used in jobs to authenticate with the Kubernetes API and access cluster resources.
// +optional
ServiceAccount *ServiceAccountSpec `json:"serviceAccount,omitempty"`
// AutomountServiceAccountToken allows to enable K8s to assign cluster API credentials to a pod, if set to false
// the pod will decline the service account
// +optional
AutomountServiceAccountToken *AutomountServiceAccountTokenSpec `json:"automountServiceAccountToken,omitempty"`
// TTLSecondsAfterFinished controller makes a job eligible to be cleaned up after it is finished.
// The timer starts when the status shows up to be Complete or Failed.
// +kubebuilder:default:=300
// +optional
TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished,omitempty"`
// ImagePullSecrets is an optional field to specify the names of secrets to use for pulling container images
// +optional
ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
}
type RuntimeSpec struct {
// FunctionReference allows to reference another KeptnTaskDefinition which contains the source code of the
// function to be executes for KeptnTasks based on this KeptnTaskDefinition. This can be useful when you have
// multiple KeptnTaskDefinitions that should execute the same logic, but each with different parameters.
// +optional
FunctionReference FunctionReference `json:"functionRef,omitempty"`
// Inline allows to specify the code that should be executed directly in the KeptnTaskDefinition, as a multi-line
// string.
// +optional
Inline Inline `json:"inline,omitempty"`
// HttpReference allows to point to an HTTP URL containing the code of the function.
// +optional
HttpReference HttpReference `json:"httpRef,omitempty"`
// ConfigMapReference allows to reference a ConfigMap containing the code of the function.
// When referencing a ConfigMap, the code of the function must be available as a value of the 'code' key
// of the referenced ConfigMap.
// +optional
ConfigMapReference ConfigMapReference `json:"configMapRef,omitempty"`
// Parameters contains parameters that will be passed to the job that executes the task as env variables.
// +optional
Parameters TaskParameters `json:"parameters,omitempty"`
// SecureParameters contains secure parameters that will be passed to the job that executes the task.
// These will be stored and accessed as secrets in the cluster.
// +optional
SecureParameters SecureParameters `json:"secureParameters,omitempty"`
// CmdParameters contains parameters that will be passed to the command
// +optional
CmdParameters string `json:"cmdParameters,omitempty"`
}
type ConfigMapReference struct {
// Name is the name of the referenced ConfigMap.
// +optional
Name string `json:"name,omitempty"`
}
type FunctionReference struct {
// Name is the name of the referenced KeptnTaskDefinition.
// +optional
Name string `json:"name,omitempty"`
}
type Inline struct {
// Code contains the code of the function.
// +optional
Code string `json:"code,omitempty"`
}
type HttpReference struct {
// Url is the URL containing the code of the function.
// +optional
Url string `json:"url,omitempty"`
}
type ContainerSpec struct {
*v1.Container `json:",inline"`
}
type AutomountServiceAccountTokenSpec struct {
Type *bool `json:"type"`
}
type ServiceAccountSpec struct {
Name string `json:"name"`
}
// KeptnTaskDefinitionStatus defines the observed state of KeptnTaskDefinition
type KeptnTaskDefinitionStatus struct {
// Function contains status information of the function definition for the task.
// +optional
Function FunctionStatus `json:"function,omitempty"`
}
type FunctionStatus struct {
// ConfigMap indicates the ConfigMap in which the function code is stored.
// +optional
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"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// Spec describes the desired state of the KeptnTaskDefinition.
// +optional
Spec KeptnTaskDefinitionSpec `json:"spec,omitempty"`
// Status describes the current state of the KeptnTaskDefinition.
// +optional
Status KeptnTaskDefinitionStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// KeptnTaskDefinitionList contains a list of KeptnTaskDefinition
type KeptnTaskDefinitionList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []KeptnTaskDefinition `json:"items"`
}
func init() {
SchemeBuilder.Register(&KeptnTaskDefinition{}, &KeptnTaskDefinitionList{})
}