forked from stolostron/multicloud-operators-foundation
/
action_types.go
116 lines (94 loc) · 3.38 KB
/
action_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
package v1beta1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// ManagedClusterAction is the action that will be done on a cluster
type ManagedClusterAction struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// Spec defines the desired behavior of the action.
// +optional
Spec ActionSpec `json:"spec,omitempty"`
// Status describes the desired status of the action
// +optional
Status ActionStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// ManagedClusterActionList is a list of all the ManagedClusterActions
type ManagedClusterActionList struct {
metav1.TypeMeta `json:",inline"`
// Standard list metadata.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
// List of ManagedClusterAction objects.
Items []ManagedClusterAction `json:"items"`
}
// ActionSpec defines the action to be processed on a cluster
type ActionSpec struct {
// ActionType is the type of the action
ActionType ActionType `json:"actionType,omitempty"`
// KubeWorkSpec is the action payload to process
KubeWork *KubeWorkSpec `json:"kube,omitempty"`
}
// ActionStatus returns the current status of the action
type ActionStatus struct {
// Conditions represents the conditions of this resource on managed cluster
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`
// Result references the related result of the action
// +nullable
// +optional
// +kubebuilder:validation:EmbeddedResource
// +kubebuilder:pruning:PreserveUnknownFields
Result runtime.RawExtension `json:"result,omitempty"`
}
// ActionType defines the type of the action
type ActionType string
const (
// CreateActionType defines create action
CreateActionType ActionType = "Create"
// DeleteActionType defines selete action
DeleteActionType ActionType = "Delete"
// UpdateActionType defines update action
UpdateActionType ActionType = "Update"
)
// These are valid conditions of a cluster.
const (
// ConditionActionCompleted means the work is completed.
ConditionActionCompleted string = "Completed"
)
const (
ReasonCreateResourceFailed string = "CreateResourceFailed"
ReasonUpdateResourceFailed string = "UpdateResourceFailed"
ReasonDeleteResourceFailed string = "DeleteResourceFailed"
ReasonActionTypeInvalid string = "ActionTypeInvalid"
)
// KubeWorkSpec is the kubernetes work details
type KubeWorkSpec struct {
// Resource of the object
Resource string `json:"resource,omitempty"`
// Name of the object
Name string `json:"name,omitempty"`
// Namespace of the object
Namespace string `json:"namespace,omitempty"`
// ObjectTemplate is the template of the object
// +kubebuilder:validation:EmbeddedResource
// +kubebuilder:pruning:PreserveUnknownFields
ObjectTemplate runtime.RawExtension `json:"template,omitempty"`
}
const (
// UserIdentityAnnotation is identity annotation
UserIdentityAnnotation = "acm.io/user-identity"
// UserGroupAnnotation is user group annotation
UserGroupAnnotation = "acm.io/user-group"
)
func init() {
SchemeBuilder.Register(&ManagedClusterAction{}, &ManagedClusterActionList{})
}