/
airbyte_types.go
288 lines (224 loc) · 8.48 KB
/
airbyte_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
287
288
/*
Copyright 2023 zncdata-labs.
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 v1alpha1
import (
"github.com/zncdata-labs/operator-go/pkg/status"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// +kubebuilder:object:root=true
// +kubebuilder:printcolumn:name="Image",type="string",JSONPath=".spec.image.repository",description="The Docker Image of Airbyte"
// +kubebuilder:printcolumn:name="Tag",type="string",JSONPath=".spec.image.tag",description="The Docker Tag of Airbyte"
// +kubebuilder:subresource:status
// Airbyte is the Schema for the airbytes API
type Airbyte struct {
metav1.TypeMeta `json:",inline,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec AirbyteSpec `json:"spec,omitempty"`
Status status.Status `json:"status,omitempty"`
}
//+kubebuilder:object:root=true
// AirbyteList contains a list of Airbyte
type AirbyteList struct {
metav1.TypeMeta `json:",inline,omitempty"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Airbyte `json:"items,omitempty"`
}
// AirbyteSpec defines the desired state of Airbyte
type AirbyteSpec struct {
// +kubebuilder:validation:Required
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
// +kubebuilder:validation:Optional
ClusterConfig *ClusterRoleConfigSpec `json:"clusterConfig,omitempty"`
// +kubebuilder:validation:Required
Server *ServerSpec `json:"server"`
// +kubebuilder:validation:Required
Worker *WorkerSpec `json:"worker"`
// +kubebuilder:validation:Required
ApiServer *AirbyteApiServerSpec `json:"airbyteApiServer"`
// +kubebuilder:validation:Required
WebApp *WebAppSpec `json:"webApp"`
// +kubebuilder:validation:Required
PodSweeper *PodSweeperSpec `json:"podSweeper"`
// +kubebuilder:validation:Required
ConnectorBuilderServer *ConnectorBuilderServerSpec `json:"connectorBuilderServer"`
// +kubebuilder:validation:Required
AirbyteBootloader *AirbyteBootloaderSpec `json:"airbyteBootloader"`
// +kubebuilder:validation:Required
Temporal *TemporalSpec `json:"temporal"`
// +kubebuilder:validation:Required
Keycloak *KeycloakSpec `json:"keycloak"`
// +kubebuilder:validation:Required
Cron *CronSpec `json:"cron"`
}
type IngresRoleConfigSpec struct {
BaseRoleConfigSpec `json:",inline"`
// +kubebuilder:validation=Optional
Ingress *IngressSpec `json:"ingress,omitempty"`
}
type GenericRoleConfigSpec struct {
BaseRoleConfigSpec `json:",inline"`
Config *BaseConfigSpec `json:"config,omitempty"`
}
type DatabaseSpec struct {
// +kubebuilder:validation:Required
Reference string `json:"reference"`
}
type S3Spec struct {
S3BucketSpec `json:"bucket"`
// +kubebuilder:validation=Optional
// +kubebuilder:default=20
MaxConnect int `json:"maxConnect,omitempty"`
// +kubebuilder:validation=Optional
PathStyleAccess bool `json:"pathStyle_access,omitempty"`
}
type S3BucketSpec struct {
Reference string `json:"reference"`
}
type LogsClusterConfigSpec struct {
// +kubebuilder:validation:Optional
S3 *S3Spec `json:"s3,omitempty"`
}
type IngressSpec struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default:=true
Enabled bool `json:"enabled,omitempty"`
// +kubebuilder:validation:Optional
TLS *networkingv1.IngressTLS `json:"tls,omitempty"`
// +kubebuilder:validation:Optional
Annotations map[string]string `json:"annotations,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:default:="webapp.example.com"
Host string `json:"host,omitempty"`
}
type ServiceSpec struct {
// +kubebuilder:validation:Optional
Annotations map[string]string `json:"annotations,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:validation:enum=ClusterIP;NodePort;LoadBalancer;ExternalName
// +kubebuilder:default=ClusterIP
Type corev1.ServiceType `json:"type,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
// +kubebuilder:default=8001
Port int32 `json:"port,omitempty"`
}
type DebugSpec struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default=false
Enabled bool `json:"enabled,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:default=5005
RemoteDebugPort int32 `json:"RemoteDebugPort,omitempty"`
}
type BaseRoleConfigSpec struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default:=1
Replicas int32 `json:"replicas"`
// +kubebuilder:validation:Optional
Image *ImageSpec `json:"image"`
// +kubebuilder:validation:Optional
Labels map[string]string `json:"labels,omitempty"`
// +kubebuilder:validation:Optional
SecurityContext *corev1.PodSecurityContext `json:"securityContext"`
// +kubebuilder:validation:Optional
MatchLabels map[string]string `json:"matchLabels,omitempty"`
// +kubebuilder:validation:Optional
Affinity *corev1.Affinity `json:"affinity"`
// +kubebuilder:validation:Optional
NodeSelector map[string]string `json:"nodeSelector"`
// +kubebuilder:validation:Optional
Tolerations *corev1.Toleration `json:"tolerations"`
// +kubebuilder:validation:Optional
Service *ServiceSpec `json:"service"`
}
type BaseConfigSpec struct {
// +kubebuilder:validation:Optional
Resources *ResourcesSpec `json:"resources"`
}
type ResourcesSpec struct {
// +kubebuilder:validation:Optional
CPU *CPUResource `json:"cpu,omitempty"`
// +kubebuilder:validation:Optional
Memory *MemoryResource `json:"memory,omitempty"`
// +kubebuilder:validation:Optional
Storage map[string]*StorageResource `json:"storage,omitempty"`
}
type CPUResource struct {
// +kubebuilder:validation:Optional
Max *resource.Quantity `json:"max,omitempty"`
// +kubebuilder:validation:Optional
Min *resource.Quantity `json:"min,omitempty"`
}
type MemoryResource struct {
// +kubebuilder:validation:Optional
Limit *resource.Quantity `json:"limit,omitempty"`
}
type StorageResource struct {
Capacity *resource.Quantity `json:"capacity,omitempty"`
}
// BaseRoleConfigSpec implements RoleConfigObject interface
func safeAccess(ptr interface{}, fun func() interface{}) interface{} {
if ptr == nil {
return nil
}
return fun()
}
func (b *BaseRoleConfigSpec) GetReplicas() int32 {
return safeAccess(b, func() interface{} { return b.Replicas }).(int32)
}
func (b *BaseRoleConfigSpec) GetImage() *ImageSpec {
return safeAccess(b, func() interface{} { return b.Image }).(*ImageSpec)
}
func (b *BaseRoleConfigSpec) GetLabels() map[string]string {
return safeAccess(b, func() interface{} { return b.Labels }).(map[string]string)
}
func (b *BaseRoleConfigSpec) GetSecurityContext() *corev1.PodSecurityContext {
return safeAccess(b, func() interface{} { return b.SecurityContext }).(*corev1.PodSecurityContext)
}
func (b *BaseRoleConfigSpec) GetMatchLabels() map[string]string {
return safeAccess(b, func() interface{} { return b.MatchLabels }).(map[string]string)
}
func (b *BaseRoleConfigSpec) GetAffinity() *corev1.Affinity {
return safeAccess(b, func() interface{} { return b.Affinity }).(*corev1.Affinity)
}
func (b *BaseRoleConfigSpec) GetNodeSelector() map[string]string {
return safeAccess(b, func() interface{} { return b.NodeSelector }).(map[string]string)
}
func (b *BaseRoleConfigSpec) GetTolerations() *corev1.Toleration {
return safeAccess(b, func() interface{} { return b.Tolerations }).(*corev1.Toleration)
}
func (b *BaseRoleConfigSpec) GetService() *ServiceSpec {
return safeAccess(b, func() interface{} { return b.Service }).(*ServiceSpec)
}
func (g *GenericRoleConfigSpec) GetConfig() any {
return safeAccess(g, func() interface{} { return g.Config })
}
func (g *GenericRoleConfigSpec) GetResource() *ResourcesSpec {
if safeAccess(g, func() interface{} { return g.Config }) == nil {
return nil
}
return g.Config.Resources
}
func (a *Airbyte) GetNameWithSuffix(name string) string {
return a.GetName() + "-" + name
}
func (a *Airbyte) InitStatusConditions() {
a.Status.InitStatus(a)
a.Status.InitStatusConditions()
}