mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Bug fixes for gcp_container_cluster (#42829)
This commit is contained in:
parent
dd3c4b0d39
commit
c38e1e5631
2 changed files with 64 additions and 78 deletions
|
@ -44,7 +44,6 @@ options:
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Whether the given object should exist in GCP
|
- Whether the given object should exist in GCP
|
||||||
required: true
|
|
||||||
choices: ['present', 'absent']
|
choices: ['present', 'absent']
|
||||||
default: 'present'
|
default: 'present'
|
||||||
name:
|
name:
|
||||||
|
@ -91,9 +90,9 @@ options:
|
||||||
- The set of Google API scopes to be made available on all of the node VMs under the
|
- The set of Google API scopes to be made available on all of the node VMs under the
|
||||||
"default" service account.
|
"default" service account.
|
||||||
- 'The following scopes are recommended, but not required, and by default are not
|
- 'The following scopes are recommended, but not required, and by default are not
|
||||||
included: https://www.googleapis.com/auth/compute is required for mounting persistent
|
included: U(https://www.googleapis.com/auth/compute) is required for mounting persistent
|
||||||
storage on your nodes.'
|
storage on your nodes.'
|
||||||
- https://www.googleapis.com/auth/devstorage.read_only is required for communicating
|
- U(https://www.googleapis.com/auth/devstorage.read_only) is required for communicating
|
||||||
with gcr.io (the Google Container Registry).
|
with gcr.io (the Google Container Registry).
|
||||||
- If unspecified, no scopes are added, unless Cloud Logging or Cloud Monitoring are
|
- If unspecified, no scopes are added, unless Cloud Logging or Cloud Monitoring are
|
||||||
enabled, in which case their required scopes will be added.
|
enabled, in which case their required scopes will be added.
|
||||||
|
@ -124,22 +123,20 @@ options:
|
||||||
required: false
|
required: false
|
||||||
labels:
|
labels:
|
||||||
description:
|
description:
|
||||||
- 'The map of Kubernetes labels (key/value pairs) to be
|
- 'The map of Kubernetes labels (key/value pairs) to be applied to each node.
|
||||||
applied to each node. These will added in addition to any
|
These will added in addition to any default label(s) that Kubernetes may apply to
|
||||||
default label(s) that Kubernetes may apply to the node. In
|
the node. In case of conflict in label keys, the applied set may differ depending
|
||||||
case of conflict in label keys, the applied set may differ
|
on the Kubernetes version -- it''s best to assume the behavior is undefined and
|
||||||
depending on the Kubernetes version -- it''s best to assume
|
conflicts should be avoided. For more information, including usage and the valid
|
||||||
the behavior is undefined and conflicts should be avoided. For
|
values, see: U(http://kubernetes.io/v1.1/docs/user-guide/labels.html) An object
|
||||||
more information, including usage and the valid values, see:
|
containing a list of "key": value pairs.'
|
||||||
http://kubernetes.io/v1.1/docs/user-guide/labels.html An
|
|
||||||
object containing a list of "key": value pairs.'
|
|
||||||
- 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.'
|
- 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.'
|
||||||
required: false
|
required: false
|
||||||
local_ssd_count:
|
local_ssd_count:
|
||||||
description:
|
description:
|
||||||
- The number of local SSD disks to be attached to the node.
|
- The number of local SSD disks to be attached to the node.
|
||||||
- 'The limit for this value is dependant upon the maximum number of disks available
|
- 'The limit for this value is dependant upon the maximum number of disks available
|
||||||
on a machine per zone. See: https://cloud.google.com/compute/docs/disks/ local-ssd#local_ssd_limits for
|
on a machine per zone. See: U(https://cloud.google.com/compute/docs/disks/local-ssd#local_ssd_limits) for
|
||||||
more information.'
|
more information.'
|
||||||
required: false
|
required: false
|
||||||
tags:
|
tags:
|
||||||
|
@ -150,7 +147,7 @@ options:
|
||||||
required: false
|
required: false
|
||||||
preemptible:
|
preemptible:
|
||||||
description:
|
description:
|
||||||
- 'Whether the nodes are created as preemptible VM instances. See: https://cloud.google.com/compute/docs/instances/preemptible
|
- 'Whether the nodes are created as preemptible VM instances. See: U(https://cloud.google.com/compute/docs/instances/preemptible)
|
||||||
for more inforamtion about preemptible VM instances.'
|
for more inforamtion about preemptible VM instances.'
|
||||||
required: false
|
required: false
|
||||||
type: bool
|
type: bool
|
||||||
|
@ -261,20 +258,18 @@ extends_documentation_fragment: gcp
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
- name: create a cluster
|
- name: create a cluster
|
||||||
gcp_container_cluster:
|
gcp_container_cluster:
|
||||||
name: testObject
|
name: "test_object"
|
||||||
initial_node_count: 2
|
initial_node_count: 2
|
||||||
master_auth:
|
master_auth:
|
||||||
username: "cluster_admin"
|
username: cluster_admin
|
||||||
password: "my-secret-password"
|
password: my-secret-password
|
||||||
node_config:
|
node_config:
|
||||||
machine_type: "n1-standard-4"
|
machine_type: n1-standard-4
|
||||||
disk_size_gb: 500
|
disk_size_gb: 500
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
project: testProject
|
project: "test_project"
|
||||||
auth_kind: service_account
|
auth_kind: "service_account"
|
||||||
service_account_file: /tmp/auth.pem
|
service_account_file: "/tmp/auth.pem"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/cloud-platform
|
|
||||||
state: present
|
state: present
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -329,9 +324,9 @@ RETURN = '''
|
||||||
- The set of Google API scopes to be made available on all of the node VMs under the
|
- The set of Google API scopes to be made available on all of the node VMs under the
|
||||||
"default" service account.
|
"default" service account.
|
||||||
- 'The following scopes are recommended, but not required, and by default are not
|
- 'The following scopes are recommended, but not required, and by default are not
|
||||||
included: https://www.googleapis.com/auth/compute is required for mounting persistent
|
included: U(https://www.googleapis.com/auth/compute) is required for mounting persistent
|
||||||
storage on your nodes.'
|
storage on your nodes.'
|
||||||
- https://www.googleapis.com/auth/devstorage.read_only is required for communicating
|
- U(https://www.googleapis.com/auth/devstorage.read_only) is required for communicating
|
||||||
with gcr.io (the Google Container Registry).
|
with gcr.io (the Google Container Registry).
|
||||||
- If unspecified, no scopes are added, unless Cloud Logging or Cloud Monitoring are
|
- If unspecified, no scopes are added, unless Cloud Logging or Cloud Monitoring are
|
||||||
enabled, in which case their required scopes will be added.
|
enabled, in which case their required scopes will be added.
|
||||||
|
@ -366,15 +361,13 @@ RETURN = '''
|
||||||
type: str
|
type: str
|
||||||
labels:
|
labels:
|
||||||
description:
|
description:
|
||||||
- 'The map of Kubernetes labels (key/value pairs) to be
|
- 'The map of Kubernetes labels (key/value pairs) to be applied to each node.
|
||||||
applied to each node. These will added in addition to any
|
These will added in addition to any default label(s) that Kubernetes may apply to
|
||||||
default label(s) that Kubernetes may apply to the node. In
|
the node. In case of conflict in label keys, the applied set may differ depending
|
||||||
case of conflict in label keys, the applied set may differ
|
on the Kubernetes version -- it''s best to assume the behavior is undefined and
|
||||||
depending on the Kubernetes version -- it''s best to assume
|
conflicts should be avoided. For more information, including usage and the valid
|
||||||
the behavior is undefined and conflicts should be avoided. For
|
values, see: U(http://kubernetes.io/v1.1/docs/user-guide/labels.html) An object
|
||||||
more information, including usage and the valid values, see:
|
containing a list of "key": value pairs.'
|
||||||
http://kubernetes.io/v1.1/docs/user-guide/labels.html An
|
|
||||||
object containing a list of "key": value pairs.'
|
|
||||||
- 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.'
|
- 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.'
|
||||||
returned: success
|
returned: success
|
||||||
type: dict
|
type: dict
|
||||||
|
@ -382,7 +375,7 @@ RETURN = '''
|
||||||
description:
|
description:
|
||||||
- The number of local SSD disks to be attached to the node.
|
- The number of local SSD disks to be attached to the node.
|
||||||
- 'The limit for this value is dependant upon the maximum number of disks available
|
- 'The limit for this value is dependant upon the maximum number of disks available
|
||||||
on a machine per zone. See: https://cloud.google.com/compute/docs/disks/ local-ssd#local_ssd_limits for
|
on a machine per zone. See: U(https://cloud.google.com/compute/docs/disks/local-ssd#local_ssd_limits) for
|
||||||
more information.'
|
more information.'
|
||||||
returned: success
|
returned: success
|
||||||
type: int
|
type: int
|
||||||
|
@ -395,7 +388,7 @@ RETURN = '''
|
||||||
type: list
|
type: list
|
||||||
preemptible:
|
preemptible:
|
||||||
description:
|
description:
|
||||||
- 'Whether the nodes are created as preemptible VM instances. See: https://cloud.google.com/compute/docs/instances/preemptible
|
- 'Whether the nodes are created as preemptible VM instances. See: U(https://cloud.google.com/compute/docs/instances/preemptible)
|
||||||
for more inforamtion about preemptible VM instances.'
|
for more inforamtion about preemptible VM instances.'
|
||||||
returned: success
|
returned: success
|
||||||
type: bool
|
type: bool
|
||||||
|
@ -628,6 +621,9 @@ def main():
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not module.params['scopes']:
|
||||||
|
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
|
||||||
|
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
|
|
||||||
fetch = fetch_resource(module, self_link(module))
|
fetch = fetch_resource(module, self_link(module))
|
||||||
|
@ -636,10 +632,10 @@ def main():
|
||||||
if fetch:
|
if fetch:
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
if is_different(module, fetch):
|
if is_different(module, fetch):
|
||||||
fetch = update(module, self_link(module), fetch)
|
fetch = update(module, self_link(module))
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
delete(module, self_link(module), fetch)
|
delete(module, self_link(module))
|
||||||
fetch = {}
|
fetch = {}
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
|
@ -659,12 +655,12 @@ def create(module, link):
|
||||||
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
|
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
|
||||||
|
|
||||||
|
|
||||||
def update(module, link, fetch):
|
def update(module, link):
|
||||||
auth = GcpSession(module, 'container')
|
auth = GcpSession(module, 'container')
|
||||||
return wait_for_operation(module, auth.put(link, resource_to_request(module)))
|
return wait_for_operation(module, auth.put(link, resource_to_request(module)))
|
||||||
|
|
||||||
|
|
||||||
def delete(module, link, fetch):
|
def delete(module, link):
|
||||||
auth = GcpSession(module, 'container')
|
auth = GcpSession(module, 'container')
|
||||||
return wait_for_operation(module, auth.delete(link))
|
return wait_for_operation(module, auth.delete(link))
|
||||||
|
|
||||||
|
@ -785,7 +781,7 @@ def async_op_url(module, extra_data=None):
|
||||||
def wait_for_operation(module, response):
|
def wait_for_operation(module, response):
|
||||||
op_result = return_if_object(module, response)
|
op_result = return_if_object(module, response)
|
||||||
if op_result is None:
|
if op_result is None:
|
||||||
return None
|
return {}
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
wait_done = wait_for_completion(status, op_result, module)
|
wait_done = wait_for_completion(status, op_result, module)
|
||||||
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']))
|
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']))
|
||||||
|
@ -900,18 +896,18 @@ class ClusterAddonsConfig(object):
|
||||||
|
|
||||||
def to_request(self):
|
def to_request(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({
|
||||||
u'httpLoadBalancing': ClustHttpLoadBalan(self.request.get('http_load_balancing', {}), self.module).to_request(),
|
u'httpLoadBalancing': ClusterHttpLoadBalancing(self.request.get('http_load_balancing', {}), self.module).to_request(),
|
||||||
u'horizontalPodAutoscaling': ClustHorizPodAutos(self.request.get('horizontal_pod_autoscaling', {}), self.module).to_request()
|
u'horizontalPodAutoscaling': ClusterHorizontalPodAutoscaling(self.request.get('horizontal_pod_autoscaling', {}), self.module).to_request()
|
||||||
})
|
})
|
||||||
|
|
||||||
def from_response(self):
|
def from_response(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({
|
||||||
u'httpLoadBalancing': ClustHttpLoadBalan(self.request.get(u'httpLoadBalancing', {}), self.module).from_response(),
|
u'httpLoadBalancing': ClusterHttpLoadBalancing(self.request.get(u'httpLoadBalancing', {}), self.module).from_response(),
|
||||||
u'horizontalPodAutoscaling': ClustHorizPodAutos(self.request.get(u'horizontalPodAutoscaling', {}), self.module).from_response()
|
u'horizontalPodAutoscaling': ClusterHorizontalPodAutoscaling(self.request.get(u'horizontalPodAutoscaling', {}), self.module).from_response()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class ClustHttpLoadBalan(object):
|
class ClusterHttpLoadBalancing(object):
|
||||||
def __init__(self, request, module):
|
def __init__(self, request, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
if request:
|
if request:
|
||||||
|
@ -930,7 +926,7 @@ class ClustHttpLoadBalan(object):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class ClustHorizPodAutos(object):
|
class ClusterHorizontalPodAutoscaling(object):
|
||||||
def __init__(self, request, module):
|
def __init__(self, request, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
if request:
|
if request:
|
||||||
|
|
|
@ -18,17 +18,15 @@
|
||||||
name: "{{ resource_name }}"
|
name: "{{ resource_name }}"
|
||||||
initial_node_count: 2
|
initial_node_count: 2
|
||||||
master_auth:
|
master_auth:
|
||||||
username: "cluster_admin"
|
username: cluster_admin
|
||||||
password: "my-secret-password"
|
password: my-secret-password
|
||||||
node_config:
|
node_config:
|
||||||
machine_type: "n1-standard-4"
|
machine_type: n1-standard-4
|
||||||
disk_size_gb: 500
|
disk_size_gb: 500
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/cloud-platform
|
|
||||||
state: absent
|
state: absent
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
- name: create a cluster
|
- name: create a cluster
|
||||||
|
@ -36,17 +34,15 @@
|
||||||
name: "{{ resource_name }}"
|
name: "{{ resource_name }}"
|
||||||
initial_node_count: 2
|
initial_node_count: 2
|
||||||
master_auth:
|
master_auth:
|
||||||
username: "cluster_admin"
|
username: cluster_admin
|
||||||
password: "my-secret-password"
|
password: my-secret-password
|
||||||
node_config:
|
node_config:
|
||||||
machine_type: "n1-standard-4"
|
machine_type: n1-standard-4
|
||||||
disk_size_gb: 500
|
disk_size_gb: 500
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/cloud-platform
|
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: result
|
||||||
- name: assert changed is true
|
- name: assert changed is true
|
||||||
|
@ -67,17 +63,15 @@
|
||||||
name: "{{ resource_name }}"
|
name: "{{ resource_name }}"
|
||||||
initial_node_count: 2
|
initial_node_count: 2
|
||||||
master_auth:
|
master_auth:
|
||||||
username: "cluster_admin"
|
username: cluster_admin
|
||||||
password: "my-secret-password"
|
password: my-secret-password
|
||||||
node_config:
|
node_config:
|
||||||
machine_type: "n1-standard-4"
|
machine_type: n1-standard-4
|
||||||
disk_size_gb: 500
|
disk_size_gb: 500
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/cloud-platform
|
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: result
|
||||||
- name: assert changed is false
|
- name: assert changed is false
|
||||||
|
@ -90,17 +84,15 @@
|
||||||
name: "{{ resource_name }}"
|
name: "{{ resource_name }}"
|
||||||
initial_node_count: 2
|
initial_node_count: 2
|
||||||
master_auth:
|
master_auth:
|
||||||
username: "cluster_admin"
|
username: cluster_admin
|
||||||
password: "my-secret-password"
|
password: my-secret-password
|
||||||
node_config:
|
node_config:
|
||||||
machine_type: "n1-standard-4"
|
machine_type: n1-standard-4
|
||||||
disk_size_gb: 500
|
disk_size_gb: 500
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/cloud-platform
|
|
||||||
state: absent
|
state: absent
|
||||||
register: result
|
register: result
|
||||||
- name: assert changed is true
|
- name: assert changed is true
|
||||||
|
@ -123,17 +115,15 @@
|
||||||
name: "{{ resource_name }}"
|
name: "{{ resource_name }}"
|
||||||
initial_node_count: 2
|
initial_node_count: 2
|
||||||
master_auth:
|
master_auth:
|
||||||
username: "cluster_admin"
|
username: cluster_admin
|
||||||
password: "my-secret-password"
|
password: my-secret-password
|
||||||
node_config:
|
node_config:
|
||||||
machine_type: "n1-standard-4"
|
machine_type: n1-standard-4
|
||||||
disk_size_gb: 500
|
disk_size_gb: 500
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/cloud-platform
|
|
||||||
state: absent
|
state: absent
|
||||||
register: result
|
register: result
|
||||||
- name: assert changed is false
|
- name: assert changed is false
|
||||||
|
|
Loading…
Reference in a new issue