-
Notifications
You must be signed in to change notification settings - Fork 2
/
radixdeploytypes.go
405 lines (329 loc) · 15.1 KB
/
radixdeploytypes.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
405
package v1
import (
"reflect"
"strings"
core_v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// RadixDeployment describe a deployment
type RadixDeployment struct {
meta_v1.TypeMeta `json:",inline" yaml:",inline"`
meta_v1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
Spec RadixDeploymentSpec `json:"spec" yaml:"spec"`
Status RadixDeployStatus `json:"status" yaml:"status"`
}
func (rd *RadixDeployment) GetComponentByName(name string) *RadixDeployComponent {
for _, component := range rd.Spec.Components {
if strings.EqualFold(component.Name, name) {
return &component
}
}
return nil
}
func (rd *RadixDeployment) GetJobComponentByName(name string) *RadixDeployJobComponent {
for _, jobComponent := range rd.Spec.Jobs {
if strings.EqualFold(jobComponent.Name, name) {
return &jobComponent
}
}
return nil
}
// RadixDeployStatus is the status for a rd
type RadixDeployStatus struct {
ActiveFrom meta_v1.Time `json:"activeFrom" yaml:"activeFrom"`
ActiveTo meta_v1.Time `json:"activeTo" yaml:"activeTo"`
Condition RadixDeployCondition `json:"condition" yaml:"condition"`
Reconciled meta_v1.Time `json:"reconciled" yaml:"reconciled"`
}
// RadixDeployCondition Holds the condition of a component
type RadixDeployCondition string
// These are valid conditions of a deployment.
const (
// Active means the radix deployment is active and should be consolidated
DeploymentActive RadixDeployCondition = "Active"
// Inactive means radix deployment is inactive and should not be consolidated
DeploymentInactive RadixDeployCondition = "Inactive"
)
// RadixDeploymentSpec is the spec for a deployment
type RadixDeploymentSpec struct {
AppName string `json:"appname" yaml:"appname"`
Components []RadixDeployComponent `json:"components"`
Jobs []RadixDeployJobComponent `json:"jobs"`
Environment string `json:"environment" yaml:"environment"`
ImagePullSecrets []core_v1.LocalObjectReference `json:"imagePullSecrets" yaml:"imagePullSecrets"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// RadixDeploymentList is a list of Radix deployments
type RadixDeploymentList struct {
meta_v1.TypeMeta `json:",inline" yaml:",inline"`
meta_v1.ListMeta `json:"metadata" yaml:"metadata"`
Items []RadixDeployment `json:"items" yaml:"items"`
}
// RadixDeployComponent defines a single component within a RadixDeployment - maps to single deployment/service/ingress etc
type RadixDeployComponent struct {
Name string `json:"name" yaml:"name"`
Image string `json:"image" yaml:"image"`
Ports []ComponentPort `json:"ports" yaml:"ports"`
Replicas *int `json:"replicas" yaml:"replicas"`
Public bool `json:"public" yaml:"public"` // Deprecated: For backwards compatibility Public is still supported, new code should use PublicPort instead
PublicPort string `json:"publicPort,omitempty" yaml:"publicPort,omitempty"`
EnvironmentVariables EnvVarsMap `json:"environmentVariables,omitempty" yaml:"environmentVariables,omitempty"`
Secrets []string `json:"secrets,omitempty" yaml:"secrets,omitempty"`
SecretRefs RadixSecretRefs `json:"secretRefs,omitempty" yaml:"secretRefs,omitempty"`
IngressConfiguration []string `json:"ingressConfiguration,omitempty" yaml:"ingressConfiguration,omitempty"`
DNSAppAlias bool `json:"dnsAppAlias,omitempty" yaml:"dnsAppAlias,omitempty"`
DNSExternalAlias []string `json:"dnsExternalAlias,omitempty" yaml:"dnsExternalAlias,omitempty"`
Monitoring bool `json:"monitoring" yaml:"monitoring"`
MonitoringConfig MonitoringConfig `json:"monitoringConfig,omitempty" yaml:"monitoringConfig,omitempty"`
Resources ResourceRequirements `json:"resources,omitempty" yaml:"resources,omitempty"`
HorizontalScaling *RadixHorizontalScaling `json:"horizontalScaling,omitempty" yaml:"horizontalScaling,omitempty"`
AlwaysPullImageOnDeploy bool `json:"alwaysPullImageOnDeploy" yaml:"alwaysPullImageOnDeploy"`
VolumeMounts []RadixVolumeMount `json:"volumeMounts,omitempty" yaml:"volumeMounts,omitempty"`
Node RadixNode `json:"node,omitempty" yaml:"node,omitempty"`
Authentication *Authentication `json:"authentication,omitempty" yaml:"authentication,omitempty"`
Identity *Identity `json:"identity,omitempty" yaml:"identity,omitempty"`
}
func (deployComponent *RadixDeployComponent) GetName() string {
return deployComponent.Name
}
func (deployComponent *RadixDeployComponent) GetType() RadixComponentType {
return RadixComponentTypeComponent
}
func (deployComponent *RadixDeployComponent) GetImage() string {
return deployComponent.Image
}
func (deployComponent *RadixDeployComponent) GetPorts() []ComponentPort {
return deployComponent.Ports
}
func (deployComponent *RadixDeployComponent) GetEnvironmentVariables() EnvVarsMap {
return deployComponent.EnvironmentVariables
}
func (deployComponent *RadixDeployComponent) GetSecrets() []string {
return deployComponent.Secrets
}
func (deployComponent *RadixDeployComponent) GetSecretRefs() RadixSecretRefs {
return deployComponent.SecretRefs
}
func (deployComponent *RadixDeployComponent) GetMonitoring() bool {
return deployComponent.Monitoring
}
func (deployComponent *RadixDeployComponent) GetMonitoringConfig() MonitoringConfig {
return deployComponent.MonitoringConfig
}
func (deployComponent *RadixDeployComponent) GetResources() *ResourceRequirements {
return &deployComponent.Resources
}
func (deployComponent *RadixDeployComponent) GetVolumeMounts() []RadixVolumeMount {
return deployComponent.VolumeMounts
}
func (deployComponent *RadixDeployComponent) IsAlwaysPullImageOnDeploy() bool {
return deployComponent.AlwaysPullImageOnDeploy
}
func (deployComponent *RadixDeployComponent) GetReplicas() *int {
return deployComponent.Replicas
}
func (deployComponent *RadixDeployComponent) GetHorizontalScaling() *RadixHorizontalScaling {
return deployComponent.HorizontalScaling
}
func (deployComponent *RadixDeployComponent) GetPublicPort() string {
return deployComponent.PublicPort
}
func (deployComponent *RadixDeployComponent) IsPublic() bool {
return len(deployComponent.PublicPort) > 0
}
func (deployComponent *RadixDeployComponent) GetDNSExternalAlias() []string {
return deployComponent.DNSExternalAlias
}
func (deployComponent *RadixDeployComponent) IsDNSAppAlias() bool {
return deployComponent.DNSAppAlias
}
func (deployComponent *RadixDeployComponent) GetIngressConfiguration() []string {
return deployComponent.IngressConfiguration
}
func (deployComponent *RadixDeployComponent) GetNode() *RadixNode {
return &deployComponent.Node
}
func (deployComponent *RadixDeployComponent) GetAuthentication() *Authentication {
return deployComponent.Authentication
}
func (deployComponent *RadixDeployComponent) GetIdentity() *Identity {
return deployComponent.Identity
}
func (deployComponent *RadixDeployComponent) SetName(name string) {
deployComponent.Name = name
}
func (deployComponent *RadixDeployComponent) SetVolumeMounts(mounts []RadixVolumeMount) {
deployComponent.VolumeMounts = mounts
}
func (deployComponent *RadixDeployComponent) SetEnvironmentVariables(envVars EnvVarsMap) {
deployComponent.EnvironmentVariables = envVars
}
func (deployJobComponent *RadixDeployJobComponent) GetName() string {
return deployJobComponent.Name
}
func (deployJobComponent *RadixDeployJobComponent) GetType() RadixComponentType {
return RadixComponentTypeJob
}
func (deployJobComponent *RadixDeployJobComponent) GetImage() string {
return deployJobComponent.Image
}
func (deployJobComponent *RadixDeployJobComponent) GetPorts() []ComponentPort {
return deployJobComponent.Ports
}
func (deployJobComponent *RadixDeployJobComponent) GetEnvironmentVariables() EnvVarsMap {
return deployJobComponent.EnvironmentVariables
}
func (deployJobComponent *RadixDeployJobComponent) GetSecrets() []string {
return deployJobComponent.Secrets
}
func (deployComponent *RadixDeployJobComponent) GetSecretRefs() RadixSecretRefs {
return deployComponent.SecretRefs
}
func (deployJobComponent *RadixDeployJobComponent) GetMonitoring() bool {
return deployJobComponent.Monitoring
}
func (deployJobComponent *RadixDeployJobComponent) GetMonitoringConfig() MonitoringConfig {
return deployJobComponent.MonitoringConfig
}
func (deployJobComponent *RadixDeployJobComponent) GetResources() *ResourceRequirements {
return &deployJobComponent.Resources
}
func (deployJobComponent *RadixDeployJobComponent) GetVolumeMounts() []RadixVolumeMount {
return deployJobComponent.VolumeMounts
}
func (deployJobComponent *RadixDeployJobComponent) GetEnvironment() string {
return deployJobComponent.Environment
}
func (deployJobComponent *RadixDeployJobComponent) IsAlwaysPullImageOnDeploy() bool {
return deployJobComponent.AlwaysPullImageOnDeploy
}
func (deployJobComponent *RadixDeployJobComponent) GetReplicas() *int {
replicas := 1
return &replicas
}
func (deployJobComponent *RadixDeployJobComponent) GetHorizontalScaling() *RadixHorizontalScaling {
return nil
}
func (deployJobComponent *RadixDeployJobComponent) GetPublicPort() string {
return ""
}
func (deployJobComponent *RadixDeployJobComponent) IsPublic() bool {
return false
}
func (deployJobComponent *RadixDeployJobComponent) GetDNSExternalAlias() []string {
return nil
}
func (deployJobComponent *RadixDeployJobComponent) IsDNSAppAlias() bool {
return false
}
func (deployJobComponent *RadixDeployJobComponent) GetIngressConfiguration() []string {
return nil
}
func (deployJobComponent *RadixDeployJobComponent) GetNode() *RadixNode {
return &deployJobComponent.Node
}
func (deployJobComponent *RadixDeployJobComponent) GetAuthentication() *Authentication {
return nil
}
func (deployJobComponent *RadixDeployJobComponent) GetIdentity() *Identity {
return deployJobComponent.Identity
}
func (deployJobComponent *RadixDeployJobComponent) GetNotifications() *Notifications {
return deployJobComponent.Notifications
}
func (deployJobComponent *RadixDeployJobComponent) SetName(name string) {
deployJobComponent.Name = name
}
func (deployJobComponent *RadixDeployJobComponent) SetVolumeMounts(mounts []RadixVolumeMount) {
deployJobComponent.VolumeMounts = mounts
}
func (deployJobComponent *RadixDeployJobComponent) SetEnvironmentVariables(envVars EnvVarsMap) {
deployJobComponent.EnvironmentVariables = envVars
}
// GetNrOfReplicas gets number of replicas component will run
func (deployComponent RadixDeployComponent) GetNrOfReplicas() int32 {
replicas := int32(1)
if deployComponent.HorizontalScaling != nil && deployComponent.HorizontalScaling.MinReplicas != nil {
replicas = *deployComponent.HorizontalScaling.MinReplicas
} else if deployComponent.Replicas != nil {
replicas = int32(*deployComponent.Replicas)
}
return replicas
}
// RadixDeployJobComponent defines a single job component within a RadixDeployment
// The job component is used by the radix-job-scheduler to create Kubernetes Job objects
type RadixDeployJobComponent struct {
Name string `json:"name" yaml:"name"`
Environment string `json:"environment" yaml:"environment"`
Image string `json:"image" yaml:"image"`
Ports []ComponentPort `json:"ports" yaml:"ports"`
EnvironmentVariables EnvVarsMap `json:"environmentVariables,omitempty" yaml:"environmentVariables,omitempty"`
Secrets []string `json:"secrets,omitempty" yaml:"secrets,omitempty"`
SecretRefs RadixSecretRefs `json:"secretRefs,omitempty" yaml:"secretRefs,omitempty"`
Monitoring bool `json:"monitoring" yaml:"monitoring"`
MonitoringConfig MonitoringConfig `json:"monitoringConfig,omitempty" yaml:"monitoringConfig,omitempty"`
Resources ResourceRequirements `json:"resources,omitempty" yaml:"resources,omitempty"`
VolumeMounts []RadixVolumeMount `json:"volumeMounts,omitempty" yaml:"volumeMounts,omitempty"`
SchedulerPort *int32 `json:"schedulerPort,omitempty" yaml:"schedulerPort,omitempty"`
Payload *RadixJobComponentPayload `json:"payload,omitempty" yaml:"payload,omitempty"`
AlwaysPullImageOnDeploy bool `json:"alwaysPullImageOnDeploy" yaml:"alwaysPullImageOnDeploy"`
Node RadixNode `json:"node,omitempty" yaml:"node,omitempty"`
TimeLimitSeconds *int64 `json:"timeLimitSeconds,omitempty" yaml:"timeLimitSeconds,omitempty"`
BackoffLimit *int32 `json:"backoffLimit,omitempty" yaml:"backoffLimit,omitempty"`
Identity *Identity `json:"identity,omitempty" yaml:"identity,omitempty"`
Notifications *Notifications `json:"notifications,omitempty"`
}
type RadixComponentType string
const (
RadixComponentTypeComponent RadixComponentType = "component"
RadixComponentTypeJob RadixComponentType = "job"
)
// RadixCommonDeployComponent defines a common component interface a RadixDeployment
type RadixCommonDeployComponent interface {
GetName() string
GetType() RadixComponentType
GetImage() string
GetPorts() []ComponentPort
GetEnvironmentVariables() EnvVarsMap
SetEnvironmentVariables(envVars EnvVarsMap)
GetSecrets() []string
GetSecretRefs() RadixSecretRefs
GetMonitoring() bool
GetMonitoringConfig() MonitoringConfig
GetResources() *ResourceRequirements
GetVolumeMounts() []RadixVolumeMount
IsAlwaysPullImageOnDeploy() bool
GetReplicas() *int
GetHorizontalScaling() *RadixHorizontalScaling
GetPublicPort() string
IsPublic() bool
GetDNSExternalAlias() []string
IsDNSAppAlias() bool
GetIngressConfiguration() []string
GetNode() *RadixNode
GetAuthentication() *Authentication
SetName(name string)
SetVolumeMounts(mounts []RadixVolumeMount)
GetIdentity() *Identity
}
// RadixCommonDeployComponentFactory defines a common component factory
type RadixCommonDeployComponentFactory interface {
Create() RadixCommonDeployComponent
GetTargetType() reflect.Type
}
type RadixDeployComponentFactory struct{}
type RadixDeployJobComponentFactory struct{}
func (factory RadixDeployComponentFactory) Create() RadixCommonDeployComponent {
return &RadixDeployComponent{}
}
func (factory RadixDeployComponentFactory) GetTargetType() reflect.Type {
return reflect.TypeOf(&RadixDeployComponent{}).Elem()
}
func (factory RadixDeployJobComponentFactory) Create() RadixCommonDeployComponent {
return &RadixDeployJobComponent{}
}
func (factory RadixDeployJobComponentFactory) GetTargetType() reflect.Type {
return reflect.TypeOf(&RadixDeployJobComponentFactory{}).Elem()
}