diff --git a/docs/modules/lke_cluster.md b/docs/modules/lke_cluster.md index c472f6cca..cf84cf044 100644 --- a/docs/modules/lke_cluster.md +++ b/docs/modules/lke_cluster.md @@ -89,6 +89,7 @@ Manage Linode LKE clusters. |-----------|------|----------|------------------------------------------------------------------------------| | `count` |
`int`
|
**Required**
| The number of nodes in the Node Pool. **(Updatable)** | | `type` |
`str`
|
**Required**
| The Linode Type for all of the nodes in the Node Pool. | +| `label` |
`str`
|
Optional
| A unique label for this Node Pool. **(Updatable)** | | [`autoscaler` (sub-options)](#autoscaler) |
`dict`
|
Optional
| When enabled, the number of nodes autoscales within the defined minimum and maximum values. **(Updatable)** | | `labels` |
`dict`
|
Optional
| Key-value pairs added as labels to nodes in the node pool. Labels help classify your nodes and to easily select subsets of objects. **(Updatable)** | | [`taints` (sub-options)](#taints) |
`list`
|
Optional
| Kubernetes taints to add to node pool nodes. Taints help control how pods are scheduled onto nodes, specifically allowing them to repel certain pods. **(Updatable)** | diff --git a/docs/modules/lke_node_pool.md b/docs/modules/lke_node_pool.md index 18787a4f4..a24df30d2 100644 --- a/docs/modules/lke_node_pool.md +++ b/docs/modules/lke_node_pool.md @@ -57,6 +57,7 @@ Manage Linode LKE cluster node pools. | `state` |
`str`
|
**Required**
| The desired state of the target. **(Choices: `present`, `absent`)** | | [`autoscaler` (sub-options)](#autoscaler) |
`dict`
|
Optional
| When enabled, the number of nodes autoscales within the defined minimum and maximum values. **(Updatable)** | | `count` |
`int`
|
Optional
| The number of nodes in the Node Pool. **(Updatable)** | +| `label` |
`str`
|
Optional
| A unique label for this Node Pool. **(Updatable)** | | [`disks` (sub-options)](#disks) |
`list`
|
Optional
| This Node Pool’s custom disk layout. Each item in this array will create a new disk partition for each node in this Node Pool. | | `type` |
`str`
|
Optional
| The Linode Type for all of the nodes in the Node Pool. Required if `state` == `present`. | | `skip_polling` |
`bool`
|
Optional
| If true, the module will not wait for all nodes in the node pool to be ready. **(Default: `False`)** | diff --git a/plugins/inventory/instance.py b/plugins/inventory/instance.py index ba47a1b2a..404c40637 100644 --- a/plugins/inventory/instance.py +++ b/plugins/inventory/instance.py @@ -97,6 +97,7 @@ HAS_LINODE = False +# pylint: disable=too-many-ancestors class InventoryModule(BaseInventoryPlugin, Constructable): """Linode instance inventory plugin""" diff --git a/plugins/modules/lke_cluster.py b/plugins/modules/lke_cluster.py index 518f62c5b..534123af5 100644 --- a/plugins/modules/lke_cluster.py +++ b/plugins/modules/lke_cluster.py @@ -134,6 +134,12 @@ } linode_lke_cluster_node_pool_spec = { + "label": SpecField( + type=FieldType.string, + editable=True, + description=["A unique label for this Node Pool."], + required=False, + ), "count": SpecField( type=FieldType.integer, editable=True, @@ -567,6 +573,16 @@ def _update_cluster(self, cluster: LKECluster) -> None: current_pool.labels = pool.get("labels") current_pool.save() + if "label" in pool and current_pool.label != pool["label"]: + self.register_action( + "Updated label for Node Pool {}".format( + current_pool.id + ) + ) + + current_pool.label = pool.get("label") + current_pool.save() + pools_handled[k] = True should_keep[i] = True break @@ -635,6 +651,16 @@ def _update_cluster(self, cluster: LKECluster) -> None: existing_pool.labels = pool["labels"] should_update = True + if "label" in pool and existing_pool.label != pool["label"]: + self.register_action( + "Updated label for Node Pool {}".format( + existing_pool.id + ) + ) + + existing_pool.label = pool["label"] + should_update = True + if should_update: existing_pool.save() diff --git a/plugins/modules/lke_node_pool.py b/plugins/modules/lke_node_pool.py index 910acd947..4a063465b 100644 --- a/plugins/modules/lke_node_pool.py +++ b/plugins/modules/lke_node_pool.py @@ -111,6 +111,12 @@ editable=True, description=["The number of nodes in the Node Pool."], ), + "label": SpecField( + type=FieldType.string, + editable=True, + description=["A unique label for this Node Pool."], + required=False, + ), "disks": SpecField( type=FieldType.list, element_type=FieldType.dict, @@ -319,6 +325,7 @@ def _update_pool(self, pool: LKENodePool) -> LKENodePool: new_count = params.pop("count") new_taints = params.pop("taints") if "taints" in params else None new_labels = params.pop("labels") if "labels" in params else None + new_label = params.pop("label") if "label" in params else None new_k8s_version = ( params.pop("k8s_version") if "k8s_version" in params else None ) @@ -362,6 +369,11 @@ def _update_pool(self, pool: LKENodePool) -> LKENodePool: pool.labels = new_labels should_update = True + if new_label is not None and pool.label != new_label: + self.register_action("Updated label for Node Pool") + pool.label = new_label + should_update = True + if new_k8s_version is not None and pool.k8s_version != new_k8s_version: self.register_action("Updated k8s version for Node Pool") pool.k8s_version = new_k8s_version diff --git a/requirements.txt b/requirements.txt index 15f37cedb..df97a767c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -linode-api4>=5.34.0 +linode-api4>=5.35.0 polling==0.3.2 ansible-specdoc>=0.0.19 diff --git a/tests/integration/targets/lke_cluster_basic/tasks/main.yaml b/tests/integration/targets/lke_cluster_basic/tasks/main.yaml index 496694539..79d783684 100644 --- a/tests/integration/targets/lke_cluster_basic/tasks/main.yaml +++ b/tests/integration/targets/lke_cluster_basic/tasks/main.yaml @@ -40,6 +40,7 @@ effect: NoExecute - type: g6-standard-4 count: 1 + label: pool-with-autoscaler autoscaler: enabled: true min: 1 @@ -55,6 +56,7 @@ - create_cluster.cluster.region == 'us-southeast' - create_cluster.node_pools[0].type == 'g6-standard-1' - create_cluster.node_pools[0].count == 3 + - create_cluster.node_pools[1].label == 'pool-with-autoscaler' - create_cluster.node_pools[0].labels['foo.example.com/test'] == 'bar' - create_cluster.node_pools[0].labels['foo.example.com/test2'] == 'foo' - create_cluster.node_pools[0].taints[0].key == 'foo.example.com/test2' @@ -73,6 +75,7 @@ node_pools: - type: g6-standard-1 count: 2 + label: updated-pool-label labels: foo.example.com/update: updated foo.example.com/test2: foo @@ -97,6 +100,7 @@ - update_pools.node_pools[0].type == 'g6-standard-1' - update_pools.node_pools[0].count == 2 + - update_pools.node_pools[0].label == 'updated-pool-label' - update_pools.node_pools[0].id == create_cluster.node_pools[0].id - update_pools.node_pools[0].labels['foo.example.com/update'] == 'updated' diff --git a/tests/integration/targets/lke_node_pool_basic/tasks/main.yaml b/tests/integration/targets/lke_node_pool_basic/tasks/main.yaml index f6f32da1a..2c25cbd2c 100644 --- a/tests/integration/targets/lke_node_pool_basic/tasks/main.yaml +++ b/tests/integration/targets/lke_node_pool_basic/tasks/main.yaml @@ -44,6 +44,7 @@ tags: ['my-pool'] type: g6-standard-1 count: 2 + label: new-pool-label labels: foo.example.com/test: bar foo.example.com/test2: foo @@ -58,6 +59,7 @@ assert: that: - new_pool.node_pool.count == 2 + - new_pool.node_pool.label == 'new-pool-label' - new_pool.node_pool.type == 'g6-standard-1' - new_pool.node_pool.nodes[0].status == 'ready' - new_pool.node_pool.nodes[1].status == 'ready' @@ -86,6 +88,7 @@ type: g6-standard-1 count: 1 skip_polling: true + label: updated-pool-label autoscaler: enabled: true min: 1 @@ -104,6 +107,7 @@ assert: that: - update_pool.node_pool.count == 1 + - update_pool.node_pool.label == 'updated-pool-label' - update_pool.node_pool.type == 'g6-standard-1' - update_pool.node_pool.autoscaler.enabled - update_pool.node_pool.autoscaler.min == 1