|
|
|
@ -409,6 +409,20 @@ options:
|
|
|
|
|
aliases:
|
|
|
|
|
- zone
|
|
|
|
|
version_added: 2.8
|
|
|
|
|
kubectl_path:
|
|
|
|
|
description:
|
|
|
|
|
- The path that the kubectl config file will be written to.
|
|
|
|
|
- The file will not be created if this path is unset.
|
|
|
|
|
- Any existing file at this path will be completely overwritten.
|
|
|
|
|
- This requires the PyYaml library.
|
|
|
|
|
required: false
|
|
|
|
|
version_added: 2.9
|
|
|
|
|
kubectl_context:
|
|
|
|
|
description:
|
|
|
|
|
- The name of the context for the kubectl config file. Will default to the cluster
|
|
|
|
|
name.
|
|
|
|
|
required: false
|
|
|
|
|
version_added: 2.9
|
|
|
|
|
extends_documentation_fragment: gcp
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
@ -619,7 +633,7 @@ masterAuth:
|
|
|
|
|
description:
|
|
|
|
|
- The password to use for HTTP basic authentication to the master endpoint.
|
|
|
|
|
Because the master endpoint is open to the Internet, you should create a strong
|
|
|
|
|
password.
|
|
|
|
|
password with a minimum of 16 characters.
|
|
|
|
|
returned: success
|
|
|
|
|
type: str
|
|
|
|
|
clientCertificateConfig:
|
|
|
|
@ -924,6 +938,20 @@ location:
|
|
|
|
|
- The location where the cluster is deployed.
|
|
|
|
|
returned: success
|
|
|
|
|
type: str
|
|
|
|
|
kubectlPath:
|
|
|
|
|
description:
|
|
|
|
|
- The path that the kubectl config file will be written to.
|
|
|
|
|
- The file will not be created if this path is unset.
|
|
|
|
|
- Any existing file at this path will be completely overwritten.
|
|
|
|
|
- This requires the PyYaml library.
|
|
|
|
|
returned: success
|
|
|
|
|
type: str
|
|
|
|
|
kubectlContext:
|
|
|
|
|
description:
|
|
|
|
|
- The name of the context for the kubectl config file. Will default to the cluster
|
|
|
|
|
name.
|
|
|
|
|
returned: success
|
|
|
|
|
type: str
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
@ -1000,6 +1028,8 @@ def main():
|
|
|
|
|
enable_tpu=dict(type='bool'),
|
|
|
|
|
tpu_ipv4_cidr_block=dict(type='str'),
|
|
|
|
|
location=dict(required=True, type='str', aliases=['zone']),
|
|
|
|
|
kubectl_path=dict(type='str'),
|
|
|
|
|
kubectl_context=dict(type='str'),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -1029,6 +1059,8 @@ def main():
|
|
|
|
|
else:
|
|
|
|
|
fetch = {}
|
|
|
|
|
|
|
|
|
|
if module.params.get('kubectl_path'):
|
|
|
|
|
Kubectl(module).write_file()
|
|
|
|
|
fetch.update({'changed': changed})
|
|
|
|
|
|
|
|
|
|
module.exit_json(**fetch)
|
|
|
|
@ -1231,6 +1263,77 @@ def delete_default_node_pool(module):
|
|
|
|
|
return wait_for_operation(module, auth.delete(link))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Kubectl(object):
|
|
|
|
|
def __init__(self, module):
|
|
|
|
|
self.module = module
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
Writes a kubectl config file
|
|
|
|
|
kubectl_path must be set or this will fail.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def write_file(self):
|
|
|
|
|
try:
|
|
|
|
|
import yaml
|
|
|
|
|
except ImportError:
|
|
|
|
|
self.module.fail_json(msg="Please install the pyyaml module")
|
|
|
|
|
|
|
|
|
|
with open(self.module.params['kubectl_path'], 'w') as f:
|
|
|
|
|
f.write(yaml.dump(self._contents()))
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
Returns the contents of a kubectl file
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def _contents(self):
|
|
|
|
|
token = self._auth_token()
|
|
|
|
|
endpoint = "https://%s" % self.fetch["endpoint"]
|
|
|
|
|
context = self.module.params.get('kubectl_context')
|
|
|
|
|
if not context:
|
|
|
|
|
context = self.module.params['name']
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
'apiVersion': 'v1',
|
|
|
|
|
'clusters': [
|
|
|
|
|
{'name': context, 'cluster': {'certificate-authority-data': str(self.fetch['masterAuth']['clusterCaCertificate']), 'server': endpoint}}
|
|
|
|
|
],
|
|
|
|
|
'contexts': [{'name': context, 'context': {'cluster': context, 'user': context}}],
|
|
|
|
|
'current-context': context,
|
|
|
|
|
'kind': 'Config',
|
|
|
|
|
'preferences': {},
|
|
|
|
|
'users': [
|
|
|
|
|
{
|
|
|
|
|
'name': context,
|
|
|
|
|
'user': {
|
|
|
|
|
'auth-provider': {
|
|
|
|
|
'config': {
|
|
|
|
|
'access-token': token,
|
|
|
|
|
'cmd-args': 'config config-helper --format=json',
|
|
|
|
|
'cmd-path': '/usr/lib64/google-cloud-sdk/bin/gcloud',
|
|
|
|
|
'expiry-key': '{.credential.token_expiry}',
|
|
|
|
|
'token-key': '{.credential.access_token}',
|
|
|
|
|
},
|
|
|
|
|
'name': 'gcp',
|
|
|
|
|
},
|
|
|
|
|
'username': str(self.fetch['masterAuth']['username']),
|
|
|
|
|
'password': str(self.fetch['masterAuth']['password']),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
Returns the auth token used in kubectl
|
|
|
|
|
This also sets the 'fetch' variable used in creating the kubectl
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def _auth_token(self):
|
|
|
|
|
auth = GcpSession(self.module, 'auth')
|
|
|
|
|
response = auth.get(self_link(self.module))
|
|
|
|
|
self.fetch = response.json()
|
|
|
|
|
return response.request.headers['authorization'].split(' ')[1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClusterNodeconfig(object):
|
|
|
|
|
def __init__(self, request, module):
|
|
|
|
|
self.module = module
|
|
|
|
|