Skip to content

Commit

Permalink
fix integration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
abikouo committed Mar 20, 2023
1 parent 982b66f commit da0baf2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 42 deletions.
79 changes: 39 additions & 40 deletions plugins/module_utils/k8s/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,48 +64,47 @@ def run_module(module) -> None:
name = module.params.get("name")
state = module.params.get("state")

if (
state == "absent"
and name is None
and resource_definition is None
and src is None
and select_all
):
# Delete all resources in the namespace for the specified resource type
if module.params.get("kind") is None:
raise CoreException(
"'kind' option is required to sepcify the resource type."
)
if select_all:
if (
state == "absent"
and name is None
and resource_definition is None
and src is None
):
# Delete all resources in the namespace for the specified resource type
if module.params.get("kind") is None:
raise CoreException(
"'kind' option is required to sepcify the resource type."
)

resource = svc.find_resource(
module.params.get("kind"), module.params.get("api_version"), fail=True
)
definitions = svc.retrieve_all(
resource,
module.params.get("namespace"),
module.params.get("label_selectors"),
)
elif (
state == "patched"
and select_all
and len(definitions) == 1
and definitions[0].get("metadata", {}).get("name") is None
):
kind = definitions[0].get("kind") or module.params.get("kind")
api_version = module.params.get("apiVersion") or definitions[0].get(
"api_version"
)
if kind is None:
raise CoreException(
"'kind' option is required to sepcify the resource type."
resource = svc.find_resource(
module.params.get("kind"), module.params.get("api_version"), fail=True
)
resource = svc.find_resource(kind, api_version, fail=True)
existing = svc.retrieve_all(
resource,
module.params.get("namespace"),
module.params.get("label_selectors"),
)
definitions = [dict_merge(d, definitions[0]) for d in existing]
definitions = svc.retrieve_all(
resource,
module.params.get("namespace"),
module.params.get("label_selectors"),
)
elif (
state == "patched"
and len(definitions) == 1
and definitions[0].get("metadata", {}).get("name") is None
):
kind = definitions[0].get("kind") or module.params.get("kind")
api_version = module.params.get("apiVersion") or definitions[0].get(
"api_version"
)
if kind is None:
raise CoreException(
"'kind' option is required to sepcify the resource type."
)
resource = svc.find_resource(kind, api_version, fail=True)
existing = svc.retrieve_all(
resource,
module.params.get("namespace"),
module.params.get("label_selectors"),
)
definitions = [dict_merge(d, definitions[0]) for d in existing]

for definition in definitions:
result = {"changed": False, "result": {}}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/targets/k8s_patched/meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dependencies:
- remove_namespace
dependencies: []
# - remove_namespace
2 changes: 2 additions & 0 deletions tests/integration/targets/k8s_patched/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
metadata:
labels:
patched: "true"
select_all: true
register: _patch

- name: Ensure task is changed
Expand Down Expand Up @@ -258,6 +259,7 @@
kind: Namespace
name: "{{ item }}"
state: absent
wait: yes
with_items:
- "{{ patch_only_namespace[0] }}"
- "{{ patch_only_namespace[1] }}"
Expand Down

0 comments on commit da0baf2

Please sign in to comment.