diff --git a/changelogs/fragments/eks_nodegroup-integration-wait-delete.yml b/changelogs/fragments/eks_nodegroup-integration-wait-delete.yml new file mode 100644 index 00000000000..a88c08d73ef --- /dev/null +++ b/changelogs/fragments/eks_nodegroup-integration-wait-delete.yml @@ -0,0 +1,4 @@ +trivial: +- eks_nodegroup - update integration test to wait for both nodegroups to be deleted. +minor_changes: +- eks_nodegroup - ensure wait also waits for deletion to complete when ``wait==True`` (https://github.com/ansible-collections/community.aws/pull/1994). diff --git a/plugins/modules/eks_nodegroup.py b/plugins/modules/eks_nodegroup.py index f146328f098..51f74c22164 100644 --- a/plugins/modules/eks_nodegroup.py +++ b/plugins/modules/eks_nodegroup.py @@ -607,18 +607,29 @@ def delete_nodegroups(client, module): clusterName = module.params["cluster_name"] existing = get_nodegroup(client, module, name, clusterName) wait = module.params.get("wait") - if not existing or existing["status"] == "DELETING": - module.exit_json(changed=False, msg="Nodegroup not exists or in DELETING status.") - if not module.check_mode: - try: - client.delete_nodegroup(clusterName=clusterName, nodegroupName=name) - except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: - module.fail_json_aws(e, msg=f"Couldn't delete Nodegroup {name}.") + if not existing: + module.exit_json(changed=False, msg="Nodegroup '{name}' does not exist") + + if existing["status"] == "DELETING": if wait: wait_until(client, module, "nodegroup_deleted", name, clusterName) + module.exit_json(changed=False, msg="Nodegroup '{name}' deletion complete") + module.exit_json(changed=False, msg="Nodegroup '{name}' already in DELETING state") + + if module.check_mode: + module.exit_json(changed=True, msg="Nodegroup '{name}' deletion would be started (check mode)") + + try: + client.delete_nodegroup(clusterName=clusterName, nodegroupName=name) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, msg=f"Couldn't delete Nodegroup '{name}'.") + + if wait: + wait_until(client, module, "nodegroup_deleted", name, clusterName) + module.exit_json(changed=True, msg="Nodegroup '{name}' deletion complete") - module.exit_json(changed=True) + module.exit_json(changed=True, msg="Nodegroup '{name}' deletion started") def get_nodegroup(client, module, nodegroup_name, cluster_name): diff --git a/tests/integration/targets/eks_nodegroup/tasks/cleanup.yml b/tests/integration/targets/eks_nodegroup/tasks/cleanup.yml index 20db67c6c6a..8bdb5bad47e 100644 --- a/tests/integration/targets/eks_nodegroup/tasks/cleanup.yml +++ b/tests/integration/targets/eks_nodegroup/tasks/cleanup.yml @@ -74,10 +74,10 @@ state: absent vpc_id: '{{ setup_vpc.vpc.id}}' ignore_errors: 'yes' - + - name: remove setup VPC ec2_vpc_net: cidr_block: 10.0.0.0/16 state: absent name: '{{ resource_prefix }}_aws_eks' - ignore_errors: 'yes' \ No newline at end of file + ignore_errors: 'yes' diff --git a/tests/integration/targets/eks_nodegroup/tasks/dependecies.yml b/tests/integration/targets/eks_nodegroup/tasks/dependecies.yml index 7289930c96d..882d45dd7af 100644 --- a/tests/integration/targets/eks_nodegroup/tasks/dependecies.yml +++ b/tests/integration/targets/eks_nodegroup/tasks/dependecies.yml @@ -2,7 +2,7 @@ # This space was a copy by aws_eks_cluster integration test - name: ensure IAM instance role exists iam_role: - name: ansible-test-eks_cluster_role + name: ansible-test-{{ tiny_prefix }}-eks_nodegroup-cluster assume_role_policy_document: '{{ lookup(''file'',''eks-trust-policy.json'') }}' state: present create_instance_profile: 'no' @@ -44,7 +44,7 @@ community.aws.ec2_vpc_route_table: vpc_id: '{{ setup_vpc.vpc.id }}' tags: - Name: EKS + Name: "EKS-ng-{{ tiny_prefix }}" subnets: '{{ setup_subnets.results | map(attribute=''subnet.id'') }}' routes: - dest: 0.0.0.0/0 @@ -77,9 +77,9 @@ - eks_create.name == eks_cluster_name # Dependecies to eks nodegroup -- name: create IAM instance role +- name: create IAM instance role iam_role: - name: 'ansible-test-eks_nodegroup' + name: 'ansible-test-{{ tiny_prefix }}-eks_nodegroup-ng' assume_role_policy_document: '{{ lookup(''file'',''eks-nodegroup-trust-policy.json'') }}' state: present create_instance_profile: no diff --git a/tests/integration/targets/eks_nodegroup/tasks/full_test.yml b/tests/integration/targets/eks_nodegroup/tasks/full_test.yml index dcb35d2d1e9..9accc8e8f29 100644 --- a/tests/integration/targets/eks_nodegroup/tasks/full_test.yml +++ b/tests/integration/targets/eks_nodegroup/tasks/full_test.yml @@ -445,7 +445,6 @@ state: absent cluster_name: '{{ eks_cluster_name }}' register: eks_nodegroup_result - check_mode: True - name: check that eks_nodegroup is not changed (idempotency) assert: @@ -578,9 +577,21 @@ cluster_name: '{{ eks_cluster_name }}' wait: True register: eks_nodegroup_result - check_mode: True - name: check that eks_nodegroup is not changed (idempotency) assert: that: - - eks_nodegroup_result is not changed \ No newline at end of file + - eks_nodegroup_result is not changed + +- name: wait for deletion of name_a nodegroup (idempotency) + eks_nodegroup: + name: '{{ eks_nodegroup_name_a }}' + state: absent + cluster_name: '{{ eks_cluster_name }}' + wait: True + register: eks_nodegroup_result + +- name: check that eks_nodegroup is not changed (idempotency) + assert: + that: + - eks_nodegroup_result is not changed