Debian Codegraph @

ansible_collections/community/okd/plugins/connection/oc.py

raw
1 # Based on the docker connection plugin
2 #
3 # Connection plugin for configuring kubernetes containers with kubectl
4 # (c) 2017, XuXinkun <[email protected]>
5 #
6 # This file is part of Ansible
7 #
8 # Ansible is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Ansible is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
20 from __future__ import absolute_import, division, print_function
21
22 __metaclass__ = type
23
24 DOCUMENTATION = """
25 author:
26 - xuxinkun (@xuxinkun)
27
28 name: oc
29
30 short_description: Execute tasks in pods running on OpenShift.
31
32 description:
33 - Use the oc exec command to run tasks in, or put/fetch files to, pods running on the OpenShift
34 container platform.
35
36
37 requirements:
38 - oc (go binary)
39
40 options:
41 oc_pod:
42 description:
43 - Pod name. Required when the host name does not match pod name.
44 default: ''
45 vars:
46 - name: ansible_oc_pod
47 env:
48 - name: K8S_AUTH_POD
49 oc_container:
50 description:
51 - Container name. Required when a pod contains more than one container.
52 default: ''
53 vars:
54 - name: ansible_oc_container
55 env:
56 - name: K8S_AUTH_CONTAINER
57 oc_namespace:
58 description:
59 - The namespace of the pod
60 default: ''
61 vars:
62 - name: ansible_oc_namespace
63 env:
64 - name: K8S_AUTH_NAMESPACE
65 oc_extra_args:
66 description:
67 - Extra arguments to pass to the oc command line.
68 default: ''
69 vars:
70 - name: ansible_oc_extra_args
71 env:
72 - name: K8S_AUTH_EXTRA_ARGS
73 oc_kubeconfig:
74 description:
75 - Path to a oc config file. Defaults to I(~/.kube/config)
76 default: ''
77 vars:
78 - name: ansible_oc_kubeconfig
79 - name: ansible_oc_config
80 env:
81 - name: K8S_AUTH_KUBECONFIG
82 oc_context:
83 description:
84 - The name of a context found in the K8s config file.
85 default: ''
86 vars:
87 - name: ansible_oc_context
88 env:
89 - name: K8S_AUTH_CONTEXT
90 oc_host:
91 description:
92 - URL for accessing the API.
93 default: ''
94 vars:
95 - name: ansible_oc_host
96 - name: ansible_oc_server
97 env:
98 - name: K8S_AUTH_HOST
99 - name: K8S_AUTH_SERVER
100 oc_token:
101 description:
102 - API authentication bearer token.
103 vars:
104 - name: ansible_oc_token
105 - name: ansible_oc_api_key
106 env:
107 - name: K8S_AUTH_TOKEN
108 - name: K8S_AUTH_API_KEY
109 oc_local_env_vars:
110 description:
111 - Local environment variable to be passed locally to the oc command line.
112 - Please be aware that this passes information directly on the command line and it could expose sensitive data.
113 default: {}
114 type: dict
115 version_added: 4.0.0
116 vars:
117 - name: ansible_oc_local_env_vars
118 client_cert:
119 description:
120 - Path to a certificate used to authenticate with the API.
121 default: ''
122 vars:
123 - name: ansible_oc_cert_file
124 - name: ansible_oc_client_cert
125 env:
126 - name: K8S_AUTH_CERT_FILE
127 aliases: [ oc_cert_file ]
128 client_key:
129 description:
130 - Path to a key file used to authenticate with the API.
131 default: ''
132 vars:
133 - name: ansible_oc_key_file
134 - name: ansible_oc_client_key
135 env:
136 - name: K8S_AUTH_KEY_FILE
137 aliases: [ oc_key_file ]
138 ca_cert:
139 description:
140 - Path to a CA certificate used to authenticate with the API.
141 default: ''
142 vars:
143 - name: ansible_oc_ssl_ca_cert
144 - name: ansible_oc_ca_cert
145 env:
146 - name: K8S_AUTH_SSL_CA_CERT
147 aliases: [ oc_ssl_ca_cert ]
148 validate_certs:
149 description:
150 - Whether or not to verify the API server's SSL certificate. Defaults to I(true).
151 default: ''
152 vars:
153 - name: ansible_oc_verify_ssl
154 - name: ansible_oc_validate_certs
155 env:
156 - name: K8S_AUTH_VERIFY_SSL
157 aliases: [ oc_verify_ssl ]
158 """
159
160 from ansible_collections.kubernetes.core.plugins.connection.kubectl import (
161 Connection as KubectlConnection,
162 )
163
164
165 CONNECTION_TRANSPORT = "oc"
166
167 CONNECTION_OPTIONS = {
168 "oc_container": "-c",
169 "oc_namespace": "-n",
170 "oc_kubeconfig": "--kubeconfig",
171 "oc_context": "--context",
172 "oc_host": "--server",
173 "client_cert": "--client-certificate",
174 "client_key": "--client-key",
175 "ca_cert": "--certificate-authority",
176 "validate_certs": "--insecure-skip-tls-verify",
177 "oc_token": "--token",
178 }
179
180
181 class Connection(KubectlConnection):
182 """Local oc based connections"""
183
184 transport = CONNECTION_TRANSPORT
185 connection_options = CONNECTION_OPTIONS
186 documentation = DOCUMENTATION