Bug fixes for gcp_container_node_pool (#42830)
This commit is contained in:
parent
7f981b4123
commit
7f10d432ec
2 changed files with 77 additions and 64 deletions
|
@ -107,15 +107,13 @@ 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:
|
||||
U(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:
|
||||
|
@ -199,7 +197,7 @@ options:
|
|||
required: false
|
||||
cluster:
|
||||
description:
|
||||
- A reference to Cluster resource.
|
||||
- The cluster this node pool belongs to.
|
||||
required: true
|
||||
zone:
|
||||
description:
|
||||
|
@ -211,28 +209,24 @@ extends_documentation_fragment: gcp
|
|||
EXAMPLES = '''
|
||||
- name: create a cluster
|
||||
gcp_container_cluster:
|
||||
name: 'cluster-nodepool'
|
||||
name: "cluster-nodepool"
|
||||
initial_node_count: 4
|
||||
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: cluster
|
||||
|
||||
- name: create a node pool
|
||||
gcp_container_node_pool:
|
||||
name: testObject
|
||||
name: "test_object"
|
||||
initial_node_count: 4
|
||||
cluster: "{{ cluster }}"
|
||||
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
|
||||
'''
|
||||
|
||||
|
@ -302,15 +296,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:
|
||||
U(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
|
||||
|
@ -410,7 +402,7 @@ RETURN = '''
|
|||
type: str
|
||||
cluster:
|
||||
description:
|
||||
- A reference to Cluster resource.
|
||||
- The cluster this node pool belongs to.
|
||||
returned: success
|
||||
type: dict
|
||||
zone:
|
||||
|
@ -471,6 +463,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))
|
||||
|
@ -517,8 +512,8 @@ def resource_to_request(module):
|
|||
u'name': module.params.get('name'),
|
||||
u'config': NodePoolConfig(module.params.get('config', {}), module).to_request(),
|
||||
u'initialNodeCount': module.params.get('initial_node_count'),
|
||||
u'autoscaling': NodePoolAutosca(module.params.get('autoscaling', {}), module).to_request(),
|
||||
u'management': NodePoolManagem(module.params.get('management', {}), module).to_request()
|
||||
u'autoscaling': NodePoolAutoscaling(module.params.get('autoscaling', {}), module).to_request(),
|
||||
u'management': NodePoolManagement(module.params.get('management', {}), module).to_request()
|
||||
}
|
||||
request = encode_request(request, module)
|
||||
return_vals = {}
|
||||
|
@ -600,8 +595,8 @@ def response_to_hash(module, response):
|
|||
u'config': NodePoolConfig(response.get(u'config', {}), module).from_response(),
|
||||
u'initialNodeCount': module.params.get('initial_node_count'),
|
||||
u'version': response.get(u'version'),
|
||||
u'autoscaling': NodePoolAutosca(response.get(u'autoscaling', {}), module).from_response(),
|
||||
u'management': NodePoolManagem(response.get(u'management', {}), module).from_response()
|
||||
u'autoscaling': NodePoolAutoscaling(response.get(u'autoscaling', {}), module).from_response(),
|
||||
u'management': NodePoolManagement(response.get(u'management', {}), module).from_response()
|
||||
}
|
||||
|
||||
|
||||
|
@ -617,7 +612,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']))
|
||||
|
@ -695,7 +690,7 @@ class NodePoolConfig(object):
|
|||
})
|
||||
|
||||
|
||||
class NodePoolAutosca(object):
|
||||
class NodePoolAutoscaling(object):
|
||||
def __init__(self, request, module):
|
||||
self.module = module
|
||||
if request:
|
||||
|
@ -718,7 +713,7 @@ class NodePoolAutosca(object):
|
|||
})
|
||||
|
||||
|
||||
class NodePoolManagem(object):
|
||||
class NodePoolManagement(object):
|
||||
def __init__(self, request, module):
|
||||
self.module = module
|
||||
if request:
|
||||
|
@ -730,18 +725,18 @@ class NodePoolManagem(object):
|
|||
return remove_nones_from_dict({
|
||||
u'autoUpgrade': self.request.get('auto_upgrade'),
|
||||
u'autoRepair': self.request.get('auto_repair'),
|
||||
u'upgradeOptions': NodePoolUpgraOptio(self.request.get('upgrade_options', {}), self.module).to_request()
|
||||
u'upgradeOptions': NodePoolUpgradeOptions(self.request.get('upgrade_options', {}), self.module).to_request()
|
||||
})
|
||||
|
||||
def from_response(self):
|
||||
return remove_nones_from_dict({
|
||||
u'autoUpgrade': self.request.get(u'autoUpgrade'),
|
||||
u'autoRepair': self.request.get(u'autoRepair'),
|
||||
u'upgradeOptions': NodePoolUpgraOptio(self.request.get(u'upgradeOptions', {}), self.module).from_response()
|
||||
u'upgradeOptions': NodePoolUpgradeOptions(self.request.get(u'upgradeOptions', {}), self.module).from_response()
|
||||
})
|
||||
|
||||
|
||||
class NodePoolUpgraOptio(object):
|
||||
class NodePoolUpgradeOptions(object):
|
||||
def __init__(self, request, module):
|
||||
self.module = module
|
||||
if request:
|
||||
|
|
|
@ -15,14 +15,12 @@
|
|||
# Pre-test setup
|
||||
- name: create a cluster
|
||||
gcp_container_cluster:
|
||||
name: 'cluster-nodepool'
|
||||
name: "cluster-nodepool"
|
||||
initial_node_count: 4
|
||||
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: cluster
|
||||
- name: delete a node pool
|
||||
|
@ -30,12 +28,10 @@
|
|||
name: "{{ resource_name }}"
|
||||
initial_node_count: 4
|
||||
cluster: "{{ cluster }}"
|
||||
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 node pool
|
||||
|
@ -43,30 +39,42 @@
|
|||
name: "{{ resource_name }}"
|
||||
initial_node_count: 4
|
||||
cluster: "{{ cluster }}"
|
||||
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
|
||||
assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- name: verify that node_pool was created
|
||||
gcp_container_node_pool_facts:
|
||||
filters:
|
||||
- name = {{ resource_name }}
|
||||
cluster: {{ cluster }}
|
||||
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
|
||||
register: results
|
||||
- name: verify that command succeeded
|
||||
assert:
|
||||
that:
|
||||
- results['items'] | length == 1
|
||||
# ----------------------------------------------------------------------------
|
||||
- name: create a node pool that already exists
|
||||
gcp_container_node_pool:
|
||||
name: "{{ resource_name }}"
|
||||
initial_node_count: 4
|
||||
cluster: "{{ cluster }}"
|
||||
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
|
||||
|
@ -79,30 +87,42 @@
|
|||
name: "{{ resource_name }}"
|
||||
initial_node_count: 4
|
||||
cluster: "{{ cluster }}"
|
||||
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
|
||||
assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- name: verify that node_pool was deleted
|
||||
gcp_container_node_pool_facts:
|
||||
filters:
|
||||
- name = {{ resource_name }}
|
||||
cluster: {{ cluster }}
|
||||
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
|
||||
register: results
|
||||
- name: verify that command succeeded
|
||||
assert:
|
||||
that:
|
||||
- results['items'] | length == 0
|
||||
# ----------------------------------------------------------------------------
|
||||
- name: delete a node pool that does not exist
|
||||
gcp_container_node_pool:
|
||||
name: "{{ resource_name }}"
|
||||
initial_node_count: 4
|
||||
cluster: "{{ cluster }}"
|
||||
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
|
||||
|
@ -113,13 +133,11 @@
|
|||
# Post-test teardown
|
||||
- name: delete a cluster
|
||||
gcp_container_cluster:
|
||||
name: 'cluster-nodepool'
|
||||
name: "cluster-nodepool"
|
||||
initial_node_count: 4
|
||||
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: cluster
|
||||
|
|
Loading…
Reference in a new issue