/
runtask.go
108 lines (87 loc) · 3.46 KB
/
runtask.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
/*
Copyright 2018 The OpenEBS Authors
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 v1beta1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +resource:path=runtask
// RunTask forms the desired run specification as well as the result of
// trying the same
type RunTask struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec RunTaskSpec `json:"spec"`
Status RunTaskStatus `json:"status"`
}
// RunTaskSpec is the specifications of a RunTask resource. It composes of a
// config as well as a list of run items. It specifies the desired actions
// against one or more kubernetes resources.
type RunTaskSpec struct {
Config map[string]string `json:"config"`
Runs []RunItem `json:"runs"`
}
// RunTaskStatus presents the state of runtask after execution of desired
// actions
type RunTaskStatus struct {
Phase string `json:"phase"`
}
// RunItem composes of properties that form a single run execution
type RunItem struct {
ID string `json:"id"` // identity of this run
Name string `json:"name,omitempty"` // description of this run
Action Action `json:"action"` // command that this run will invoke
APIVersion string `json:"apiVersion,omitempty"` // resource version
Kind Kind `json:"kind"` // refers to resource against which action gets executed
Options []Option `json:"options"` // options while executing the action
Conditions []Condition `json:"conditions,omitempty"` // conditions to satisfy before executing
ConditionOp ConditionOperator `json:"conditionOp,omitempty"` // operator applied against the list of conditions
}
// Option represents a logic and corresponding condition(s) to execute the
// action
type Option struct {
Func string `json:"func"`
Conditions []Condition `json:"conditions,omitempty"`
ConditionOp ConditionOperator `json:"conditionOp,omitempty"`
}
// Action defines the supported commands to be executed against a supported
// resource
type Action string
const (
Get Action = "get"
Template Action = "template"
List Action = "list"
Create Action = "create"
Update Action = "update"
Patch Action = "patch"
)
// Kind defines the supported resource types
type Kind string
const (
// DaemonSet is a supported resource
DaemonSet Kind = "daemonset"
)
// Condition defines a condition in string format
type Condition string
// ConditionOperator defines the logical operator to be used against one or
// more conditions
type ConditionOperator string
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +resource:path=runtasks
// RunTaskList is a list of RunTask resources
type RunTaskList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []RunTask `json:"items"`
}