This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathopenshift_v1_deployment_config.py
687 lines (675 loc) · 27 KB
/
openshift_v1_deployment_config.py
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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
#!/usr/bin/python
# -*- coding: utf-8 -*-
from ansible.module_utils.openshift_common import OpenShiftAnsibleModule, OpenShiftAnsibleException
DOCUMENTATION = '''
module: openshift_v1_deployment_config
short_description: OpenShift DeploymentConfig
description:
- Manage the lifecycle of a deployment_config object. Supports check mode, and attempts
to to be idempotent.
version_added: 2.3.0
author: OpenShift (@openshift)
options:
annotations:
description:
- Annotations is an unstructured key value map stored with a resource that may
be set by external tools to store and retrieve arbitrary metadata. They are
not queryable and should be preserved when modifying objects.
type: dict
api_key:
description:
- Token used to connect to the API.
cert_file:
description:
- Path to a certificate used to authenticate with the API.
type: path
context:
description:
- The name of a context found in the Kubernetes config file.
debug:
description:
- Enable debug output from the OpenShift helper. Logging info is written to KubeObjHelper.log
default: false
type: bool
force:
description:
- If set to C(True), and I(state) is C(present), an existing object will updated,
and lists will be replaced, rather than merged.
default: false
type: bool
host:
description:
- Provide a URL for acessing the Kubernetes API.
key_file:
description:
- Path to a key file used to authenticate with the API.
type: path
kubeconfig:
description:
- Path to an existing Kubernetes config file. If not provided, and no other connection
options are provided, the openshift client will attempt to load the default
configuration file from I(~/.kube/config.json).
type: path
labels:
description:
- Map of string keys and values that can be used to organize and categorize (scope
and select) objects. May match selectors of replication controllers and services.
type: dict
name:
description:
- Name must be unique within a namespace. Is required when creating resources,
although some resources may allow a client to request the generation of an appropriate
name automatically. Name is primarily intended for creation idempotence and
configuration definition. Cannot be updated.
namespace:
description:
- Namespace defines the space within each name must be unique. An empty namespace
is equivalent to the "default" namespace, but "default" is the canonical representation.
Not all objects are required to be scoped to a namespace - the value of this
field for those objects will be empty. Must be a DNS_LABEL. Cannot be updated.
password:
description:
- Provide a password for connecting to the API. Use in conjunction with I(username).
resource_definition:
description:
- Provide the YAML definition for the object, bypassing any modules parameters
intended to define object attributes.
type: dict
spec_min_ready_seconds:
description:
- MinReadySeconds is the minimum number of seconds for which a newly created pod
should be ready without any of its container crashing, for it to be considered
available. Defaults to 0 (pod will be considered available as soon as it is
ready)
aliases:
- min_ready_seconds
type: int
spec_paused:
description:
- Paused indicates that the deployment config is paused resulting in no new deployments
on template changes or changes in the template caused by other triggers.
aliases:
- paused
type: bool
spec_replicas:
description:
- Replicas is the number of desired replicas.
aliases:
- replicas
type: int
spec_revision_history_limit:
description:
- RevisionHistoryLimit is the number of old ReplicationControllers to retain to
allow for rollbacks. This field is a pointer to allow for differentiation between
an explicit zero and not specified. Defaults to 10. (This only applies to DeploymentConfigs
created via the new group API resource, not the legacy resource.)
aliases:
- revision_history_limit
type: int
spec_selector:
description:
- Selector is a label query over pods that should match the Replicas count.
aliases:
- selector
type: dict
spec_strategy_active_deadline_seconds:
description:
- ActiveDeadlineSeconds is the duration in seconds that the deployer pods for
this deployment config may be active on a node before the system actively tries
to terminate them.
aliases:
- strategy_active_deadline_seconds
type: int
spec_strategy_annotations:
description:
- Annotations is a set of key, value pairs added to custom deployer and lifecycle
pre/post hook pods.
aliases:
- strategy_annotations
type: dict
spec_strategy_custom_params:
description:
- When C(spec_strategy_type) is I(Custom), provide a mapping of 'key:value' settings.
aliases:
- strategy_custom_params
type: dict
spec_strategy_labels:
description:
- Labels is a set of key, value pairs added to custom deployer and lifecycle pre/post
hook pods.
aliases:
- strategy_labels
type: dict
spec_strategy_recreate_params:
description:
- When C(spec_strategy_type) is I(Recreate), provide a mapping of 'key:value'
settings.
aliases:
- strategy_recreate_params
type: dict
spec_strategy_resources_limits:
description:
- Limits describes the maximum amount of compute resources allowed.
aliases:
- strategy_resources_limits
type: dict
spec_strategy_resources_requests:
description:
- Requests describes the minimum amount of compute resources required. If Requests
is omitted for a container, it defaults to Limits if that is explicitly specified,
otherwise to an implementation-defined value.
aliases:
- strategy_resources_requests
type: dict
spec_strategy_rolling_params:
description:
- When C(spec_strategy_type) is I(Rolling), provide a mapping of 'key:value' settings.
aliases:
- strategy_rolling_params
type: dict
spec_strategy_type:
description:
- Type is the name of a deployment strategy.
choices:
- Rolling
- Custom
- Recreate
aliases:
- strategy_type
spec_template_metadata_annotations:
description:
- Annotations is an unstructured key value map stored with a resource that may
be set by external tools to store and retrieve arbitrary metadata. They are
not queryable and should be preserved when modifying objects.
type: dict
spec_template_metadata_labels:
description:
- Map of string keys and values that can be used to organize and categorize (scope
and select) objects. May match selectors of replication controllers and services.
type: dict
spec_template_metadata_name:
description:
- Name must be unique within a namespace. Is required when creating resources,
although some resources may allow a client to request the generation of an appropriate
name automatically. Name is primarily intended for creation idempotence and
configuration definition. Cannot be updated.
spec_template_metadata_namespace:
description:
- Namespace defines the space within each name must be unique. An empty namespace
is equivalent to the "default" namespace, but "default" is the canonical representation.
Not all objects are required to be scoped to a namespace - the value of this
field for those objects will be empty. Must be a DNS_LABEL. Cannot be updated.
spec_template_spec_active_deadline_seconds:
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.
aliases:
- active_deadline_seconds
type: int
spec_template_spec_affinity_node_affinity_preferred_during_scheduling_ignored_during_execution:
description:
- The scheduler will prefer to schedule pods to nodes that satisfy the affinity
expressions specified by this field, but it may choose a node that violates
one or more of the expressions. The node that is most preferred is the one with
the greatest sum of weights, i.e. for each node that meets all of the scheduling
requirements (resource request, requiredDuringScheduling affinity expressions,
etc.), compute a sum by iterating through the elements of this field and adding
"weight" to the sum if the node matches the corresponding matchExpressions;
the node(s) with the highest sum are the most preferred.
aliases:
- affinity_node_affinity_preferred_during_scheduling_ignored_during_execution
type: list
spec_template_spec_affinity_node_affinity_required_during_scheduling_ignored_during_execution_node_selector_terms:
description:
- Required. A list of node selector terms. The terms are ORed.
aliases:
- affinity_node_affinity_required_during_scheduling_ignored_during_execution_node_selector_terms
type: list
spec_template_spec_affinity_pod_affinity_preferred_during_scheduling_ignored_during_execution:
description:
- The scheduler will prefer to schedule pods to nodes that satisfy the affinity
expressions specified by this field, but it may choose a node that violates
one or more of the expressions. The node that is most preferred is the one with
the greatest sum of weights, i.e. for each node that meets all of the scheduling
requirements (resource request, requiredDuringScheduling affinity expressions,
etc.), compute a sum by iterating through the elements of this field and adding
"weight" to the sum if the node has pods which matches the corresponding podAffinityTerm;
the node(s) with the highest sum are the most preferred.
aliases:
- affinity_pod_affinity_preferred_during_scheduling_ignored_during_execution
type: list
spec_template_spec_affinity_pod_affinity_required_during_scheduling_ignored_during_execution:
description:
- If the affinity requirements specified by this field are not met at scheduling
time, the pod will not be scheduled onto the node. If the affinity requirements
specified by this field cease to be met at some point during pod execution (e.g.
due to a pod label update), the system may or may not try to eventually evict
the pod from its node. When there are multiple elements, the lists of nodes
corresponding to each podAffinityTerm are intersected, i.e. all terms must be
satisfied.
aliases:
- affinity_pod_affinity_required_during_scheduling_ignored_during_execution
type: list
spec_template_spec_affinity_pod_anti_affinity_preferred_during_scheduling_ignored_during_execution:
description:
- The scheduler will prefer to schedule pods to nodes that satisfy the anti-affinity
expressions specified by this field, but it may choose a node that violates
one or more of the expressions. The node that is most preferred is the one with
the greatest sum of weights, i.e. for each node that meets all of the scheduling
requirements (resource request, requiredDuringScheduling anti-affinity expressions,
etc.), compute a sum by iterating through the elements of this field and adding
"weight" to the sum if the node has pods which matches the corresponding podAffinityTerm;
the node(s) with the highest sum are the most preferred.
aliases:
- affinity_pod_anti_affinity_preferred_during_scheduling_ignored_during_execution
type: list
spec_template_spec_affinity_pod_anti_affinity_required_during_scheduling_ignored_during_execution:
description:
- If the anti-affinity requirements specified by this field are not met at scheduling
time, the pod will not be scheduled onto the node. If the anti-affinity requirements
specified by this field cease to be met at some point during pod execution (e.g.
due to a pod label update), the system may or may not try to eventually evict
the pod from its node. When there are multiple elements, the lists of nodes
corresponding to each podAffinityTerm are intersected, i.e. all terms must be
satisfied.
aliases:
- affinity_pod_anti_affinity_required_during_scheduling_ignored_during_execution
type: list
spec_template_spec_automount_service_account_token:
description:
- AutomountServiceAccountToken indicates whether a service account token should
be automatically mounted.
aliases:
- automount_service_account_token
type: bool
spec_template_spec_containers:
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.
aliases:
- containers
type: list
spec_template_spec_dns_policy:
description:
- Set DNS policy for containers within the pod. One of 'ClusterFirstWithHostNet',
'ClusterFirst' or 'Default'. Defaults to "ClusterFirst". To have DNS options
set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'.
aliases:
- dns_policy
spec_template_spec_host_aliases:
description:
- HostAliases is an optional list of hosts and IPs that will be injected into
the pod's hosts file if specified. This is only valid for non-hostNetwork pods.
aliases:
- host_aliases
type: list
spec_template_spec_host_ipc:
description:
- "Use the host's ipc namespace. Optional: Default to false."
aliases:
- host_ipc
type: bool
spec_template_spec_host_network:
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. Default to
false.
aliases:
- host_network
type: bool
spec_template_spec_host_pid:
description:
- "Use the host's pid namespace. Optional: Default to false."
aliases:
- host_pid
type: bool
spec_template_spec_hostname:
description:
- Specifies the hostname of the Pod If not specified, the pod's hostname will
be set to a system-defined value.
aliases:
- hostname
spec_template_spec_image_pull_secrets:
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.
aliases:
- image_pull_secrets
type: list
spec_template_spec_init_containers:
description:
- List of initialization containers belonging to the pod. Init containers are
executed in order prior to containers being started. If any init container fails,
the pod is considered to have failed and is handled according to its restartPolicy.
The name for an init container or normal container must be unique among all
containers. Init containers may not have Lifecycle actions, Readiness probes,
or Liveness probes. The resourceRequirements of an init container are taken
into account during scheduling by finding the highest request/limit for each
resource type, and then using the max of of that value or the sum of the normal
containers. Limits are applied to init containers in a similar fashion. Init
containers cannot currently be added or removed. Cannot be updated.
aliases:
- init_containers
type: list
spec_template_spec_node_name:
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.
aliases:
- node_name
spec_template_spec_node_selector:
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.
aliases:
- node_selector
type: dict
spec_template_spec_priority:
description:
- The priority value. Various system components use this field to find the priority
of the pod. When Priority Admission Controller is enabled, it prevents users
from setting this field. The admission controller populates this field from
PriorityClassName. The higher the value, the higher the priority.
aliases:
- priority
type: int
spec_template_spec_priority_class_name:
description:
- If specified, indicates the pod's priority. "SYSTEM" is a special keyword which
indicates the highest priority. Any other name must be defined by creating a
PriorityClass object with that name. If not specified, the pod priority will
be default or zero if there is no default.
aliases:
- priority_class_name
spec_template_spec_restart_policy:
description:
- Restart policy for all containers within the pod. One of Always, OnFailure,
Never. Default to Always.
aliases:
- restart_policy
spec_template_spec_scheduler_name:
description:
- If specified, the pod will be dispatched by specified scheduler. If not specified,
the pod will be dispatched by default scheduler.
aliases:
- scheduler_name
spec_template_spec_security_context_fs_group:
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."
aliases:
- security_context_fs_group
type: int
spec_template_spec_security_context_run_as_non_root:
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. If unset or false, no such validation
will be performed. May also be set in SecurityContext. If set in both SecurityContext
and PodSecurityContext, the value specified in SecurityContext takes precedence.
aliases:
- security_context_run_as_non_root
type: bool
spec_template_spec_security_context_run_as_user:
description:
- The UID to run the entrypoint of the container process. Defaults to user specified
in image metadata if unspecified. May also be set in SecurityContext. If set
in both SecurityContext and PodSecurityContext, the value specified in SecurityContext
takes precedence for that container.
aliases:
- security_context_run_as_user
type: int
spec_template_spec_security_context_se_linux_options_level:
description:
- Level is SELinux level label that applies to the container.
aliases:
- security_context_se_linux_options_level
spec_template_spec_security_context_se_linux_options_role:
description:
- Role is a SELinux role label that applies to the container.
aliases:
- security_context_se_linux_options_role
spec_template_spec_security_context_se_linux_options_type:
description:
- Type is a SELinux type label that applies to the container.
aliases:
- security_context_se_linux_options_type
spec_template_spec_security_context_se_linux_options_user:
description:
- User is a SELinux user label that applies to the container.
aliases:
- security_context_se_linux_options_user
spec_template_spec_security_context_supplemental_groups:
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.
aliases:
- security_context_supplemental_groups
type: list
spec_template_spec_service_account:
description:
- 'DeprecatedServiceAccount is a depreciated alias for ServiceAccountName. Deprecated:
Use serviceAccountName instead.'
aliases:
- service_account
spec_template_spec_service_account_name:
description:
- ServiceAccountName is the name of the ServiceAccount to use to run this pod.
aliases:
- service_account_name
spec_template_spec_subdomain:
description:
- If specified, the fully qualified Pod hostname will be "<hostname>.<subdomain>.<pod
namespace>.svc.<cluster domain>". If not specified, the pod will not have a
domainname at all.
aliases:
- subdomain
spec_template_spec_termination_grace_period_seconds:
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. Defaults to 30 seconds.
aliases:
- termination_grace_period_seconds
type: int
spec_template_spec_tolerations:
description:
- If specified, the pod's tolerations.
aliases:
- tolerations
type: list
spec_template_spec_volumes:
description:
- List of volumes that can be mounted by containers belonging to the pod.
aliases:
- volumes
type: list
spec_test:
description:
- Test ensures that this deployment config will have zero replicas except while
a deployment is running. This allows the deployment config to be used as a continuous
deployment test - triggering on images, running the deployment, and then succeeding
or failing. Post strategy hooks and After actions can be used to integrate successful
deployment with an action.
aliases:
- test
type: bool
spec_triggers:
description:
- Triggers determine how updates to a DeploymentConfig result in new deployments.
If no triggers are defined, a new deployment can only occur as a result of an
explicit client update to the DeploymentConfig with a new LatestVersion. If
null, defaults to having a config change trigger.
aliases:
- triggers
type: list
src:
description:
- Provide a path to a file containing the YAML definition of the object. Mutually
exclusive with I(resource_definition).
type: path
ssl_ca_cert:
description:
- Path to a CA certificate used to authenticate with the API.
type: path
state:
description:
- Determines if an object should be created, patched, or deleted. When set to
C(present), the object will be created, if it does not exist, or patched, if
parameter values differ from the existing object's attributes, and deleted,
if set to C(absent). A patch operation results in merging lists and updating
dictionaries, with lists being merged into a unique set of values. If a list
contains a dictionary with a I(name) or I(type) attribute, a strategic merge
is performed, where individual elements with a matching I(name_) or I(type)
are merged. To force the replacement of lists, set the I(force) option to C(True).
default: present
choices:
- present
- absent
username:
description:
- Provide a username for connecting to the API.
verify_ssl:
description:
- Whether or not to verify the API server's SSL certificates.
type: bool
requirements:
- openshift == 0.4.0.a1
'''
EXAMPLES = '''
- name: Create deployment config
openshift_v1_deployment_config.yml:
name: frontend
namespace: k8s-project
state: present
spec_template_metadata_labels:
name: frontend
containers:
- name: helloworld
image: openshift/origin-ruby-sample
ports:
- container_port: 8080
protocol: TCP
name: http-port
replicas: 5
selector:
name: frontend
triggers:
- type: ConfigChange
- type: ImageChange
image_change_params:
automatic: true
container_names:
- helloworld
_from:
kind: ImageStreamTag
name: origin-ruby-sample:latest
strategy_type: Rolling
- name: Patch deployment config
openshift_v1_deployment_config.yml:
name: frontend
namespace: k8s-project
state: present
spec_template_metadata_labels:
name: frontend
containers:
- name: helloworld
image: openshift/origin-ruby-sample:v1.0
ports:
- container_port: 9000
protocol: UDP
name: udp-port
replicas: 3
- name: Replace deployment config
openshift_v1_deployment_config.yml:
name: frontend
namespace: k8s-project
state: replaced
spec_template_metadata_labels:
name: frontend_app
containers:
- name: helloworld
image: openshift/origin-ruby-sample:v2
ports:
- container_port: 8888
protocol: TCP
name: http-port
replicas: 2
selector:
name: frontend_app
triggers:
- type: ConfigChange
- type: ImageChange
image_change_params:
automatic: true
container_names:
- helloworld
_from:
kind: ImageStreamTag
name: origin-ruby-sample:v2
strategy_type: Rolling
- name: Remove deployment config
openshift_v1_deployment_config.yml:
name: frontend
namespace: k8s-project
state: absent
'''
RETURN = '''
api_version:
description: Requested API version
type: string
deployment_config:
type: complex
returned: when I(state) = C(present)
contains:
api_version:
description:
- APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
type: str
kind:
description:
- Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to. Cannot
be updated. In CamelCase.
type: str
metadata:
description:
- Standard object's metadata.
type: complex
spec:
description:
- Spec represents a desired deployment state and how to deploy to it.
type: complex
status:
description:
- Status represents the current deployment state.
type: complex
'''
def main():
try:
module = OpenShiftAnsibleModule('deployment_config', 'v1')
except OpenShiftAnsibleException as exc:
# The helper failed to init, so there is no module object. All we can do is raise the error.
raise Exception(exc.message)
try:
module.execute_module()
except OpenShiftAnsibleException as exc:
module.fail_json(msg="Module failed!", error=str(exc))
if __name__ == '__main__':
main()