/
typha_deployment_types.go
287 lines (252 loc) · 10.4 KB
/
typha_deployment_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
// Copyright (c) 2022 Tigera, Inc. All rights reserved.
/*
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 v1
import (
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
)
// TyphaDeploymentContainer is a typha Deployment container.
type TyphaDeploymentContainer struct {
// Name is an enum which identifies the typha Deployment container by name.
// +kubebuilder:validation:Enum=calico-typha
Name string `json:"name"`
// Resources allows customization of limits and requests for compute resources such as cpu and memory.
// If specified, this overrides the named typha Deployment container's resources.
// If omitted, the typha Deployment will use its default value for this container's resources.
// If used in conjunction with the deprecated ComponentResources, then this value takes precedence.
// +optional
Resources *v1.ResourceRequirements `json:"resources,omitempty"`
}
// TyphaDeploymentInitContainer is a typha Deployment init container.
type TyphaDeploymentInitContainer struct {
// Name is an enum which identifies the typha Deployment init container by name.
// +kubebuilder:validation:Enum=typha-certs-key-cert-provisioner
Name string `json:"name"`
// Resources allows customization of limits and requests for compute resources such as cpu and memory.
// If specified, this overrides the named typha Deployment init container's resources.
// If omitted, the typha Deployment will use its default value for this init container's resources.
// If used in conjunction with the deprecated ComponentResources, then this value takes precedence.
// +optional
Resources *v1.ResourceRequirements `json:"resources,omitempty"`
}
// TyphaDeploymentPodSpec is the typha Deployment's PodSpec.
type TyphaDeploymentPodSpec struct {
// InitContainers is a list of typha init containers.
// If specified, this overrides the specified typha Deployment init containers.
// If omitted, the typha Deployment will use its default values for its init containers.
// +optional
InitContainers []TyphaDeploymentInitContainer `json:"initContainers,omitempty"`
// Containers is a list of typha containers.
// If specified, this overrides the specified typha Deployment containers.
// If omitted, the typha Deployment will use its default values for its containers.
// +optional
Containers []TyphaDeploymentContainer `json:"containers,omitempty"`
// Affinity is a group of affinity scheduling rules for the typha pods.
// If specified, this overrides any affinity that may be set on the typha Deployment.
// If omitted, the typha Deployment will use its default value for affinity.
// If used in conjunction with the deprecated TyphaAffinity, then this value takes precedence.
// WARNING: Please note that this field will override the default calico-typha Deployment affinity.
// +optional
Affinity *v1.Affinity `json:"affinity,omitempty"`
// NodeSelector is the calico-typha pod's scheduling constraints.
// If specified, each of the key/value pairs are added to the calico-typha Deployment nodeSelector provided
// the key does not already exist in the object's nodeSelector.
// If omitted, the calico-typha Deployment will use its default value for nodeSelector.
// WARNING: Please note that this field will modify the default calico-typha Deployment nodeSelector.
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request.
// Value must be non-negative integer. The value zero indicates stop immediately via
// the kill signal (no opportunity to shut down).
// If this value is nil, the default grace period will be used instead.
// The grace period is the duration in seconds after the processes running in the pod are sent
// a termination signal and the time when the processes are forcibly halted with a kill signal.
// Set this value longer than the expected cleanup time for your process.
// Defaults to 30 seconds.
// +optional
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
// TopologySpreadConstraints describes how a group of pods ought to spread across topology
// domains. Scheduler will schedule pods in a way which abides by the constraints.
// All topologySpreadConstraints are ANDed.
// +optional
TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
// Tolerations is the typha pod's tolerations.
// If specified, this overrides any tolerations that may be set on the typha Deployment.
// If omitted, the typha Deployment will use its default value for tolerations.
// WARNING: Please note that this field will override the default calico-typha Deployment tolerations.
// +optional
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
}
// TyphaDeploymentPodTemplateSpec is the typha Deployment's PodTemplateSpec
type TyphaDeploymentPodTemplateSpec struct {
// Metadata is a subset of a Kubernetes object's metadata that is added to
// the pod's metadata.
// +optional
Metadata *Metadata `json:"metadata,omitempty"`
// Spec is the typha Deployment's PodSpec.
// +optional
Spec *TyphaDeploymentPodSpec `json:"spec,omitempty"`
}
// TyphaDeployment is the configuration for the typha Deployment.
type TyphaDeployment struct {
// Metadata is a subset of a Kubernetes object's metadata that is added to the Deployment.
// +optional
Metadata *Metadata `json:"metadata,omitempty"`
// Spec is the specification of the typha Deployment.
// +optional
Spec *TyphaDeploymentSpec `json:"spec,omitempty"`
}
// TyphaDeploymentSpec defines configuration for the typha Deployment.
type TyphaDeploymentSpec struct {
// MinReadySeconds is the minimum number of seconds for which a newly created Deployment pod should
// be ready without any of its container crashing, for it to be considered available.
// If specified, this overrides any minReadySeconds value that may be set on the typha Deployment.
// If omitted, the typha Deployment will use its default value for minReadySeconds.
// +optional
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=2147483647
MinReadySeconds *int32 `json:"minReadySeconds,omitempty"`
// Template describes the typha Deployment pod that will be created.
// +optional
Template *TyphaDeploymentPodTemplateSpec `json:"template,omitempty"`
// The deployment strategy to use to replace existing pods with new ones.
// +optional
// +patchStrategy=retainKeys
Strategy *TyphaDeploymentStrategy `json:"strategy,omitempty" patchStrategy:"retainKeys" protobuf:"bytes,4,opt,name=strategy"`
}
// TyphaDeploymentStrategy describes how to replace existing pods with new ones. Only RollingUpdate is supported
// at this time so the Type field is not exposed.
type TyphaDeploymentStrategy struct {
// Rolling update config params. Present only if DeploymentStrategyType =
// RollingUpdate.
// to be.
// +optional
RollingUpdate *appsv1.RollingUpdateDeployment `json:"rollingUpdate,omitempty" protobuf:"bytes,2,opt,name=rollingUpdate"`
}
func (c *TyphaDeployment) GetMetadata() *Metadata {
return c.Metadata
}
func (c *TyphaDeployment) GetMinReadySeconds() *int32 {
if c.Spec != nil {
return c.Spec.MinReadySeconds
}
return nil
}
func (c *TyphaDeployment) GetPodTemplateMetadata() *Metadata {
if c.Spec != nil {
if c.Spec.Template != nil {
return c.Spec.Template.Metadata
}
}
return nil
}
func (c *TyphaDeployment) GetInitContainers() []v1.Container {
if c.Spec != nil {
if c.Spec.Template != nil {
if c.Spec.Template.Spec != nil {
if c.Spec.Template.Spec.InitContainers != nil {
cs := make([]v1.Container, len(c.Spec.Template.Spec.InitContainers))
for i, v := range c.Spec.Template.Spec.InitContainers {
// Only copy and return the init container if it has resources set.
if v.Resources == nil {
continue
}
c := v1.Container{Name: v.Name, Resources: *v.Resources}
cs[i] = c
}
return cs
}
}
}
}
return nil
}
func (c *TyphaDeployment) GetContainers() []v1.Container {
if c.Spec != nil {
if c.Spec.Template != nil {
if c.Spec.Template.Spec != nil {
if c.Spec.Template.Spec.Containers != nil {
cs := make([]v1.Container, len(c.Spec.Template.Spec.Containers))
for i, v := range c.Spec.Template.Spec.Containers {
// Only copy and return the container if it has resources set.
if v.Resources == nil {
continue
}
c := v1.Container{Name: v.Name, Resources: *v.Resources}
cs[i] = c
}
return cs
}
}
}
}
return nil
}
func (c *TyphaDeployment) GetAffinity() *v1.Affinity {
if c.Spec != nil {
if c.Spec.Template != nil {
if c.Spec.Template.Spec != nil {
return c.Spec.Template.Spec.Affinity
}
}
}
return nil
}
func (c *TyphaDeployment) GetTopologySpreadConstraints() []v1.TopologySpreadConstraint {
if c.Spec != nil {
if c.Spec.Template != nil {
if c.Spec.Template.Spec != nil {
return c.Spec.Template.Spec.TopologySpreadConstraints
}
}
}
return nil
}
func (c *TyphaDeployment) GetNodeSelector() map[string]string {
if c.Spec != nil {
if c.Spec.Template != nil {
if c.Spec.Template.Spec != nil {
return c.Spec.Template.Spec.NodeSelector
}
}
}
return nil
}
func (c *TyphaDeployment) GetTolerations() []v1.Toleration {
if c.Spec != nil {
if c.Spec.Template != nil {
if c.Spec.Template.Spec != nil {
return c.Spec.Template.Spec.Tolerations
}
}
}
return nil
}
func (c *TyphaDeployment) GetTerminationGracePeriodSeconds() *int64 {
if c.Spec != nil {
if c.Spec.Template != nil {
if c.Spec.Template.Spec != nil {
return c.Spec.Template.Spec.TerminationGracePeriodSeconds
}
}
}
return nil
}
func (c *TyphaDeployment) GetDeploymentStrategy() *appsv1.DeploymentStrategy {
if c.Spec != nil && c.Spec.Strategy != nil && c.Spec.Strategy.RollingUpdate != nil {
return &appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: c.Spec.Strategy.RollingUpdate,
}
}
return nil
}