-
Notifications
You must be signed in to change notification settings - Fork 24
/
common_types.go
404 lines (318 loc) · 13.2 KB
/
common_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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/*
Copyright 2022.
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.
*/
// +kubebuilder:object:generate=true
package common
import (
amclient "github.com/fluxninja/aperture/pkg/alertmanager/client"
"github.com/fluxninja/aperture/pkg/config"
etcd "github.com/fluxninja/aperture/pkg/etcd/client"
"github.com/fluxninja/aperture/pkg/jobs"
"github.com/fluxninja/aperture/pkg/metrics"
"github.com/fluxninja/aperture/pkg/net/grpc"
"github.com/fluxninja/aperture/pkg/net/grpcgateway"
"github.com/fluxninja/aperture/pkg/net/http"
"github.com/fluxninja/aperture/pkg/net/listener"
"github.com/fluxninja/aperture/pkg/net/tlsconfig"
"github.com/fluxninja/aperture/pkg/otelcollector"
"github.com/fluxninja/aperture/pkg/plugins"
"github.com/fluxninja/aperture/pkg/profilers"
"github.com/fluxninja/aperture/pkg/prometheus"
"github.com/fluxninja/aperture/pkg/watchdog"
"github.com/fluxninja/aperture/plugins/service/aperture-plugin-fluxninja/pluginconfig"
"github.com/fluxninja/aperture/plugins/service/aperture-plugin-sentry/sentry"
corev1 "k8s.io/api/core/v1"
)
// Image defines the Registry, Repository, Tag, PullPolicy, PullSecrets and Debug.
type Image struct {
// The registry of the image
//+kubebuilder:validation:Optional
Registry string `json:"registry" default:"docker.io/fluxninja"`
// The tag (version) of the image
//+kubebuilder:validation:Optional
Tag string `json:"tag" default:"latest"`
// The ImagePullPolicy of the image
//+kubebuilder:validation:Optional
PullPolicy string `json:"pullPolicy" default:"IfNotPresent" validate:"oneof=Never Always IfNotPresent"`
// The PullSecrets for the image
//+kubebuilder:validation:Optional
PullSecrets []string `json:"pullSecrets,omitempty"`
}
// AgentImage defines Image spec for Aperture Agent.
type AgentImage struct {
// Image specs for Agent
Image `json:",inline"`
// The repository of the image
//+kubebuilder:validation:Optional
Repository string `json:"repository" default:"aperture-agent"`
}
// ControllerImage defines Image spec for Aperture Controller.
type ControllerImage struct {
// Image specs for Controller
Image `json:",inline"`
// The repository of the image
//+kubebuilder:validation:Optional
Repository string `json:"repository" default:"aperture-controller"`
}
// Probe defines Enabled, InitialDelaySeconds, PeriodSeconds, TimeoutSeconds, FailureThreshold and SuccessThreshold for probes like livenessProbe.
type Probe struct {
// Enable probe on agent containers
Enabled bool `json:"enabled" default:"true"`
// Initial delay seconds for probe
//+kubebuilder:validation:Optional
InitialDelaySeconds int32 `json:"initialDelaySeconds" default:"15" validate:"gte=0"`
// Period delay seconds for probe
//+kubebuilder:validation:Optional
PeriodSeconds int32 `json:"periodSeconds" default:"15" validate:"gte=1"`
// Timeout delay seconds for probe
//+kubebuilder:validation:Optional
TimeoutSeconds int32 `json:"timeoutSeconds" default:"5" validate:"gte=1"`
// Failure threshold for probe
//+kubebuilder:validation:Optional
FailureThreshold int32 `json:"failureThreshold" default:"6" validate:"gte=1"`
// Success threshold for probe
//+kubebuilder:validation:Optional
SuccessThreshold int32 `json:"successThreshold" default:"1" validate:"gte=1"`
}
// PodSecurityContext defines Enabled and FsGroup for the Pods' security context.
type PodSecurityContext struct {
// Enable PodSecurityContext on Pod
Enabled bool `json:"enabled" default:"false"`
// fsGroup to define the Group ID for the Pod
//+kubebuilder:validation:Optional
FsGroup int64 `json:"fsGroup" default:"1001" validate:"gte=0"`
}
// ContainerSecurityContext defines Enabled, RunAsUser, RunAsNonRootUser and ReadOnlyRootFilesystem for the containers' security context.
type ContainerSecurityContext struct {
// Enable ContainerSecurityContext on containers
Enabled bool `json:"enabled" default:"false"`
// Set containers' Security Context runAsUser
//+kubebuilder:validation:Optional
RunAsUser int64 `json:"runAsUser" default:"1001" validate:"gte=0"`
// Set containers' Security Context runAsNonRoot
//+kubebuilder:validation:Optional
RunAsNonRootUser bool `json:"runAsNonRoot" default:"false"`
// Set agent containers' Security Context runAsNonRoot
//+kubebuilder:validation:Optional
ReadOnlyRootFilesystem bool `json:"readOnlyRootFilesystem" default:"false"`
}
// CommonSpec defines the desired the common state of Agent and Controller.
type CommonSpec struct {
// Labels to add to all deployed objects
//+mapType=atomic
//+kubebuilder:validation:Optional
Labels map[string]string `json:"labels,omitempty"`
// Annotations to add to all deployed objects
//+kubebuilder:validation:Optional
Annotations map[string]string `json:"annotations,omitempty"`
// Configuration for Agent or Controller service
//+kubebuilder:validation:Optional
Service Service `json:"service"`
// ServiceAccountSpec defines the the configuration pf Service account for Agent or Controller
//+kubebuilder:validation:Optional
ServiceAccountSpec ServiceAccountSpec `json:"serviceAccount"`
// livenessProbe related configuration
//+kubebuilder:validation:Optional
LivenessProbe Probe `json:"livenessProbe"`
// readinessProbe related configuration
//+kubebuilder:validation:Optional
ReadinessProbe Probe `json:"readinessProbe"`
// Custom livenessProbe that overrides the default one
//+kubebuilder:validation:Optional
CustomLivenessProbe *corev1.Probe `json:"customLivenessProbe,omitempty"`
// Custom readinessProbe that overrides the default one
//+kubebuilder:validation:Optional
CustomReadinessProbe *corev1.Probe `json:"customReadinessProbe,omitempty"`
// Resource requests and limits
//+kubebuilder:validation:Optional
Resources corev1.ResourceRequirements `json:"resources"`
// Configure Pods' Security Context
//+kubebuilder:validation:Optional
PodSecurityContext PodSecurityContext `json:"podSecurityContext"`
// Configure Containers' Security Context
//+kubebuilder:validation:Optional
ContainerSecurityContext ContainerSecurityContext `json:"containerSecurityContext"`
// Override default container command
//+kubebuilder:validation:Optional
Command []string `json:"command,omitempty"`
// Override default container args
//+kubebuilder:validation:Optional
Args []string `json:"args,omitempty"`
// Extra labels for pods
//+mapType=atomic
//+kubebuilder:validation:Optional
PodLabels map[string]string `json:"podLabels,omitempty"`
// Extra Annotations for pods
//+kubebuilder:validation:Optional
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
// Affinity for pods assignment.
//+kubebuilder:validation:Optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`
// Node labels for pods assignment
//+kubebuilder:validation:Optional
//+mapType=atomic
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Tolerations for pods assignment
//+kubebuilder:validation:Optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
// Seconds Redmine pod needs to terminate gracefully
//+kubebuilder:validation:Optional
TerminationGracePeriodSeconds int64 `json:"terminationGracePeriodSeconds" validate:"gte=0"`
// For the container(s) to automate configuration before or after startup
//+kubebuilder:validation:Optional
LifecycleHooks *corev1.Lifecycle `json:"lifecycleHooks,omitempty" validate:"omitempty"`
// Array with extra environment variables to add
//+kubebuilder:validation:Optional
ExtraEnvVars []corev1.EnvVar `json:"extraEnvVars,omitempty"`
// Name of existing ConfigMap containing extra env vars
//+kubebuilder:validation:Optional
ExtraEnvVarsCM string `json:"extraEnvVarsCM"`
// Name of existing Secret containing extra env vars
//+kubebuilder:validation:Optional
ExtraEnvVarsSecret string `json:"extraEnvVarsSecret"`
// Optionally specify extra list of additional volumes for the pod(s)
//+kubebuilder:validation:Optional
ExtraVolumes []corev1.Volume `json:"extraVolumes,omitempty"`
// Optionally specify extra list of additional volumeMounts
//+kubebuilder:validation:Optional
ExtraVolumeMounts []corev1.VolumeMount `json:"extraVolumeMounts,omitempty"`
// Add additional sidecar containers
//+kubebuilder:validation:Optional
Sidecars []corev1.Container `json:"sidecars,omitempty"`
// Add additional init containers
//+kubebuilder:validation:Optional
InitContainers []corev1.Container `json:"initContainers,omitempty"`
// Secrets
//+kubebuilder:validation:Optional
Secrets Secrets `json:"secrets"`
}
// Secrets for Agent or Controller.
type Secrets struct {
// FluxNinja plugin.
//+kubebuilder:validation:Optional
FluxNinjaPlugin APIKeySecret `json:"fluxNinjaPlugin"`
}
// APIKeySecret defines fields required for creation/usage of secret for the ApiKey of Agent and Controller.
type APIKeySecret struct {
// Create new secret or not
Create bool `json:"create" default:"false"`
// Secret details
//+kubebuilder:validation:Optional
SecretKeyRef SecretKeyRef `json:"secretKeyRef"`
// Value for the ApiKey
Value string `json:"value"`
}
// SecretKeyRef defines fields for details of the ApiKey secret.
type SecretKeyRef struct {
// Name of the secret
//+kubebuilder:validation:Optional
Name string `json:"name"`
// Key of the secret in Data
//+kubebuilder:validation:Optional
Key string `json:"key" default:"apiKey"`
}
// APIKeySecretSpec defines API Key secret details for Agent and Controller.
type APIKeySecretSpec struct {
// API Key secret reference for Agent
//+kubebuilder:validation:Optional
Agent APIKeySecret `json:"agent"`
// API Key secret reference for Controller
//+kubebuilder:validation:Optional
Controller APIKeySecret `json:"controller"`
}
// CommonConfigSpec defines common configuration for agent and controller.
type CommonConfigSpec struct {
// Client configuration such as proxy settings.
//+kubebuilder:validation:Optional
Client ClientConfigSpec `json:"client"`
// Etcd configuration.
//+kubebuilder:validation:Required
Etcd etcd.EtcdConfig `json:"etcd"`
// Liveness probe configuration.
//+kubebuilder:validation:Optional
Liveness ProbeConfigSpec `json:"liveness"`
// Readiness probe configuration.
//+kubebuilder:validation:Optional
Readiness ProbeConfigSpec `json:"readiness"`
// Log configuration.
//+kubebuilder:validation:Optional
Log config.LogConfig `json:"log"`
// Metrics configuration.
//+kubebuilder:validation:Optional
Metrics metrics.MetricsConfig `json:"metrics"`
// OTEL configuration.
//+kubebuilder:validation:Optional
Otel otelcollector.OtelConfig `json:"otel"`
// Plugins configuration.
//+kubebuilder:validation:Optional
Plugins plugins.PluginsConfig `json:"plugins"`
// Profilers configuration.
//+kubebuilder:validation:Optional
Profilers profilers.ProfilersConfig `json:"profilers"`
// Prometheus configuration.
//+kubebuilder:validation:Required
Prometheus prometheus.PrometheusConfig `json:"prometheus"`
// Server configuration.
//+kubebuilder:validation:Optional
Server ServerConfigSpec `json:"server"`
// Watchdog configuration.
//+kubebuilder:validation:Optional
Watchdog watchdog.WatchdogConfig `json:"watchdog"`
// Alert Managers configuration.
//+kubebuilder:validation:Optional
Alertmanagers amclient.AlertManagerConfig `json:"alertmanagers,omitempty"`
// BundledPluginsSpec defines configuration for bundled plugins.
//+kubebuilder:validation:Optional
BundledPluginsSpec `json:",inline"`
}
// ServerConfigSpec configures main server.
type ServerConfigSpec struct {
// Listener configuration.
//+kubebuilder:validation:Optional
listener.ListenerConfig `json:",inline"`
// GRPC server configuration.
//+kubebuilder:validation:Optional
Grpc grpc.GRPCServerConfig `json:"grpc"`
// GRPC Gateway configuration.
//+kubebuilder:validation:Optional
GrpcGateway grpcgateway.GRPCGatewayConfig `json:"grpc_gateway"`
// HTTP server configuration.
//+kubebuilder:validation:Optional
HTTP http.HTTPServerConfig `json:"http"`
// TLS configuration.
//+kubebuilder:validation:Optional
TLS tlsconfig.ServerTLSConfig `json:"tls"`
}
// ProbeConfigSpec defines liveness and readiness probe configuration.
type ProbeConfigSpec struct {
// Scheduler settings.
//+kubebuilder:validation:Optional
Scheduler jobs.JobGroupConfig `json:"scheduler"`
// Service settings.
//+kubebuilder:validation:Optional
Service jobs.JobConfig `json:"service"`
}
// ClientConfigSpec defines client configuration.
type ClientConfigSpec struct {
// Proxy settings for the client.
//+kubebuilder:validation:Optional
Proxy http.ProxyConfig `json:"proxy"`
}
// BundledPluginsSpec defines configuration for bundled plugins.
type BundledPluginsSpec struct {
// FluxNinja Cloud plugin configuration.
//+kubebuilder:validation:Optional
FluxNinjaPlugin pluginconfig.FluxNinjaPluginConfig `json:"fluxninja_plugin"`
// Sentry plugin configuration.
//+kubebuilder:validation:Optional
SentryPlugin sentry.SentryConfig `json:"sentry_plugin"`
}