-
Notifications
You must be signed in to change notification settings - Fork 727
/
types.go
215 lines (192 loc) · 10 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
package v1alpha1
import (
corev1 "k8s.io/api/core/v1"
apiresource "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/argoproj/argo-events/pkg/apis/common"
)
// EventBus is the definition of a eventbus resource
// +genclient
// +kubebuilder:resource:singular=eventbus,shortName=eb
// +kubebuilder:subresource:status
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=true
type EventBus struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata" protobuf:"bytes,1,opt,name=metadata"`
Spec EventBusSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
// +optional
Status EventBusStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}
// EventBusList is the list of eventbus resources
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type EventBusList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata" protobuf:"bytes,1,opt,name=metadata"`
Items []EventBus `json:"items" protobuf:"bytes,2,rep,name=items"`
}
// EventBusSpec refers to specification of eventbus resource
type EventBusSpec struct {
// NATS eventbus
NATS *NATSBus `json:"nats,omitempty" protobuf:"bytes,1,opt,name=nats"`
}
// EventBusStatus holds the status of the eventbus resource
type EventBusStatus struct {
common.Status `json:",inline" protobuf:"bytes,1,opt,name=status"`
// Config holds the fininalized configuration of EventBus
Config BusConfig `json:"config,omitempty" protobuf:"bytes,2,opt,name=config"`
}
// NATSBus holds the NATS eventbus information
type NATSBus struct {
// Native means to bring up a native NATS service
Native *NativeStrategy `json:"native,omitempty" protobuf:"bytes,1,opt,name=native"`
// Exotic holds an exotic NATS config
Exotic *NATSConfig `json:"exotic,omitempty" protobuf:"bytes,2,opt,name=exotic"`
}
// AuthStrategy is the auth strategy of native nats installaion
type AuthStrategy string
// possible auth strategies
var (
AuthStrategyNone AuthStrategy = "none"
AuthStrategyToken AuthStrategy = "token"
)
// NativeStrategy indicates to install a native NATS service
type NativeStrategy struct {
// Size is the NATS StatefulSet size
Replicas int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"`
Auth *AuthStrategy `json:"auth,omitempty" protobuf:"bytes,2,opt,name=auth,casttype=AuthStrategy"`
// +optional
Persistence *PersistenceStrategy `json:"persistence,omitempty" protobuf:"bytes,3,opt,name=persistence"`
// ContainerTemplate contains customized spec for NATS container
// +optional
ContainerTemplate *ContainerTemplate `json:"containerTemplate,omitempty" protobuf:"bytes,4,opt,name=containerTemplate"`
// MetricsContainerTemplate contains customized spec for metrics container
// +optional
MetricsContainerTemplate *ContainerTemplate `json:"metricsContainerTemplate,omitempty" protobuf:"bytes,5,opt,name=metricsContainerTemplate"`
// NodeSelector is a selector which must be true for the pod to fit on a node.
// Selector which must match a node's labels for the pod to be scheduled on that node.
// More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty" protobuf:"bytes,6,rep,name=nodeSelector"`
// If specified, the pod's tolerations.
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty" protobuf:"bytes,7,rep,name=tolerations"`
// Metadata sets the pods's metadata, i.e. annotations and labels
Metadata *common.Metadata `json:"metadata,omitempty" protobuf:"bytes,8,opt,name=metadata"`
// SecurityContext holds pod-level security attributes and common container settings.
// Optional: Defaults to empty. See type description for default values of each field.
// +optional
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty" protobuf:"bytes,9,opt,name=securityContext"`
// Max Age of existing messages, i.e. "72h", “4h35m”
// +optional
MaxAge *string `json:"maxAge,omitempty" protobuf:"bytes,10,opt,name=maxAge"`
// ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images used by this PodSpec.
// If specified, these secrets will be passed to individual puller implementations for them to use. For example,
// in the case of docker, only DockerConfig type secrets are honored.
// More info: https://kubernetes.io/docs/concepts/containers/images#specifying-imagepullsecrets-on-a-pod
// +optional
// +patchMergeKey=name
// +patchStrategy=merge
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,11,rep,name=imagePullSecrets"`
// ServiceAccountName to apply to NATS StatefulSet
// +optional
ServiceAccountName string `json:"serviceAccountName,omitempty" protobuf:"bytes,12,opt,name=serviceAccountName"`
// If specified, indicates the EventSource pod's priority. "system-node-critical"
// and "system-cluster-critical" are two special keywords which indicate the
// highest priorities with the former being the highest priority. Any other
// name must be defined by creating a PriorityClass object with that name.
// If not specified, the pod priority will be default or zero if there is no
// default.
// More info: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/
// +optional
PriorityClassName string `json:"priorityClassName,omitempty" protobuf:"bytes,13,opt,name=priorityClassName"`
// The priority value. Various system components use this field to find the
// priority of the EventSource pod. When Priority Admission Controller is enabled,
// it prevents users from setting this field. The admission controller populates
// this field from PriorityClassName.
// The higher the value, the higher the priority.
// More info: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/
// +optional
Priority *int32 `json:"priority,omitempty" protobuf:"bytes,14,opt,name=priority"`
// The pod's scheduling constraints
// More info: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/
// +optional
Affinity *corev1.Affinity `json:"affinity,omitempty" protobuf:"bytes,15,opt,name=affinity"`
// Maximum number of messages per channel, 0 means unlimited. Defaults to 1000000
MaxMsgs *uint64 `json:"maxMsgs,omitempty" protobuf:"bytes,16,opt,name=maxMsgs"`
// Total size of messages per channel, 0 means unlimited. Defaults to 1GB
MaxBytes *string `json:"maxBytes,omitempty" protobuf:"bytes,17,opt,name=maxBytes"`
// Maximum number of subscriptions per channel, 0 means unlimited. Defaults to 1000
MaxSubs *uint64 `json:"maxSubs,omitempty" protobuf:"bytes,18,opt,name=maxSubs"`
}
// ContainerTemplate defines customized spec for a container
type ContainerTemplate struct {
Resources corev1.ResourceRequirements `json:"resources,omitempty" protobuf:"bytes,1,opt,name=resources"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty" protobuf:"bytes,2,opt,name=imagePullPolicy,casttype=PullPolicy"`
}
// GetReplicas return the replicas of statefulset
func (in *NativeStrategy) GetReplicas() int {
return int(in.Replicas)
}
// PersistenceStrategy defines the strategy of persistence
type PersistenceStrategy struct {
// Name of the StorageClass required by the claim.
// More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1
// +optional
StorageClassName *string `json:"storageClassName,omitempty" protobuf:"bytes,1,opt,name=storageClassName"`
// Available access modes such as ReadWriteOnce, ReadWriteMany
// https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes
// +optional
AccessMode *corev1.PersistentVolumeAccessMode `json:"accessMode,omitempty" protobuf:"bytes,2,opt,name=accessMode,casttype=k8s.io/api/core/v1.PersistentVolumeAccessMode"`
// Volume size, e.g. 10Gi
VolumeSize *apiresource.Quantity `json:"volumeSize,omitempty" protobuf:"bytes,3,opt,name=volumeSize"`
}
// BusConfig has the finalized configuration for EventBus
type BusConfig struct {
NATS *NATSConfig `json:"nats,omitempty" protobuf:"bytes,1,opt,name=nats"`
}
// NATSConfig holds the config of NATS
type NATSConfig struct {
// NATS streaming url
URL string `json:"url,omitempty" protobuf:"bytes,1,opt,name=url"`
// Cluster ID for nats streaming
ClusterID *string `json:"clusterID,omitempty" protobuf:"bytes,2,opt,name=clusterID"`
// Auth strategy, default to AuthStrategyNone
// +optional
Auth *AuthStrategy `json:"auth,omitempty" protobuf:"bytes,3,opt,name=auth,casttype=AuthStrategy"`
// Secret for auth
// +optional
AccessSecret *corev1.SecretKeySelector `json:"accessSecret,omitempty" protobuf:"bytes,4,opt,name=accessSecret"`
}
const (
// EventBusConditionDeployed has the status True when the EventBus
// has its RestfulSet/Deployment ans service created.
EventBusConditionDeployed common.ConditionType = "Deployed"
// EventBusConditionConfigured has the status True when the EventBus
// has its configuration ready.
EventBusConditionConfigured common.ConditionType = "Configured"
)
// InitConditions sets conditions to Unknown state.
func (s *EventBusStatus) InitConditions() {
s.InitializeConditions(EventBusConditionDeployed, EventBusConditionConfigured)
}
// MarkDeployed set the bus has been deployed.
func (s *EventBusStatus) MarkDeployed(reason, message string) {
s.MarkTrueWithReason(EventBusConditionDeployed, reason, message)
}
// MarkDeploying set the bus is deploying
func (s *EventBusStatus) MarkDeploying(reason, message string) {
s.MarkUnknown(EventBusConditionDeployed, reason, message)
}
// MarkDeployFailed set the bus deploy failed
func (s *EventBusStatus) MarkDeployFailed(reason, message string) {
s.MarkFalse(EventBusConditionDeployed, reason, message)
}
// MarkConfigured set the bus configuration has been done.
func (s *EventBusStatus) MarkConfigured() {
s.MarkTrue(EventBusConditionConfigured)
}
// MarkNotConfigured set the bus status not configured.
func (s *EventBusStatus) MarkNotConfigured(reason, message string) {
s.MarkFalse(EventBusConditionConfigured, reason, message)
}