-
Notifications
You must be signed in to change notification settings - Fork 517
/
types.go
286 lines (238 loc) · 12.8 KB
/
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
// MyOperatorResource is an example operator configuration type
//
// Compatibility level 4: No compatibility is provided, the API can change at any point for any reason. These capabilities should not be used by applications needing long term support.
// +openshift:compatibility-gen:internal
type MyOperatorResource struct {
metav1.TypeMeta `json:",inline"`
// metadata is the standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
metav1.ObjectMeta `json:"metadata"`
// +kubebuilder:validation:Required
// +required
Spec MyOperatorResourceSpec `json:"spec"`
Status MyOperatorResourceStatus `json:"status"`
}
type MyOperatorResourceSpec struct {
OperatorSpec `json:",inline"`
}
type MyOperatorResourceStatus struct {
OperatorStatus `json:",inline"`
}
// +kubebuilder:validation:Pattern=`^(Managed|Unmanaged|Force|Removed)$`
type ManagementState string
var (
// Force means that the operator is actively managing its resources but will not block an upgrade
// if unmet prereqs exist. This state puts the operator at risk for unsuccessful upgrades
Force ManagementState = "Force"
// Managed means that the operator is actively managing its resources and trying to keep the component active.
// It will only upgrade the component if it is safe to do so
Managed ManagementState = "Managed"
// Unmanaged means that the operator will not take any action related to the component
// Some operators might not support this management state as it might damage the cluster and lead to manual recovery.
Unmanaged ManagementState = "Unmanaged"
// Removed means that the operator is actively managing its resources and trying to remove all traces of the component
// Some operators (like kube-apiserver-operator) might not support this management state as removing the API server will
// brick the cluster.
Removed ManagementState = "Removed"
)
// OperatorSpec contains common fields operators need. It is intended to be anonymous included
// inside of the Spec struct for your particular operator.
type OperatorSpec struct {
// managementState indicates whether and how the operator should manage the component
ManagementState ManagementState `json:"managementState"`
// logLevel is an intent based logging for an overall component. It does not give fine grained control, but it is a
// simple way to manage coarse grained logging choices that operators have to interpret for their operands.
//
// Valid values are: "Normal", "Debug", "Trace", "TraceAll".
// Defaults to "Normal".
// +optional
// +kubebuilder:default=Normal
LogLevel LogLevel `json:"logLevel,omitempty"`
// operatorLogLevel is an intent based logging for the operator itself. It does not give fine grained control, but it is a
// simple way to manage coarse grained logging choices that operators have to interpret for themselves.
//
// Valid values are: "Normal", "Debug", "Trace", "TraceAll".
// Defaults to "Normal".
// +optional
// +kubebuilder:default=Normal
OperatorLogLevel LogLevel `json:"operatorLogLevel,omitempty"`
// unsupportedConfigOverrides overrides the final configuration that was computed by the operator.
// Red Hat does not support the use of this field.
// Misuse of this field could lead to unexpected behavior or conflict with other configuration options.
// Seek guidance from the Red Hat support before using this field.
// Use of this property blocks cluster upgrades, it must be removed before upgrading your cluster.
// +optional
// +nullable
// +kubebuilder:pruning:PreserveUnknownFields
UnsupportedConfigOverrides runtime.RawExtension `json:"unsupportedConfigOverrides"`
// observedConfig holds a sparse config that controller has observed from the cluster state. It exists in spec because
// it is an input to the level for the operator
// +optional
// +nullable
// +kubebuilder:pruning:PreserveUnknownFields
ObservedConfig runtime.RawExtension `json:"observedConfig"`
}
// +kubebuilder:validation:Enum="";Normal;Debug;Trace;TraceAll
type LogLevel string
var (
// Normal is the default. Normal, working log information, everything is fine, but helpful notices for auditing or common operations. In kube, this is probably glog=2.
Normal LogLevel = "Normal"
// Debug is used when something went wrong. Even common operations may be logged, and less helpful but more quantity of notices. In kube, this is probably glog=4.
Debug LogLevel = "Debug"
// Trace is used when something went really badly and even more verbose logs are needed. Logging every function call as part of a common operation, to tracing execution of a query. In kube, this is probably glog=6.
Trace LogLevel = "Trace"
// TraceAll is used when something is broken at the level of API content/decoding. It will dump complete body content. If you turn this on in a production cluster
// prepare from serious performance issues and massive amounts of logs. In kube, this is probably glog=8.
TraceAll LogLevel = "TraceAll"
)
type OperatorStatus struct {
// observedGeneration is the last generation change you've dealt with
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// conditions is a list of conditions and their status
// +listType=map
// +listMapKey=type
// +optional
Conditions []OperatorCondition `json:"conditions,omitempty"`
// version is the level this availability applies to
// +optional
Version string `json:"version,omitempty"`
// readyReplicas indicates how many replicas are ready and at the desired state
ReadyReplicas int32 `json:"readyReplicas"`
// latestAvailableRevision is the deploymentID of the most recent deployment
// +optional
// +kubebuilder:validation:XValidation:rule="self >= oldSelf",message="must only increase"
LatestAvailableRevision int32 `json:"latestAvailableRevision,omitempty"`
// generations are used to determine when an item needs to be reconciled or has changed in a way that needs a reaction.
// +listType=map
// +listMapKey=group
// +listMapKey=resource
// +listMapKey=namespace
// +listMapKey=name
// +optional
Generations []GenerationStatus `json:"generations,omitempty"`
}
// GenerationStatus keeps track of the generation for a given resource so that decisions about forced updates can be made.
type GenerationStatus struct {
// group is the group of the thing you're tracking
// +kubebuilder:validation:Required
Group string `json:"group"`
// resource is the resource type of the thing you're tracking
// +kubebuilder:validation:Required
Resource string `json:"resource"`
// namespace is where the thing you're tracking is
// +kubebuilder:validation:Required
Namespace string `json:"namespace"`
// name is the name of the thing you're tracking
// +kubebuilder:validation:Required
Name string `json:"name"`
// TODO: Add validation for lastGeneration. The value for this field should generally increase, except when the associated
// resource has been deleted and re-created. To accurately validate this field, we should introduce a new UID field and only
// enforce an increasing value in lastGeneration when the UID remains unchanged. A change in the UID indicates that the resource
// was re-created, allowing the lastGeneration value to reset or decrease.
// lastGeneration is the last generation of the workload controller involved
LastGeneration int64 `json:"lastGeneration"`
// hash is an optional field set for resources without generation that are content sensitive like secrets and configmaps
Hash string `json:"hash"`
}
var (
// Available indicates that the operand is present and accessible in the cluster
OperatorStatusTypeAvailable = "Available"
// Progressing indicates that the operator is trying to transition the operand to a different state
OperatorStatusTypeProgressing = "Progressing"
// Degraded indicates that the operator (not the operand) is unable to fulfill the user intent
OperatorStatusTypeDegraded = "Degraded"
// PrereqsSatisfied indicates that the things this operator depends on are present and at levels compatible with the
// current and desired states.
OperatorStatusTypePrereqsSatisfied = "PrereqsSatisfied"
// Upgradeable indicates that the operator configuration itself (not prereqs) can be auto-upgraded by the CVO
OperatorStatusTypeUpgradeable = "Upgradeable"
)
// OperatorCondition is just the standard condition fields.
type OperatorCondition struct {
// type of condition in CamelCase or in foo.example.com/CamelCase.
// ---
// Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be
// useful (see .node.status.conditions), the ability to deconflict is important.
// The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Pattern=`^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$`
// +kubebuilder:validation:MaxLength=316
Type string `json:"type" protobuf:"bytes,1,opt,name=type"`
// status of the condition, one of True, False, Unknown.
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=True;False;Unknown
Status ConditionStatus `json:"status"`
// lastTransitionTime is the last time the condition transitioned from one status to another.
// This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=date-time
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
}
type ConditionStatus string
const (
ConditionTrue ConditionStatus = "True"
ConditionFalse ConditionStatus = "False"
ConditionUnknown ConditionStatus = "Unknown"
)
// StaticPodOperatorSpec is spec for controllers that manage static pods.
type StaticPodOperatorSpec struct {
OperatorSpec `json:",inline"`
// forceRedeploymentReason can be used to force the redeployment of the operand by providing a unique string.
// This provides a mechanism to kick a previously failed deployment and provide a reason why you think it will work
// this time instead of failing again on the same config.
ForceRedeploymentReason string `json:"forceRedeploymentReason"`
// failedRevisionLimit is the number of failed static pod installer revisions to keep on disk and in the api
// -1 = unlimited, 0 or unset = 5 (default)
FailedRevisionLimit int32 `json:"failedRevisionLimit,omitempty"`
// succeededRevisionLimit is the number of successful static pod installer revisions to keep on disk and in the api
// -1 = unlimited, 0 or unset = 5 (default)
SucceededRevisionLimit int32 `json:"succeededRevisionLimit,omitempty"`
}
// StaticPodOperatorStatus is status for controllers that manage static pods. There are different needs because individual
// node status must be tracked.
type StaticPodOperatorStatus struct {
OperatorStatus `json:",inline"`
// latestAvailableRevisionReason describe the detailed reason for the most recent deployment
// +optional
LatestAvailableRevisionReason string `json:"latestAvailableRevisionReason,omitempty"`
// nodeStatuses track the deployment values and errors across individual nodes
// +listType=map
// +listMapKey=nodeName
// +optional
NodeStatuses []NodeStatus `json:"nodeStatuses,omitempty"`
}
// NodeStatus provides information about the current state of a particular node managed by this operator.
type NodeStatus struct {
// nodeName is the name of the node
// +kubebuilder:validation:Required
NodeName string `json:"nodeName"`
// currentRevision is the generation of the most recently successful deployment
CurrentRevision int32 `json:"currentRevision"`
// targetRevision is the generation of the deployment we're trying to apply
TargetRevision int32 `json:"targetRevision,omitempty"`
// lastFailedRevision is the generation of the deployment we tried and failed to deploy.
LastFailedRevision int32 `json:"lastFailedRevision,omitempty"`
// lastFailedTime is the time the last failed revision failed the last time.
LastFailedTime *metav1.Time `json:"lastFailedTime,omitempty"`
// lastFailedReason is a machine readable failure reason string.
LastFailedReason string `json:"lastFailedReason,omitempty"`
// lastFailedCount is how often the installer pod of the last failed revision failed.
LastFailedCount int `json:"lastFailedCount,omitempty"`
// lastFallbackCount is how often a fallback to a previous revision happened.
LastFallbackCount int `json:"lastFallbackCount,omitempty"`
// lastFailedRevisionErrors is a list of human readable errors during the failed deployment referenced in lastFailedRevision.
// +listType=atomic
LastFailedRevisionErrors []string `json:"lastFailedRevisionErrors,omitempty"`
}