This repository has been archived by the owner on Feb 18, 2022. It is now read-only.
forked from hashicorp/terraform-provider-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema_pod_spec.go
438 lines (425 loc) · 19.2 KB
/
schema_pod_spec.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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
package kubernetes
import (
"github.com/hashicorp/terraform/helper/schema"
)
func podSpecFields(isUpdatable bool) map[string]*schema.Schema {
s := map[string]*schema.Schema{
"active_deadline_seconds": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validatePositiveInteger,
Description: "Optional duration in seconds the pod may be active on the node relative to StartTime before the system will actively try to mark it failed and kill associated containers. Value must be a positive integer.",
},
"container": {
Type: schema.TypeList,
Optional: true,
Description: "List of containers belonging to the pod. Containers cannot currently be added or removed. There must be at least one container in a Pod. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/containers",
Elem: &schema.Resource{
Schema: containerFields(isUpdatable, false),
},
},
"init_container": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: "List of init containers belonging to the pod. Init containers always run to completion and each must complete succesfully before the next is started. More info: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/",
Elem: &schema.Resource{
Schema: containerFields(isUpdatable, true),
},
},
"dns_policy": {
Type: schema.TypeString,
Optional: true,
Default: "ClusterFirst",
Description: "Set DNS policy for containers within the pod. One of 'ClusterFirst' or 'Default'. Defaults to 'ClusterFirst'.",
},
"host_ipc": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Use the host's ipc namespace. Optional: Default to false.",
},
"host_network": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Host networking requested for this pod. Use the host's network namespace. If this option is set, the ports that will be used must be specified.",
},
"host_pid": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Use the host's pid namespace.",
},
"hostname": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Specifies the hostname of the Pod If not specified, the pod's hostname will be set to a system-defined value.",
},
"image_pull_secrets": {
Type: schema.TypeList,
Description: "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: http://kubernetes.io/docs/user-guide/images#specifying-imagepullsecrets-on-a-pod",
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Description: "Name of the referent. More info: http://kubernetes.io/docs/user-guide/identifiers#names",
Required: true,
},
},
},
},
"node_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "NodeName is a request to schedule this pod onto a specific node. If it is non-empty, the scheduler simply schedules this pod onto that node, assuming that it fits resource requirements.",
},
"node_selector": {
Type: schema.TypeMap,
Optional: true,
Description: "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: http://kubernetes.io/docs/user-guide/node-selection.",
},
"restart_policy": {
Type: schema.TypeString,
Optional: true,
Default: "Always",
Description: "Restart policy for all containers within the pod. One of Always, OnFailure, Never. More info: http://kubernetes.io/docs/user-guide/pod-states#restartpolicy.",
},
"security_context": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "SecurityContext holds pod-level security attributes and common container settings. Optional: Defaults to empty",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"fs_group": {
Type: schema.TypeInt,
Description: "A special supplemental group that applies to all containers in a pod. Some volume types allow the Kubelet to change the ownership of that volume to be owned by the pod: 1. The owning GID will be the FSGroup 2. The setgid bit is set (new files created in the volume will be owned by FSGroup) 3. The permission bits are OR'd with rw-rw---- If unset, the Kubelet will not modify the ownership and permissions of any volume.",
Optional: true,
},
"run_as_non_root": {
Type: schema.TypeBool,
Description: "Indicates that the container must run as a non-root user. If true, the Kubelet will validate the image at runtime to ensure that it does not run as UID 0 (root) and fail to start the container if it does.",
Optional: true,
},
"run_as_user": {
Type: schema.TypeInt,
Description: "The UID to run the entrypoint of the container process. Defaults to user specified in image metadata if unspecified",
Optional: true,
},
"supplemental_groups": {
Type: schema.TypeSet,
Description: "A list of groups applied to the first process run in each container, in addition to the container's primary GID. If unspecified, no groups will be added to any container.",
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"se_linux_options": {
Type: schema.TypeList,
Description: "The SELinux context to be applied to all containers. If unspecified, the container runtime will allocate a random SELinux context for each container. May also be set in SecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence for that container.",
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: seLinuxOptionsField(),
},
},
},
},
},
"service_account_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "ServiceAccountName is the name of the ServiceAccount to use to run this pod. More info: http://releases.k8s.io/HEAD/docs/design/service_accounts.md.",
},
"subdomain": {
Type: schema.TypeString,
Optional: true,
Description: `If specified, the fully qualified Pod hostname will be "...svc.". If not specified, the pod will not have a domainname at all..`,
},
"termination_grace_period_seconds": {
Type: schema.TypeInt,
Optional: true,
Default: 30,
ValidateFunc: validateTerminationGracePeriodSeconds,
Description: "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 delete immediately. 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.",
},
"volume": {
Type: schema.TypeList,
Optional: true,
Description: "List of volumes that can be mounted by containers belonging to the pod. More info: http://kubernetes.io/docs/user-guide/volumes",
Elem: volumeSchema(),
},
}
if !isUpdatable {
for k, _ := range s {
if k == "active_deadline_seconds" {
// This field is always updatable
continue
}
if k == "container" {
// Some fields are always updatable
continue
}
s[k].ForceNew = true
}
}
return s
}
func volumeSchema() *schema.Resource {
v := commonVolumeSources()
v["config_map"] = &schema.Schema{
Type: schema.TypeList,
Description: "ConfigMap represents a configMap that should populate this volume",
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"items": {
Type: schema.TypeList,
Description: `If unspecified, each key-value pair in the Data field of the referenced ConfigMap will be projected into the volume as a file whose name is the key and content is the value. If specified, the listed keys will be projected into the specified paths, and unlisted keys will not be present. If a key is specified which is not present in the ConfigMap, the volume setup will error. Paths must be relative and may not contain the '..' path or start with '..'.`,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Optional: true,
Description: "The key to project.",
},
"mode": {
Type: schema.TypeInt,
Optional: true,
Description: `Optional: mode bits to use on this file, must be a value between 0 and 0777. If not specified, the volume defaultMode will be used. This might be in conflict with other options that affect the file mode, like fsGroup, and the result can be other mode bits set.`,
},
"path": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateAttributeValueDoesNotContain(".."),
Description: `The relative path of the file to map the key to. May not be an absolute path. May not contain the path element '..'. May not start with the string '..'.`,
},
},
},
},
"default_mode": {
Type: schema.TypeInt,
Description: "Optional: mode bits to use on created files by default. Must be a value between 0 and 0777. Defaults to 0644. Directories within the path are not affected by this setting. This might be in conflict with other options that affect the file mode, like fsGroup, and the result can be other mode bits set.",
Optional: true,
ValidateFunc: validateModeBits,
},
"name": {
Type: schema.TypeString,
Description: "Name of the referent. More info: http://kubernetes.io/docs/user-guide/identifiers#names",
Optional: true,
},
},
},
}
v["git_repo"] = &schema.Schema{
Type: schema.TypeList,
Description: "GitRepo represents a git repository at a particular revision.",
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"directory": {
Type: schema.TypeString,
Description: "Target directory name. Must not contain or start with '..'. If '.' is supplied, the volume directory will be the git repository. Otherwise, if specified, the volume will contain the git repository in the subdirectory with the given name.",
Optional: true,
ValidateFunc: validateAttributeValueDoesNotContain(".."),
},
"repository": {
Type: schema.TypeString,
Description: "Repository URL",
Optional: true,
},
"revision": {
Type: schema.TypeString,
Description: "Commit hash for the specified revision.",
Optional: true,
},
},
},
}
v["downward_api"] = &schema.Schema{
Type: schema.TypeList,
Description: "DownwardAPI represents downward API about the pod that should populate this volume",
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"default_mode": {
Type: schema.TypeInt,
Description: "Optional: mode bits to use on created files by default. Must be a value between 0 and 0777. Defaults to 0644. Directories within the path are not affected by this setting. This might be in conflict with other options that affect the file mode, like fsGroup, and the result can be other mode bits set.",
Optional: true,
},
"items": {
Type: schema.TypeList,
Description: `If unspecified, each key-value pair in the Data field of the referenced ConfigMap will be projected into the volume as a file whose name is the key and content is the value. If specified, the listed keys will be projected into the specified paths, and unlisted keys will not be present. If a key is specified which is not present in the ConfigMap, the volume setup will error. Paths must be relative and may not contain the '..' path or start with '..'.`,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"field_ref": {
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Description: "Required: Selects a field of the pod: only annotations, labels, name and namespace are supported.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"api_version": {
Type: schema.TypeString,
Optional: true,
Default: "v1",
Description: `Version of the schema the FieldPath is written in terms of, defaults to "v1".`,
},
"field_path": {
Type: schema.TypeString,
Optional: true,
Description: "Path of the field to select in the specified API version",
},
},
},
},
"mode": {
Type: schema.TypeInt,
Optional: true,
Description: `Optional: mode bits to use on this file, must be a value between 0 and 0777. If not specified, the volume defaultMode will be used. This might be in conflict with other options that affect the file mode, like fsGroup, and the result can be other mode bits set.`,
},
"path": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateAttributeValueDoesNotContain(".."),
Description: `Path is the relative path name of the file to be created. Must not be absolute or contain the '..' path. Must be utf-8 encoded. The first item of the relative path must not start with '..'`,
},
"resource_field_ref": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Selects a resource of the container: only resources limits and requests (limits.cpu, limits.memory, requests.cpu and requests.memory) are currently supported.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"container_name": {
Type: schema.TypeString,
Required: true,
},
"quantity": {
Type: schema.TypeString,
Optional: true,
},
"resource": {
Type: schema.TypeString,
Required: true,
Description: "Resource to select",
},
},
},
},
},
},
},
},
},
}
v["empty_dir"] = &schema.Schema{
Type: schema.TypeList,
Description: "EmptyDir represents a temporary directory that shares a pod's lifetime. More info: http://kubernetes.io/docs/user-guide/volumes#emptydir",
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"medium": {
Type: schema.TypeString,
Description: `What type of storage medium should back this directory. The default is "" which means to use the node's default medium. Must be an empty string (default) or Memory. More info: http://kubernetes.io/docs/user-guide/volumes#emptydir`,
Optional: true,
Default: "",
ValidateFunc: validateAttributeValueIsIn([]string{"", "Memory"}),
},
},
},
}
v["persistent_volume_claim"] = &schema.Schema{
Type: schema.TypeList,
Description: "The specification of a persistent volume.",
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"claim_name": {
Type: schema.TypeString,
Description: "ClaimName is the name of a PersistentVolumeClaim in the same ",
Optional: true,
},
"read_only": {
Type: schema.TypeBool,
Description: "Will force the ReadOnly setting in VolumeMounts.",
Optional: true,
Default: false,
},
},
},
}
v["secret"] = &schema.Schema{
Type: schema.TypeList,
Description: "Secret represents a secret that should populate this volume. More info: http://kubernetes.io/docs/user-guide/volumes#secrets",
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"default_mode": {
Type: schema.TypeInt,
Description: "Optional: mode bits to use on created files by default. Must be a value between 0 and 0777. Defaults to 0644. Directories within the path are not affected by this setting. This might be in conflict with other options that affect the file mode, like fsGroup, and the result can be other mode bits set.",
Optional: true,
Default: 0644,
ValidateFunc: validateModeBits,
},
"items": {
Type: schema.TypeList,
Description: "If unspecified, each key-value pair in the Data field of the referenced Secret will be projected into the volume as a file whose name is the key and content is the value. If specified, the listed keys will be projected into the specified paths, and unlisted keys will not be present. If a key is specified which is not present in the Secret, the volume setup will error unless it is marked optional. Paths must be relative and may not contain the '..' path or start with '..'.",
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Optional: true,
Description: "The key to project.",
},
"mode": {
Type: schema.TypeInt,
Optional: true,
Description: "Optional: mode bits to use on this file, must be a value between 0 and 0777. If not specified, the volume defaultMode will be used. This might be in conflict with other options that affect the file mode, like fsGroup, and the result can be other mode bits set.",
},
"path": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateAttributeValueDoesNotContain(".."),
Description: "The relative path of the file to map the key to. May not be an absolute path. May not contain the path element '..'. May not start with the string '..'.",
},
},
},
},
"optional": {
Type: schema.TypeBool,
Description: "Optional: Specify whether the Secret or it's keys must be defined.",
Optional: true,
},
"secret_name": {
Type: schema.TypeString,
Description: "Name of the secret in the pod's namespace to use. More info: http://kubernetes.io/docs/user-guide/volumes#secrets",
Optional: true,
},
},
},
}
v["name"] = &schema.Schema{
Type: schema.TypeString,
Description: "Volume's name. Must be a DNS_LABEL and unique within the pod. More info: http://kubernetes.io/docs/user-guide/identifiers#names",
Optional: true,
}
return &schema.Resource{
Schema: v,
}
}