From bd3950e21be26e88c65a41a4a35cee81e7403ab3 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Tue, 29 Oct 2024 16:16:37 +0000 Subject: [PATCH 01/28] add support of local environ for kustomize lookup plugin --- docs/kubernetes.core.kustomize_lookup.rst | 30 +++++++++++++++++++++++ plugins/lookup/kustomize.py | 22 +++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/docs/kubernetes.core.kustomize_lookup.rst b/docs/kubernetes.core.kustomize_lookup.rst index 423e8aaff6..708d44939a 100644 --- a/docs/kubernetes.core.kustomize_lookup.rst +++ b/docs/kubernetes.core.kustomize_lookup.rst @@ -112,6 +112,29 @@ Parameters
An optional list of directories to search for the executable in addition to PATH.
+ + +
+ use_local_env + +
+ boolean +
+
added in 3.3.0
+ + + + Default:
"False"
+ + + + +
Use the local environment varaible for the command execution
+ +
@@ -145,6 +168,13 @@ Examples kubernetes.core.k8s: definition: "{{ lookup('kubernetes.core.kustomize', dir='/path/to/kustomization', enable_helm=True) }}" + - name: Create kubernetes resources for lookup output considering the local environment variables + environment: + CI: true + HTTP_PROXY: http://proxy.example.com:8080 + kubernetes.core.k8s: + definition: "{{ lookup('kubernetes.core.kustomize', binary_path='/path/to/kubectl', use_local_env=True) }}" + Return Values diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index c4e8473780..59c96b00d5 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -34,6 +34,12 @@ description: - Enable the helm chart inflation generator default: "False" + use_local_env: + description: + - Use the local environment varaible for the command execution + default: "False" + type: bool + version_added: 3.3.0 requirements: - "python >= 3.6" @@ -55,6 +61,13 @@ - name: Create kubernetes resources for lookup output with `--enable-helm` set kubernetes.core.k8s: definition: "{{ lookup('kubernetes.core.kustomize', dir='/path/to/kustomization', enable_helm=True) }}" + +- name: Create kubernetes resources for lookup output considering the local environment variables + environment: + CI: true + HTTP_PROXY: http://proxy.example.com:8080 + kubernetes.core.k8s: + definition: "{{ lookup('kubernetes.core.kustomize', binary_path='/path/to/kubectl', use_local_env=True) }}" """ RETURN = """ @@ -72,6 +85,7 @@ key1: val1 """ +import os import subprocess from ansible.errors import AnsibleLookupError @@ -92,8 +106,8 @@ def get_binary_from_path(name, opt_dirs=None): return None -def run_command(command): - cmd = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) +def run_command(command, environ=None): + cmd = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=environ) stdout, stderr = cmd.communicate() return cmd.returncode, stdout, stderr @@ -107,6 +121,7 @@ def run( binary_path=None, opt_dirs=None, enable_helm=False, + use_local_env=False, **kwargs ): executable_path = binary_path @@ -140,6 +155,9 @@ def run( if enable_helm: command += ["--enable-helm"] + + if use_local_env: + environ = dict(os.environ) (ret, out, err) = run_command(command) if ret != 0: From 5a42b952b35a30c964040102a6c42cfad6ab36e5 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Wed, 30 Oct 2024 07:59:03 +0000 Subject: [PATCH 02/28] add changelog fragment (assuming next PR number) --- .../20241030-support-of-evrion-for-kustomize-lookup-plugin.yaml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/20241030-support-of-evrion-for-kustomize-lookup-plugin.yaml diff --git a/changelogs/fragments/20241030-support-of-evrion-for-kustomize-lookup-plugin.yaml b/changelogs/fragments/20241030-support-of-evrion-for-kustomize-lookup-plugin.yaml new file mode 100644 index 0000000000..21128dd927 --- /dev/null +++ b/changelogs/fragments/20241030-support-of-evrion-for-kustomize-lookup-plugin.yaml @@ -0,0 +1,2 @@ +minor_changes: + - kustomize - add support of local environ (https://github.com/ansible-collections/kubernetes.core/pull/786). From 26d85f038e46e737ce2059afc4b0535641296634 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Wed, 30 Oct 2024 08:36:40 +0000 Subject: [PATCH 03/28] fix W293: blank line contains whitespace --- plugins/lookup/kustomize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index 59c96b00d5..f76147bdca 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -155,7 +155,7 @@ def run( if enable_helm: command += ["--enable-helm"] - + if use_local_env: environ = dict(os.environ) From 4a784138d6a70d5d60bc12d3bc261a9bd406f320 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Wed, 30 Oct 2024 08:40:21 +0000 Subject: [PATCH 04/28] fix using of evrion --- plugins/lookup/kustomize.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index f76147bdca..864357b6e3 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -158,8 +158,10 @@ def run( if use_local_env: environ = dict(os.environ) + else: + environ = None - (ret, out, err) = run_command(command) + (ret, out, err) = run_command(command, environ=environ) if ret != 0: if err: raise AnsibleLookupError( From 4655376d4d1cb578e6088e35b16518493e285caa Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Wed, 30 Oct 2024 08:47:44 +0000 Subject: [PATCH 05/28] reformat with black --- plugins/lookup/kustomize.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index 864357b6e3..4f515a8f1b 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -107,7 +107,9 @@ def get_binary_from_path(name, opt_dirs=None): def run_command(command, environ=None): - cmd = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=environ) + cmd = subprocess.Popen( + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=environ + ) stdout, stderr = cmd.communicate() return cmd.returncode, stdout, stderr From e85e95a813d47c553f0110627aa218a8dc4e5e57 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Wed, 30 Oct 2024 10:29:29 +0000 Subject: [PATCH 06/28] change approach of support enviromental variable --- docs/kubernetes.core.kustomize_lookup.rst | 27 +++++++------------ plugins/lookup/kustomize.py | 33 ++++++++++++++--------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/docs/kubernetes.core.kustomize_lookup.rst b/docs/kubernetes.core.kustomize_lookup.rst index 708d44939a..2f2928ac55 100644 --- a/docs/kubernetes.core.kustomize_lookup.rst +++ b/docs/kubernetes.core.kustomize_lookup.rst @@ -98,41 +98,37 @@ Parameters
- opt_dirs + enviroment
- - + dictionary
+
added in 3.3.0
+ Default:
{}
-
An optional list of directories to search for the executable in addition to PATH.
+
The environment variables to pass to the kustomize or kubectl command.
- use_local_env + opt_dirs
- boolean + -
-
added in 3.3.0
-
    Choices: -
  • no
  • -
  • yes
  • -
- Default:
"False"
-
Use the local environment varaible for the command execution
+
An optional list of directories to search for the executable in addition to PATH.
@@ -168,12 +164,9 @@ Examples kubernetes.core.k8s: definition: "{{ lookup('kubernetes.core.kustomize', dir='/path/to/kustomization', enable_helm=True) }}" - - name: Create kubernetes resources for lookup output considering the local environment variables - environment: - CI: true - HTTP_PROXY: http://proxy.example.com:8080 + - name: Create kubernetes resources for lookup output with environment variables kubernetes.core.k8s: - definition: "{{ lookup('kubernetes.core.kustomize', binary_path='/path/to/kubectl', use_local_env=True) }}" + definition: "{{ lookup('kubernetes.core.kustomize', binary_path='/path/to/kubectl', enviroment='HTTP_PROXY=http://proxy.example.com:3128') }}" diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index 4f515a8f1b..b5d076650e 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -34,11 +34,11 @@ description: - Enable the helm chart inflation generator default: "False" - use_local_env: + enviroment: description: - - Use the local environment varaible for the command execution - default: "False" - type: bool + - The environment variables to pass to the kustomize or kubectl command. + type: dict + default: {} version_added: 3.3.0 requirements: @@ -62,12 +62,9 @@ kubernetes.core.k8s: definition: "{{ lookup('kubernetes.core.kustomize', dir='/path/to/kustomization', enable_helm=True) }}" -- name: Create kubernetes resources for lookup output considering the local environment variables - environment: - CI: true - HTTP_PROXY: http://proxy.example.com:8080 +- name: Create kubernetes resources for lookup output with environment variables kubernetes.core.k8s: - definition: "{{ lookup('kubernetes.core.kustomize', binary_path='/path/to/kubectl', use_local_env=True) }}" + definition: "{{ lookup('kubernetes.core.kustomize', binary_path='/path/to/kubectl', enviroment='HTTP_PROXY=http://proxy.example.com:3128') }}" """ RETURN = """ @@ -158,10 +155,20 @@ def run( if enable_helm: command += ["--enable-helm"] - if use_local_env: - environ = dict(os.environ) - else: - environ = None + evrion = os.environ.copy() + + if enviroment: + if isinstance(enviroment, str): + if not all([env.count("=") == 1 for env in enviroment.split(" ")]): + raise AnsibleLookupError( + "Enviroment should be dict or string in the format key=value" + ) + for env in enviroment.split(" "): + key, value = env.split("=") + evrion[key] = value + if isinstance(enviroment, dict): + for key, value in enviroment.items(): + evrion[key] = value (ret, out, err) = run_command(command, environ=environ) if ret != 0: From c6f67230485b8f4b3359461553eb87936093971a Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Wed, 30 Oct 2024 10:51:18 +0000 Subject: [PATCH 07/28] fix typo envion e -> envrion --- plugins/lookup/kustomize.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index b5d076650e..48c11f4589 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -120,7 +120,7 @@ def run( binary_path=None, opt_dirs=None, enable_helm=False, - use_local_env=False, + enviroment={}, **kwargs ): executable_path = binary_path @@ -155,7 +155,7 @@ def run( if enable_helm: command += ["--enable-helm"] - evrion = os.environ.copy() + envrion = os.environ.copy() if enviroment: if isinstance(enviroment, str): @@ -165,10 +165,10 @@ def run( ) for env in enviroment.split(" "): key, value = env.split("=") - evrion[key] = value + envrion[key] = value if isinstance(enviroment, dict): for key, value in enviroment.items(): - evrion[key] = value + envrion[key] = value (ret, out, err) = run_command(command, environ=environ) if ret != 0: From fcd3517312bd8e146c432a450aa34d47d9e786a5 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Wed, 30 Oct 2024 11:10:23 +0000 Subject: [PATCH 08/28] fix typo envion e -> envrion --- plugins/lookup/kustomize.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index 48c11f4589..aae95c58ec 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -155,7 +155,7 @@ def run( if enable_helm: command += ["--enable-helm"] - envrion = os.environ.copy() + environ = os.environ.copy() if enviroment: if isinstance(enviroment, str): @@ -165,10 +165,10 @@ def run( ) for env in enviroment.split(" "): key, value = env.split("=") - envrion[key] = value + environ[key] = value if isinstance(enviroment, dict): for key, value in enviroment.items(): - envrion[key] = value + environ[key] = value (ret, out, err) = run_command(command, environ=environ) if ret != 0: From 9ee83855088f4bc3e968bd35f0e4fe75562f80c2 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Wed, 30 Oct 2024 13:58:39 +0000 Subject: [PATCH 09/28] attemp to fix linter --- plugins/lookup/kustomize.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index aae95c58ec..4942410f92 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -120,7 +120,7 @@ def run( binary_path=None, opt_dirs=None, enable_helm=False, - enviroment={}, + enviroment=None, **kwargs ): executable_path = binary_path @@ -159,7 +159,7 @@ def run( if enviroment: if isinstance(enviroment, str): - if not all([env.count("=") == 1 for env in enviroment.split(" ")]): + if not all(env.count("=") == 1 for env in enviroment.split(" ")): raise AnsibleLookupError( "Enviroment should be dict or string in the format key=value" ) From 10b852505cb67672051df0fbf765388793c0e8b6 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Sat, 2 Nov 2024 12:43:54 +0000 Subject: [PATCH 10/28] temprarly commit to test ansible-network/github_actions/pull/162 to be reverted --- .github/workflows/integration-tests.yaml | 14 +++++++------- .github/workflows/sanity-tests.yaml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index 4323bf87d9..5cbfb356d8 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -29,7 +29,7 @@ jobs: - name: list changes for pull request id: splitter - uses: ansible-network/github_actions/.github/actions/ansible_test_splitter@main + uses: yurnov/ansible_github_actions/.github/actions/ansible_test_splitter@update_ansible_n_python_version_to_current_state with: collections_to_test: ${{ env.source_dir }} total_jobs: 8 @@ -99,33 +99,33 @@ jobs: - name: Build and install collection id: install-src - uses: ansible-network/github_actions/.github/actions/build_install_collection@main + uses: yurnov/ansible_github_actions/.github/actions/build_install_collection@update_ansible_n_python_version_to_current_state with: install_python_dependencies: true source_path: ${{ env.source }} - name: checkout ansible-collections/cloud.common - uses: ansible-network/github_actions/.github/actions/checkout_dependency@main + uses: yurnov/ansible_github_actions/.github/actions/checkout_dependency@update_ansible_n_python_version_to_current_state with: repository: ansible-collections/cloud.common path: ${{ env.cloud_common }} ref: main - name: checkout ansible-collections/ansible.posix - uses: ansible-network/github_actions/.github/actions/checkout_dependency@main + uses: yurnov/ansible_github_actions/.github/actions/checkout_dependency@update_ansible_n_python_version_to_current_state with: repository: ansible-collections/ansible.posix path: ${{ env.ansible_posix }} ref: main - name: install cloud.common collection - uses: ansible-network/github_actions/.github/actions/build_install_collection@main + uses: yurnov/ansible_github_actions/.github/actions/build_install_collection@update_ansible_n_python_version_to_current_state with: install_python_dependencies: true source_path: ${{ env.cloud_common }} - name: install ansible.posix collection - uses: ansible-network/github_actions/.github/actions/build_install_collection@main + uses: yurnov/ansible_github_actions/.github/actions/build_install_collection@update_ansible_n_python_version_to_current_state with: install_python_dependencies: true source_path: ${{ env.ansible_posix }} @@ -136,7 +136,7 @@ jobs: node_image: "kindest/node:v1.29.2" - name: Run integration tests - uses: ansible-network/github_actions/.github/actions/ansible_test_integration@main + uses: yurnov/ansible_github_actions/.github/actions/ansible_test_integration@update_ansible_n_python_version_to_current_state with: collection_path: ${{ steps.install-src.outputs.collection_path }} python_version: ${{ matrix.python-version }} diff --git a/.github/workflows/sanity-tests.yaml b/.github/workflows/sanity-tests.yaml index 044f6def12..b2f942b35a 100644 --- a/.github/workflows/sanity-tests.yaml +++ b/.github/workflows/sanity-tests.yaml @@ -12,4 +12,4 @@ on: jobs: sanity: - uses: ansible-network/github_actions/.github/workflows/sanity.yml@main + uses: yurnov/ansible_github_actions/.github/workflows/sanity.yml@update_ansible_n_python_version_to_current_state From c4795f52bc119121c924e23e85bffb2e943a7f98 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Sat, 2 Nov 2024 13:31:38 +0000 Subject: [PATCH 11/28] fix sanity test with ansible-core 2.18 and 2.19 --- tests/sanity/ignore-2.14.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/sanity/ignore-2.14.txt b/tests/sanity/ignore-2.14.txt index 0069053bf4..f811b2b7db 100644 --- a/tests/sanity/ignore-2.14.txt +++ b/tests/sanity/ignore-2.14.txt @@ -1,12 +1,18 @@ plugins/module_utils/client/discovery.py import-3.9!skip plugins/module_utils/client/discovery.py import-3.10!skip plugins/module_utils/client/discovery.py import-3.11!skip +plugins/module_utils/client/discovery.py import-3.12!skip +plugins/module_utils/client/discovery.py import-3.13!skip plugins/module_utils/client/resource.py import-3.9!skip plugins/module_utils/client/resource.py import-3.10!skip plugins/module_utils/client/resource.py import-3.11!skip +plugins/module_utils/client/resource.py import-3.12!skip +plugins/module_utils/client/resource.py import-3.13!skip plugins/module_utils/k8sdynamicclient.py import-3.9!skip plugins/module_utils/k8sdynamicclient.py import-3.10!skip plugins/module_utils/k8sdynamicclient.py import-3.11!skip +plugins/module_utils/k8sdynamicclient.py import-3.12!skip +plugins/module_utils/k8sdynamicclient.py import-3.13!skip plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc plugins/modules/k8s_scale.py validate-modules:parameter-type-not-in-doc plugins/modules/k8s_service.py validate-modules:parameter-type-not-in-doc From bbd760cc877a58dbb23240b850bd355e3fa0e5c4 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Sat, 2 Nov 2024 13:34:57 +0000 Subject: [PATCH 12/28] revert back ignore-2.14.txt that should not be changed --- tests/sanity/ignore-2.14.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/sanity/ignore-2.14.txt b/tests/sanity/ignore-2.14.txt index f811b2b7db..0069053bf4 100644 --- a/tests/sanity/ignore-2.14.txt +++ b/tests/sanity/ignore-2.14.txt @@ -1,18 +1,12 @@ plugins/module_utils/client/discovery.py import-3.9!skip plugins/module_utils/client/discovery.py import-3.10!skip plugins/module_utils/client/discovery.py import-3.11!skip -plugins/module_utils/client/discovery.py import-3.12!skip -plugins/module_utils/client/discovery.py import-3.13!skip plugins/module_utils/client/resource.py import-3.9!skip plugins/module_utils/client/resource.py import-3.10!skip plugins/module_utils/client/resource.py import-3.11!skip -plugins/module_utils/client/resource.py import-3.12!skip -plugins/module_utils/client/resource.py import-3.13!skip plugins/module_utils/k8sdynamicclient.py import-3.9!skip plugins/module_utils/k8sdynamicclient.py import-3.10!skip plugins/module_utils/k8sdynamicclient.py import-3.11!skip -plugins/module_utils/k8sdynamicclient.py import-3.12!skip -plugins/module_utils/k8sdynamicclient.py import-3.13!skip plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc plugins/modules/k8s_scale.py validate-modules:parameter-type-not-in-doc plugins/modules/k8s_service.py validate-modules:parameter-type-not-in-doc From 1ac828d1a8f6d4858a2e871d3723463e19d0337a Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Sat, 2 Nov 2024 13:48:44 +0000 Subject: [PATCH 13/28] Revert "temprarly commit to test ansible-network/github_actions/pull/162" This reverts commit 9249d9a154219c6f69e2db4445307330d9745c90. --- .github/workflows/integration-tests.yaml | 14 +++++++------- .github/workflows/sanity-tests.yaml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index 5cbfb356d8..4323bf87d9 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -29,7 +29,7 @@ jobs: - name: list changes for pull request id: splitter - uses: yurnov/ansible_github_actions/.github/actions/ansible_test_splitter@update_ansible_n_python_version_to_current_state + uses: ansible-network/github_actions/.github/actions/ansible_test_splitter@main with: collections_to_test: ${{ env.source_dir }} total_jobs: 8 @@ -99,33 +99,33 @@ jobs: - name: Build and install collection id: install-src - uses: yurnov/ansible_github_actions/.github/actions/build_install_collection@update_ansible_n_python_version_to_current_state + uses: ansible-network/github_actions/.github/actions/build_install_collection@main with: install_python_dependencies: true source_path: ${{ env.source }} - name: checkout ansible-collections/cloud.common - uses: yurnov/ansible_github_actions/.github/actions/checkout_dependency@update_ansible_n_python_version_to_current_state + uses: ansible-network/github_actions/.github/actions/checkout_dependency@main with: repository: ansible-collections/cloud.common path: ${{ env.cloud_common }} ref: main - name: checkout ansible-collections/ansible.posix - uses: yurnov/ansible_github_actions/.github/actions/checkout_dependency@update_ansible_n_python_version_to_current_state + uses: ansible-network/github_actions/.github/actions/checkout_dependency@main with: repository: ansible-collections/ansible.posix path: ${{ env.ansible_posix }} ref: main - name: install cloud.common collection - uses: yurnov/ansible_github_actions/.github/actions/build_install_collection@update_ansible_n_python_version_to_current_state + uses: ansible-network/github_actions/.github/actions/build_install_collection@main with: install_python_dependencies: true source_path: ${{ env.cloud_common }} - name: install ansible.posix collection - uses: yurnov/ansible_github_actions/.github/actions/build_install_collection@update_ansible_n_python_version_to_current_state + uses: ansible-network/github_actions/.github/actions/build_install_collection@main with: install_python_dependencies: true source_path: ${{ env.ansible_posix }} @@ -136,7 +136,7 @@ jobs: node_image: "kindest/node:v1.29.2" - name: Run integration tests - uses: yurnov/ansible_github_actions/.github/actions/ansible_test_integration@update_ansible_n_python_version_to_current_state + uses: ansible-network/github_actions/.github/actions/ansible_test_integration@main with: collection_path: ${{ steps.install-src.outputs.collection_path }} python_version: ${{ matrix.python-version }} diff --git a/.github/workflows/sanity-tests.yaml b/.github/workflows/sanity-tests.yaml index b2f942b35a..044f6def12 100644 --- a/.github/workflows/sanity-tests.yaml +++ b/.github/workflows/sanity-tests.yaml @@ -12,4 +12,4 @@ on: jobs: sanity: - uses: yurnov/ansible_github_actions/.github/workflows/sanity.yml@update_ansible_n_python_version_to_current_state + uses: ansible-network/github_actions/.github/workflows/sanity.yml@main From 260574dc66c1e9e27d7d39f0f66e25e881eceb52 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Thu, 21 Nov 2024 12:15:19 +0000 Subject: [PATCH 14/28] apply code-review suggestion from @abikouo --- README.md | 4 ++++ docs/kubernetes.core.kustomize_lookup.rst | 4 ++-- plugins/lookup/kustomize.py | 11 +++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 553d7f08b4..78fc79a44b 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,10 @@ If you encounter issues or have questions, you can submit a support request thro See the [raw generated changelog](https://github.com/ansible-collections/kubernetes.core/blob/main/CHANGELOG.rst). +## More Information + +For more information about Ansible's Kubernetes integration, join the `#ansible-kubernetes` channel on [libera.chat](https://libera.chat/) IRC, and browse the resources in the [Kubernetes Working Group](https://github.com/ansible/community/wiki/Kubernetes) Community wiki page. + ## Code of Conduct We follow the [Ansible Code of Conduct](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html) in all our interactions within this project. diff --git a/docs/kubernetes.core.kustomize_lookup.rst b/docs/kubernetes.core.kustomize_lookup.rst index 2f2928ac55..a305bdc438 100644 --- a/docs/kubernetes.core.kustomize_lookup.rst +++ b/docs/kubernetes.core.kustomize_lookup.rst @@ -98,7 +98,7 @@ Parameters
- enviroment + environment
dictionary @@ -166,7 +166,7 @@ Examples - name: Create kubernetes resources for lookup output with environment variables kubernetes.core.k8s: - definition: "{{ lookup('kubernetes.core.kustomize', binary_path='/path/to/kubectl', enviroment='HTTP_PROXY=http://proxy.example.com:3128') }}" + definition: "{{ lookup('kubernetes.core.kustomize', binary_path='/path/to/kubectl', environment='HTTP_PROXY=http://proxy.example.com:3128') }}" diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index 4942410f92..c2cd2fc00d 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -34,7 +34,7 @@ description: - Enable the helm chart inflation generator default: "False" - enviroment: + environment: description: - The environment variables to pass to the kustomize or kubectl command. type: dict @@ -64,7 +64,7 @@ - name: Create kubernetes resources for lookup output with environment variables kubernetes.core.k8s: - definition: "{{ lookup('kubernetes.core.kustomize', binary_path='/path/to/kubectl', enviroment='HTTP_PROXY=http://proxy.example.com:3128') }}" + definition: "{{ lookup('kubernetes.core.kustomize', binary_path='/path/to/kubectl', environment='HTTP_PROXY=http://proxy.example.com:3128') }}" """ RETURN = """ @@ -155,9 +155,9 @@ def run( if enable_helm: command += ["--enable-helm"] - environ = os.environ.copy() - + environ = None if enviroment: + environ = os.environ.copy() if isinstance(enviroment, str): if not all(env.count("=") == 1 for env in enviroment.split(" ")): raise AnsibleLookupError( @@ -167,8 +167,7 @@ def run( key, value = env.split("=") environ[key] = value if isinstance(enviroment, dict): - for key, value in enviroment.items(): - environ[key] = value + environ.update(environment) (ret, out, err) = run_command(command, environ=environ) if ret != 0: From b57560855749f041988676320f8489331c7ac46f Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Thu, 21 Nov 2024 12:29:00 +0000 Subject: [PATCH 15/28] fix typo --- plugins/lookup/kustomize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index c2cd2fc00d..cde31868a7 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -120,7 +120,7 @@ def run( binary_path=None, opt_dirs=None, enable_helm=False, - enviroment=None, + environment=None, **kwargs ): executable_path = binary_path From fd8abed07a319984653819cc2538249212de56af Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Thu, 21 Nov 2024 12:35:55 +0000 Subject: [PATCH 16/28] fix typo --- plugins/lookup/kustomize.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index cde31868a7..54e597c9ff 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -156,17 +156,17 @@ def run( command += ["--enable-helm"] environ = None - if enviroment: + if environment: environ = os.environ.copy() - if isinstance(enviroment, str): - if not all(env.count("=") == 1 for env in enviroment.split(" ")): + if isinstance(environment, str): + if not all(env.count("=") == 1 for env in environment.split(" ")): raise AnsibleLookupError( - "Enviroment should be dict or string in the format key=value" + "environment should be dict or string in the format key=value" ) - for env in enviroment.split(" "): + for env in environment.split(" "): key, value = env.split("=") environ[key] = value - if isinstance(enviroment, dict): + if isinstance(environment, dict): environ.update(environment) (ret, out, err) = run_command(command, environ=environ) From b10f2ac1d0011b114a92c5396cd3f29b518d6582 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Thu, 21 Nov 2024 13:21:40 +0000 Subject: [PATCH 17/28] Initial commit with integration tests --- .../targets/lookup_kustomize/tasks/main.yml | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/lookup_kustomize/tasks/main.yml b/tests/integration/targets/lookup_kustomize/tasks/main.yml index dafdcdd0bd..6ce1be3bf4 100644 --- a/tests/integration/targets/lookup_kustomize/tasks/main.yml +++ b/tests/integration/targets/lookup_kustomize/tasks/main.yml @@ -94,6 +94,62 @@ namespace: "{{ kustomize_ns }}" definition: "{{ lookup('kubernetes.core.kustomize', dir=kustomize_dir, opt_dirs=tmp_dir_path) }}" + - name: Create temporarly directory for test + ansible.builtin.tempfile: + state: directory + suffix: .testkustomize + register: _tmp_dir_kustomize + + - name: Create a base directory + ansible.builtin.file: + path: "{{ _tmp_dir_kustomize.path }}/base" + state: directory + mode: '0755' + + - name: Download helloWorld example + ansible.builtin.get_url: + url: "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/examples/helloWorld/{{ item }}.yaml" + dest: "{{ _tmp_dir_kustomize.path }}/base/" + with_items: + - configMap + - deployment + - kustomization + - service + + - name: Replace label in kustomization.yaml + # Replace the 'app: hello' with 'app: ${TEST_APP}' + ansible.builtin.replace: + path: "{{ _tmp_dir_kustomize.path }}/base/kustomization.yaml" + regexp: 'app: hello' + replace: 'app: ${TEST_APP}' + + - name: Test kustomize lookup plugin with environment variables in the string format + set_fact: + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment="TEST_APP=testpassed VAR2=Flase") }}" + + - ansible.builtin.debug: + var: resource_kustomize + + - name: Assest that TEST_APP is replaced with testpassed + assert: + that: + - "'app: testpassed' in resource_kustomize.string" + fail_msg: "kustomize lookup plugin with environment variables in the string format failed" + + - name: Test kustomize lookup plugin with environment variables in the list format + set_fact: + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment="{TEST_APP=testpassed, VAR2=Flase}") }}" + + - ansible.builtin.debug: + var: resource_kustomize + + - name: Assest that TEST_APP is replaced with testpassed + assert: + that: + - "'app: testpassed' in resource_kustomize.string" + fail_msg: "kustomize lookup plugin with environment variables in the list format failed" + + always: - name: Delete namespace k8s: @@ -105,4 +161,7 @@ - name: Delete temporary directory file: state: absent - path: "{{ tmp_dir_path }}" + path: "{{ item }}" + with_items: + - "{{ tmp_dir_path }}" + - "{{ _tmp_dir_kustomize.path }}" From d8b920469641bd738e781bfcd75b2cc343cb82dc Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Thu, 21 Nov 2024 13:49:10 +0000 Subject: [PATCH 18/28] Fix integration tests --- tests/integration/targets/lookup_kustomize/tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/lookup_kustomize/tasks/main.yml b/tests/integration/targets/lookup_kustomize/tasks/main.yml index 6ce1be3bf4..b9ec3a0b46 100644 --- a/tests/integration/targets/lookup_kustomize/tasks/main.yml +++ b/tests/integration/targets/lookup_kustomize/tasks/main.yml @@ -125,7 +125,7 @@ - name: Test kustomize lookup plugin with environment variables in the string format set_fact: - resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment="TEST_APP=testpassed VAR2=Flase") }}" + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='TEST_APP=testpassed VAR2=Flase') }}" - ansible.builtin.debug: var: resource_kustomize @@ -138,7 +138,7 @@ - name: Test kustomize lookup plugin with environment variables in the list format set_fact: - resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment="{TEST_APP=testpassed, VAR2=Flase}") }}" + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={TEST_APP=testpassed, VAR2=Flase}) }}" - ansible.builtin.debug: var: resource_kustomize From 0e580ba994aa8238ae74e7d8ca2bccad40466969 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Thu, 21 Nov 2024 13:53:24 +0000 Subject: [PATCH 19/28] Fix linter in integration tests --- .../targets/lookup_kustomize/tasks/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integration/targets/lookup_kustomize/tasks/main.yml b/tests/integration/targets/lookup_kustomize/tasks/main.yml index b9ec3a0b46..6888e0d528 100644 --- a/tests/integration/targets/lookup_kustomize/tasks/main.yml +++ b/tests/integration/targets/lookup_kustomize/tasks/main.yml @@ -99,13 +99,13 @@ state: directory suffix: .testkustomize register: _tmp_dir_kustomize - + - name: Create a base directory ansible.builtin.file: path: "{{ _tmp_dir_kustomize.path }}/base" state: directory mode: '0755' - + - name: Download helloWorld example ansible.builtin.get_url: url: "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/examples/helloWorld/{{ item }}.yaml" @@ -115,7 +115,7 @@ - deployment - kustomization - service - + - name: Replace label in kustomization.yaml # Replace the 'app: hello' with 'app: ${TEST_APP}' ansible.builtin.replace: @@ -125,7 +125,7 @@ - name: Test kustomize lookup plugin with environment variables in the string format set_fact: - resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='TEST_APP=testpassed VAR2=Flase') }}" + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='TEST_APP=testpassed VAR2=Flase') }}" - ansible.builtin.debug: var: resource_kustomize @@ -138,7 +138,7 @@ - name: Test kustomize lookup plugin with environment variables in the list format set_fact: - resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={TEST_APP=testpassed, VAR2=Flase}) }}" + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={TEST_APP=testpassed, VAR2=Flase}) }}" - ansible.builtin.debug: var: resource_kustomize @@ -162,6 +162,6 @@ file: state: absent path: "{{ item }}" - with_items: + with_items: - "{{ tmp_dir_path }}" - "{{ _tmp_dir_kustomize.path }}" From f638e65970479589e29e90f35654d65ea577bd28 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Thu, 21 Nov 2024 13:56:02 +0000 Subject: [PATCH 20/28] Fix linter in integration tests --- .../targets/lookup_kustomize/tasks/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integration/targets/lookup_kustomize/tasks/main.yml b/tests/integration/targets/lookup_kustomize/tasks/main.yml index 6888e0d528..f152a20f4e 100644 --- a/tests/integration/targets/lookup_kustomize/tasks/main.yml +++ b/tests/integration/targets/lookup_kustomize/tasks/main.yml @@ -111,10 +111,10 @@ url: "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/examples/helloWorld/{{ item }}.yaml" dest: "{{ _tmp_dir_kustomize.path }}/base/" with_items: - - configMap - - deployment - - kustomization - - service + - configMap + - deployment + - kustomization + - service - name: Replace label in kustomization.yaml # Replace the 'app: hello' with 'app: ${TEST_APP}' @@ -163,5 +163,5 @@ state: absent path: "{{ item }}" with_items: - - "{{ tmp_dir_path }}" - - "{{ _tmp_dir_kustomize.path }}" + - "{{ tmp_dir_path }}" + - "{{ _tmp_dir_kustomize.path }}" From 756ce7e4c7acf4b2ac15b3bf7e96a9d1bbb06f42 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Thu, 21 Nov 2024 13:58:42 +0000 Subject: [PATCH 21/28] Fix integration tests --- .../targets/lookup_kustomize/tasks/main.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/integration/targets/lookup_kustomize/tasks/main.yml b/tests/integration/targets/lookup_kustomize/tasks/main.yml index f152a20f4e..d09069d9be 100644 --- a/tests/integration/targets/lookup_kustomize/tasks/main.yml +++ b/tests/integration/targets/lookup_kustomize/tasks/main.yml @@ -132,9 +132,8 @@ - name: Assest that TEST_APP is replaced with testpassed assert: - that: - - "'app: testpassed' in resource_kustomize.string" - fail_msg: "kustomize lookup plugin with environment variables in the string format failed" + that: "'app: testpassed' in resource_kustomize.string" + fail_msg: "kustomize lookup plugin with environment variables in the string format failed" - name: Test kustomize lookup plugin with environment variables in the list format set_fact: @@ -145,9 +144,8 @@ - name: Assest that TEST_APP is replaced with testpassed assert: - that: - - "'app: testpassed' in resource_kustomize.string" - fail_msg: "kustomize lookup plugin with environment variables in the list format failed" + that: "'app: testpassed' in resource_kustomize.string" + fail_msg: "kustomize lookup plugin with environment variables in the list format failed" always: From bd00866f7362d6be7941ed9a9a1f9b3adba1181f Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Thu, 21 Nov 2024 14:06:20 +0000 Subject: [PATCH 22/28] another attempt to integration tests --- README.md | 4 ---- tests/integration/targets/lookup_kustomize/tasks/main.yml | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 78fc79a44b..553d7f08b4 100644 --- a/README.md +++ b/README.md @@ -267,10 +267,6 @@ If you encounter issues or have questions, you can submit a support request thro See the [raw generated changelog](https://github.com/ansible-collections/kubernetes.core/blob/main/CHANGELOG.rst). -## More Information - -For more information about Ansible's Kubernetes integration, join the `#ansible-kubernetes` channel on [libera.chat](https://libera.chat/) IRC, and browse the resources in the [Kubernetes Working Group](https://github.com/ansible/community/wiki/Kubernetes) Community wiki page. - ## Code of Conduct We follow the [Ansible Code of Conduct](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html) in all our interactions within this project. diff --git a/tests/integration/targets/lookup_kustomize/tasks/main.yml b/tests/integration/targets/lookup_kustomize/tasks/main.yml index d09069d9be..65eb63ae0b 100644 --- a/tests/integration/targets/lookup_kustomize/tasks/main.yml +++ b/tests/integration/targets/lookup_kustomize/tasks/main.yml @@ -125,7 +125,7 @@ - name: Test kustomize lookup plugin with environment variables in the string format set_fact: - resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='TEST_APP=testpassed VAR2=Flase') }}" + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path/base, environment='TEST_APP=testpassed VAR2=Flase') }}" - ansible.builtin.debug: var: resource_kustomize @@ -137,7 +137,7 @@ - name: Test kustomize lookup plugin with environment variables in the list format set_fact: - resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={TEST_APP=testpassed, VAR2=Flase}) }}" + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path/base, environment={TEST_APP=testpassed, VAR2=Flase}) }}" - ansible.builtin.debug: var: resource_kustomize From e0b353245137dc54c690e15f0404dde0698fdc42 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Thu, 21 Nov 2024 14:21:17 +0000 Subject: [PATCH 23/28] another attempt to integration tests --- .../targets/lookup_kustomize/tasks/main.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/integration/targets/lookup_kustomize/tasks/main.yml b/tests/integration/targets/lookup_kustomize/tasks/main.yml index 65eb63ae0b..d150a88246 100644 --- a/tests/integration/targets/lookup_kustomize/tasks/main.yml +++ b/tests/integration/targets/lookup_kustomize/tasks/main.yml @@ -100,16 +100,16 @@ suffix: .testkustomize register: _tmp_dir_kustomize - - name: Create a base directory - ansible.builtin.file: - path: "{{ _tmp_dir_kustomize.path }}/base" - state: directory - mode: '0755' + # - name: Create a base directory + # ansible.builtin.file: + # path: "{{ _tmp_dir_kustomize.path }}/base" + # state: directory + # mode: '0755' - name: Download helloWorld example ansible.builtin.get_url: url: "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/examples/helloWorld/{{ item }}.yaml" - dest: "{{ _tmp_dir_kustomize.path }}/base/" + dest: "{{ _tmp_dir_kustomize.path }}" with_items: - configMap - deployment @@ -119,13 +119,13 @@ - name: Replace label in kustomization.yaml # Replace the 'app: hello' with 'app: ${TEST_APP}' ansible.builtin.replace: - path: "{{ _tmp_dir_kustomize.path }}/base/kustomization.yaml" + path: "{{ _tmp_dir_kustomize.path }}kustomization.yaml" regexp: 'app: hello' replace: 'app: ${TEST_APP}' - name: Test kustomize lookup plugin with environment variables in the string format set_fact: - resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path/base, environment='TEST_APP=testpassed VAR2=Flase') }}" + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='TEST_APP=testpassed VAR2=Flase') }}" - ansible.builtin.debug: var: resource_kustomize @@ -137,7 +137,7 @@ - name: Test kustomize lookup plugin with environment variables in the list format set_fact: - resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path/base, environment={TEST_APP=testpassed, VAR2=Flase}) }}" + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={TEST_APP=testpassed, VAR2=Flase}) }}" - ansible.builtin.debug: var: resource_kustomize From 00e25254ff5f9065e3e0964a920b8afcc9debe56 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Thu, 21 Nov 2024 14:26:46 +0000 Subject: [PATCH 24/28] another attempt to integration tests --- tests/integration/targets/lookup_kustomize/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/lookup_kustomize/tasks/main.yml b/tests/integration/targets/lookup_kustomize/tasks/main.yml index d150a88246..055fa2e434 100644 --- a/tests/integration/targets/lookup_kustomize/tasks/main.yml +++ b/tests/integration/targets/lookup_kustomize/tasks/main.yml @@ -119,7 +119,7 @@ - name: Replace label in kustomization.yaml # Replace the 'app: hello' with 'app: ${TEST_APP}' ansible.builtin.replace: - path: "{{ _tmp_dir_kustomize.path }}kustomization.yaml" + path: "{{ _tmp_dir_kustomize.path }}/kustomization.yaml" regexp: 'app: hello' replace: 'app: ${TEST_APP}' From 61d950e2672fcceebd79d31946af81ab6ca95ed0 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Thu, 21 Nov 2024 20:12:42 +0000 Subject: [PATCH 25/28] Refactor integration test for kustomize environ support --- .../targets/lookup_kustomize/tasks/main.yml | 62 ++++++++----------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/tests/integration/targets/lookup_kustomize/tasks/main.yml b/tests/integration/targets/lookup_kustomize/tasks/main.yml index 055fa2e434..c5b4184bc4 100644 --- a/tests/integration/targets/lookup_kustomize/tasks/main.yml +++ b/tests/integration/targets/lookup_kustomize/tasks/main.yml @@ -100,53 +100,41 @@ suffix: .testkustomize register: _tmp_dir_kustomize - # - name: Create a base directory - # ansible.builtin.file: - # path: "{{ _tmp_dir_kustomize.path }}/base" - # state: directory - # mode: '0755' - - name: Download helloWorld example ansible.builtin.get_url: - url: "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/examples/helloWorld/{{ item }}.yaml" + url: "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/refs/heads/master/examples/loadHttp/kustomization.yaml" dest: "{{ _tmp_dir_kustomize.path }}" - with_items: - - configMap - - deployment - - kustomization - - service - - name: Replace label in kustomization.yaml + - name: Run tinyproxy in docker # Replace the 'app: hello' with 'app: ${TEST_APP}' - ansible.builtin.replace: - path: "{{ _tmp_dir_kustomize.path }}/kustomization.yaml" - regexp: 'app: hello' - replace: 'app: ${TEST_APP}' + ansible.builtin.command: "docker run --rm -d -p 8888:8888 --name=tinyproxy dannydirect/tinyproxy ANY" + + - name: Ensure that tinyproxy is running + ansible.builtin.wait_for: + host: localhost + port: 8888 + state: started - name: Test kustomize lookup plugin with environment variables in the string format set_fact: - resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='TEST_APP=testpassed VAR2=Flase') }}" + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='HTTPS_PROXY=http://localhost:8888 VAR2=Flase') }}" + ignore_errors: true - - ansible.builtin.debug: - var: resource_kustomize + - name: Stop tinyproxy + ansible.builtin.command: "docker stop tinyproxy" - - name: Assest that TEST_APP is replaced with testpassed - assert: - that: "'app: testpassed' in resource_kustomize.string" - fail_msg: "kustomize lookup plugin with environment variables in the string format failed" - - - name: Test kustomize lookup plugin with environment variables in the list format + - name: Ensure kustomize lookup plugin fail with proxy down set_fact: - resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={TEST_APP=testpassed, VAR2=Flase}) }}" - - - ansible.builtin.debug: - var: resource_kustomize - - - name: Assest that TEST_APP is replaced with testpassed - assert: - that: "'app: testpassed' in resource_kustomize.string" - fail_msg: "kustomize lookup plugin with environment variables in the list format failed" + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='HTTPS_PROXY=http://localhost:8888 VAR2=Flase') }}" + register: result + ignore_errors: true + - name: Assert that kustomize lookup plugin failed + ansible.builtin.assert: + that: + - result.failed + - "'proxyconnect tcp: dial' in result.msg" + - "'connection refused' in result.msg" always: - name: Delete namespace @@ -163,3 +151,7 @@ with_items: - "{{ tmp_dir_path }}" - "{{ _tmp_dir_kustomize.path }}" + + - name: Stop tinyproxy + ansible.builtin.command: "docker stop tinyproxy" + ignore_errors: true From 246773d54c69645eb1bda0e184a97440445d0f6c Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Tue, 17 Dec 2024 17:17:19 +0000 Subject: [PATCH 26/28] change version_added to 5.1.0 --- plugins/lookup/kustomize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index 54e597c9ff..6d88cc44bd 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -39,7 +39,7 @@ - The environment variables to pass to the kustomize or kubectl command. type: dict default: {} - version_added: 3.3.0 + version_added: 5.1.0 requirements: - "python >= 3.6" From 4ea5735c245604f9cb257878b74cced46311c791 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Tue, 21 Jan 2025 13:35:32 +0200 Subject: [PATCH 27/28] update version_added to 5.2.0 as 5.1.0 released already --- docs/kubernetes.core.kustomize_lookup.rst | 2 +- plugins/lookup/kustomize.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/kubernetes.core.kustomize_lookup.rst b/docs/kubernetes.core.kustomize_lookup.rst index a305bdc438..4af09af822 100644 --- a/docs/kubernetes.core.kustomize_lookup.rst +++ b/docs/kubernetes.core.kustomize_lookup.rst @@ -103,7 +103,7 @@ Parameters
dictionary
-
added in 3.3.0
+
added in 5.2.0
Default:
{}
diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index 6d88cc44bd..3b093dd37d 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -39,7 +39,7 @@ - The environment variables to pass to the kustomize or kubectl command. type: dict default: {} - version_added: 5.1.0 + version_added: 5.2.0 requirements: - "python >= 3.6" From 8360fb0d308597a77c2c41c95fbc97ac77e179a2 Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Tue, 21 Jan 2025 21:57:50 +0200 Subject: [PATCH 28/28] bump version_added to 6.0.0 no feature release planned in stable-5 branch --- docs/kubernetes.core.kustomize_lookup.rst | 2 +- plugins/lookup/kustomize.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/kubernetes.core.kustomize_lookup.rst b/docs/kubernetes.core.kustomize_lookup.rst index 4af09af822..1f42d22b0d 100644 --- a/docs/kubernetes.core.kustomize_lookup.rst +++ b/docs/kubernetes.core.kustomize_lookup.rst @@ -103,7 +103,7 @@ Parameters
dictionary
-
added in 5.2.0
+
added in 6.0.0
Default:
{}
diff --git a/plugins/lookup/kustomize.py b/plugins/lookup/kustomize.py index 3b093dd37d..2b9fdb95f5 100644 --- a/plugins/lookup/kustomize.py +++ b/plugins/lookup/kustomize.py @@ -39,7 +39,7 @@ - The environment variables to pass to the kustomize or kubectl command. type: dict default: {} - version_added: 5.2.0 + version_added: 6.0.0 requirements: - "python >= 3.6"