Bug fixes for gcp_container_cluster (#42829)

This commit is contained in:
Alex Stephen 2018-08-13 09:15:02 -07:00 committed by Ryan Brown
parent dd3c4b0d39
commit c38e1e5631
2 changed files with 64 additions and 78 deletions

View file

@ -44,7 +44,6 @@ options:
state:
description:
- Whether the given object should exist in GCP
required: true
choices: ['present', 'absent']
default: 'present'
name:
@ -91,9 +90,9 @@ options:
- The set of Google API scopes to be made available on all of the node VMs under the
"default" service account.
- '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.'
- 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).
- If unspecified, no scopes are added, unless Cloud Logging or Cloud Monitoring are
enabled, in which case their required scopes will be added.
@ -124,22 +123,20 @@ options:
required: false
labels:
description:
- 'The map of Kubernetes labels (key/value pairs) to be
applied to each node. These will added in addition to any
default label(s) that Kubernetes may apply to the node. In
case of conflict in label keys, the applied set may differ
depending on the Kubernetes version -- it''s best to assume
the behavior is undefined and conflicts should be avoided. For
more information, including usage and the valid values, see:
http://kubernetes.io/v1.1/docs/user-guide/labels.html An
object containing a list of "key": value pairs.'
- 'The map of Kubernetes labels (key/value pairs) to be applied to each node.
These will added in addition to any default label(s) that Kubernetes may apply to
the node. In case of conflict in label keys, the applied set may differ depending
on the Kubernetes version -- it''s best to assume the behavior is undefined and
conflicts should be avoided. For more information, including usage and the valid
values, see: U(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" }.'
required: false
local_ssd_count:
description:
- 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
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.'
required: false
tags:
@ -150,7 +147,7 @@ options:
required: false
preemptible:
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.'
required: false
type: bool
@ -261,20 +258,18 @@ extends_documentation_fragment: gcp
EXAMPLES = '''
- name: create a cluster
gcp_container_cluster:
name: testObject
name: "test_object"
initial_node_count: 2
master_auth:
username: "cluster_admin"
password: "my-secret-password"
username: cluster_admin
password: my-secret-password
node_config:
machine_type: "n1-standard-4"
machine_type: n1-standard-4
disk_size_gb: 500
zone: 'us-central1-a'
project: testProject
auth_kind: service_account
service_account_file: /tmp/auth.pem
scopes:
- https://www.googleapis.com/auth/cloud-platform
zone: us-central1-a
project: "test_project"
auth_kind: "service_account"
service_account_file: "/tmp/auth.pem"
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
"default" service account.
- '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.'
- 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).
- If unspecified, no scopes are added, unless Cloud Logging or Cloud Monitoring are
enabled, in which case their required scopes will be added.
@ -366,15 +361,13 @@ RETURN = '''
type: str
labels:
description:
- 'The map of Kubernetes labels (key/value pairs) to be
applied to each node. These will added in addition to any
default label(s) that Kubernetes may apply to the node. In
case of conflict in label keys, the applied set may differ
depending on the Kubernetes version -- it''s best to assume
the behavior is undefined and conflicts should be avoided. For
more information, including usage and the valid values, see:
http://kubernetes.io/v1.1/docs/user-guide/labels.html An
object containing a list of "key": value pairs.'
- 'The map of Kubernetes labels (key/value pairs) to be applied to each node.
These will added in addition to any default label(s) that Kubernetes may apply to
the node. In case of conflict in label keys, the applied set may differ depending
on the Kubernetes version -- it''s best to assume the behavior is undefined and
conflicts should be avoided. For more information, including usage and the valid
values, see: U(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" }.'
returned: success
type: dict
@ -382,7 +375,7 @@ RETURN = '''
description:
- 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
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.'
returned: success
type: int
@ -395,7 +388,7 @@ RETURN = '''
type: list
preemptible:
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.'
returned: success
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']
fetch = fetch_resource(module, self_link(module))
@ -636,10 +632,10 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
fetch = update(module, self_link(module), fetch)
fetch = update(module, self_link(module))
changed = True
else:
delete(module, self_link(module), fetch)
delete(module, self_link(module))
fetch = {}
changed = True
else:
@ -659,12 +655,12 @@ def create(module, link):
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')
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')
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):
op_result = return_if_object(module, response)
if op_result is None:
return None
return {}
status = navigate_hash(op_result, ['status'])
wait_done = wait_for_completion(status, op_result, module)
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']))
@ -900,18 +896,18 @@ class ClusterAddonsConfig(object):
def to_request(self):
return remove_nones_from_dict({
u'httpLoadBalancing': ClustHttpLoadBalan(self.request.get('http_load_balancing', {}), self.module).to_request(),
u'horizontalPodAutoscaling': ClustHorizPodAutos(self.request.get('horizontal_pod_autoscaling', {}), self.module).to_request()
u'httpLoadBalancing': ClusterHttpLoadBalancing(self.request.get('http_load_balancing', {}), self.module).to_request(),
u'horizontalPodAutoscaling': ClusterHorizontalPodAutoscaling(self.request.get('horizontal_pod_autoscaling', {}), self.module).to_request()
})
def from_response(self):
return remove_nones_from_dict({
u'httpLoadBalancing': ClustHttpLoadBalan(self.request.get(u'httpLoadBalancing', {}), self.module).from_response(),
u'horizontalPodAutoscaling': ClustHorizPodAutos(self.request.get(u'horizontalPodAutoscaling', {}), self.module).from_response()
u'httpLoadBalancing': ClusterHttpLoadBalancing(self.request.get(u'httpLoadBalancing', {}), 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):
self.module = module
if request:
@ -930,7 +926,7 @@ class ClustHttpLoadBalan(object):
})
class ClustHorizPodAutos(object):
class ClusterHorizontalPodAutoscaling(object):
def __init__(self, request, module):
self.module = module
if request:

View file

@ -18,17 +18,15 @@
name: "{{ resource_name }}"
initial_node_count: 2
master_auth:
username: "cluster_admin"
password: "my-secret-password"
username: cluster_admin
password: my-secret-password
node_config:
machine_type: "n1-standard-4"
machine_type: n1-standard-4
disk_size_gb: 500
zone: 'us-central1-a'
zone: us-central1-a
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/cloud-platform
state: absent
#----------------------------------------------------------
- name: create a cluster
@ -36,17 +34,15 @@
name: "{{ resource_name }}"
initial_node_count: 2
master_auth:
username: "cluster_admin"
password: "my-secret-password"
username: cluster_admin
password: my-secret-password
node_config:
machine_type: "n1-standard-4"
machine_type: n1-standard-4
disk_size_gb: 500
zone: 'us-central1-a'
zone: us-central1-a
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/cloud-platform
state: present
register: result
- name: assert changed is true
@ -67,17 +63,15 @@
name: "{{ resource_name }}"
initial_node_count: 2
master_auth:
username: "cluster_admin"
password: "my-secret-password"
username: cluster_admin
password: my-secret-password
node_config:
machine_type: "n1-standard-4"
machine_type: n1-standard-4
disk_size_gb: 500
zone: 'us-central1-a'
zone: us-central1-a
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/cloud-platform
state: present
register: result
- name: assert changed is false
@ -90,17 +84,15 @@
name: "{{ resource_name }}"
initial_node_count: 2
master_auth:
username: "cluster_admin"
password: "my-secret-password"
username: cluster_admin
password: my-secret-password
node_config:
machine_type: "n1-standard-4"
machine_type: n1-standard-4
disk_size_gb: 500
zone: 'us-central1-a'
zone: us-central1-a
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/cloud-platform
state: absent
register: result
- name: assert changed is true
@ -123,17 +115,15 @@
name: "{{ resource_name }}"
initial_node_count: 2
master_auth:
username: "cluster_admin"
password: "my-secret-password"
username: cluster_admin
password: my-secret-password
node_config:
machine_type: "n1-standard-4"
machine_type: n1-standard-4
disk_size_gb: 500
zone: 'us-central1-a'
zone: us-central1-a
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/cloud-platform
state: absent
register: result
- name: assert changed is false