Skip to content

fix: add support for block 5k,15k in k8s pool and update_pool method #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 58 additions & 15 deletions plugins/modules/scaleway_k8s_pool.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
##################
# Waiting for scaleway merge fix https://github.com/scaleway/ansible/pull/47
##################


#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2023, Scaleway
Expand Down Expand Up @@ -25,7 +30,7 @@
state:
description:
- Indicate desired state of the target.
- C(present) will create the resource.
- C(present) will create the resource, or update if 'pool_id' is present
- C(absent) will delete the resource, if it exists.
default: present
choices: ["present", "absent"]
Expand Down Expand Up @@ -71,6 +76,8 @@
- default_volume_type
- l_ssd
- b_ssd
- sbs_5k
- sbs_15k
region:
description: region
type: str
Expand Down Expand Up @@ -116,6 +123,10 @@
description: root_volume_size
type: int
required: false
public_ip_disabled:
description: public_ip_disabled
type: bool
required: true
"""

EXAMPLES = r"""
Expand All @@ -130,6 +141,15 @@
container_runtime: "aaaaaa"
autohealing: true
root_volume_type: "aaaaaa"
public_ip_disabled: true

Check failure on line 145 in plugins/modules/scaleway_k8s_pool.py

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[trailing-spaces]

Trailing spaces
- name: Update a pool
scaleway.scaleway.scaleway_k8s_pool:
access_key: "{{ scw_access_key }}"
secret_key: "{{ scw_secret_key }}"
cluster_id: "aaaaaa"
pool_id: "my_pool"
size: 3
"""

RETURN = r"""
Expand Down Expand Up @@ -166,6 +186,7 @@
zone: "aaaaaa"
root_volume_type: default_volume_type
root_volume_size: 3
public_ip_disabled: true
region: fr-par
"""

Expand Down Expand Up @@ -193,14 +214,28 @@
def create(module: AnsibleModule, client: "Client") -> None:
api = K8SV1API(client)

id = module.params.pop("id", None)
obj = lambda: None
obj.stop = None
obj.timeout = 600
obj.min_delay = 1
obj.max_delay = 30

id = module.params["pool_id"]
if id is not None:
resource = api.get_pool(pool_id=id)
resource = api.get_pool(pool_id=id, region=module.params["region"])

if module.check_mode:
module.exit_json(changed=False)

module.exit_json(changed=False, data=resource)
not_none_params = {
key: value for key, value in module.params.items() if value is not None
}
not_none_params.pop("cluster_id")
resource = api.update_pool(**not_none_params)
resource = api.wait_for_pool(pool_id=resource.id, options=obj, region=module.params["region"])

del resource.upgrade_policy
module.exit_json(changed=True, data=vars(resource))

if module.check_mode:
module.exit_json(changed=True)
Expand All @@ -209,15 +244,16 @@
key: value for key, value in module.params.items() if value is not None
}
resource = api.create_pool(**not_none_params)
resource = api.wait_for_pool(pool_id=resource.id, region=module.params["region"])
resource = api.wait_for_pool(pool_id=resource.id, options=obj, region=module.params["region"])

module.exit_json(changed=True, data=resource.__dict__)
del resource.upgrade_policy
module.exit_json(changed=True, data=vars(resource))


def delete(module: AnsibleModule, client: "Client") -> None:
api = K8SV1API(client)

id = module.params.pop("id", None)
id = module.params.pop("pool_id", None)
name = module.params.pop("name", None)

if id is not None:
Expand Down Expand Up @@ -268,36 +304,36 @@
argument_spec.update(scaleway_waitable_resource_argument_spec())
argument_spec.update(
state=dict(type="str", default="present", choices=["absent", "present"]),
pool_id=dict(type="str"),
pool_id=dict(type="str", default=None),
cluster_id=dict(
type="str",
required=True,
),
node_type=dict(
type="str",
required=True,
required=False,
),
autoscaling=dict(
type="bool",
required=True,
required=False,
),
size=dict(
type="int",
required=True,
required=False,
),
container_runtime=dict(
type="str",
required=True,
required=False,
choices=["unknown_runtime", "docker", "containerd", "crio"],
),
autohealing=dict(
type="bool",
required=True,
required=False,
),
root_volume_type=dict(
type="str",
required=True,
choices=["default_volume_type", "l_ssd", "b_ssd"],
required=False,
choices=["default_volume_type", "l_ssd", "b_ssd", "sbs_5k", "sbs_15k"],
),
region=dict(
type="str",
Expand Down Expand Up @@ -341,11 +377,18 @@
type="int",
required=False,
),
public_ip_disabled=dict(
type="bool",
required=False,
),
)

module = AnsibleModule(
argument_spec=argument_spec,
required_one_of=(["pool_id", "name"],),
required_by={
'name': ('node_type','root_volume_type','autohealing','container_runtime','size','autoscaling','public_ip_disabled',),
},
supports_check_mode=True,
)

Expand Down
Loading