Skip to content
Draft
Show file tree
Hide file tree
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
15 changes: 13 additions & 2 deletions plugins/modules/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
- Fernando Giorgetti (@fgiorgetti)
'''

RETURN = r'''
path:
description:
- Path to the namespace where resources are located when manipulating a system site
returned: success
type: str
'''

EXAMPLES = r'''
# Applying resources to a kubernetes cluster
- name: Apply Skupper Resources
Expand Down Expand Up @@ -122,7 +130,8 @@
delete as resource_delete
)
from ansible_collections.skupper.v2.plugins.module_utils.common import (
is_non_kube
is_non_kube,
namespace_home
)
from ansible_collections.skupper.v2.plugins.module_utils.exceptions import (
RuntimeException
Expand Down Expand Up @@ -186,12 +195,13 @@ def run(self):
changed = False
state = self.params.get("state", "present")
overwrite = state == "latest"
path = ""
try:
if is_non_kube(platform):
namespace = self.params["namespace"] or "default"
if not is_valid_name(namespace):
self.module.fail_json("invalid namespace (rfc1123): {}".format(namespace))

path = namespace_home(namespace)
if state == "absent":
changed = resource_delete(definitions, namespace)
else:
Expand All @@ -210,6 +220,7 @@ def run(self):
self.module.fail_json(ex.args)

result['changed'] = changed
result['path'] = path

self.module.exit_json(**result)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
- name: Setting namespace home directory (rootless)
ansible.builtin.set_fact:
_namespace_home: "{{ lookup('env', 'HOME') + '/.local/share/skupper/namespaces/' + namespace + '/' }}"
_namespace_home: "{{ lookup('env', 'HOME') + '/.local/share/skupper/namespaces/' + namespace | string + '/' }}"
when: ansible_real_user_id != 0
- name: Setting namespace home directory (rootful)
ansible.builtin.set_fact:
_namespace_home: "{{ '/var/lib/skupper/namespaces/' + namespace + '/' }}"
_namespace_home: "{{ '/var/lib/skupper/namespaces/' + namespace | string + '/' }}"
when: ansible_real_user_id == 0
- name: Removing namespace directory
ansible.builtin.file:
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/targets/resource/tasks/kube/resource.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: Create Site A resources based on definition
skupper.v2.resource:
def: "{{ lookup('ansible.builtin.file', 'site_a.yml') }}"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
kubeconfig: "{{ kubeconfig }}"
register: _result
- name: Assert that resources have been created
Expand All @@ -19,7 +19,7 @@
- name: Create Site A resources based on definition (no changes expected)
skupper.v2.resource:
def: "{{ lookup('ansible.builtin.file', 'site_a.yml') }}"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
kubeconfig: "{{ kubeconfig }}"
register: _result
- name: Assert that resources have not been changed
Expand All @@ -30,7 +30,7 @@
- name: Create Site A resources based on local path (no changes expected)
skupper.v2.resource:
path: "{{ role_path }}/files/site_a.yml"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
kubeconfig: "{{ kubeconfig }}"
register: _result
- name: Assert that resources have not been changed
Expand All @@ -41,7 +41,7 @@
- name: Create Site A resources based on remote path (no changes expected)
skupper.v2.resource:
path: "{{ role_path }}/files/site_a.yml"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
remote: true
kubeconfig: "{{ kubeconfig }}"
register: _result
Expand All @@ -53,7 +53,7 @@
- name: Override Site A resources based on local path
skupper.v2.resource:
path: "{{ role_path }}/files/site_a.yml"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
state: latest
kubeconfig: "{{ kubeconfig }}"
register: _result
Expand All @@ -65,7 +65,7 @@
- name: Delete Site A resources based on remote path
skupper.v2.resource:
path: "{{ role_path }}/files/site_a.yml"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
state: absent
kubeconfig: "{{ kubeconfig }}"
register: _result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
api_version: skupper.io/v2alpha1
kind: "{{ item.kind }}"
name: "{{ item.name }}"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
kubeconfig: "{{ kubeconfig }}"
register: my_resource
- name: Assert that the resource was successfully retrieved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
api_version: skupper.io/v2alpha1
kind: "{{ item.kind }}"
name: "{{ item.name }}"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
kubeconfig: "{{ kubeconfig }}"
register: _resource
until: _resource.resources | length == 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: Create Site A resources based on definition
skupper.v2.resource:
def: "{{ lookup('ansible.builtin.file', 'site_a.yml') }}"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
platform: podman
register: _result
- name: Assert that resources have been created
Expand All @@ -19,7 +19,7 @@
- name: Delete Site A resources based on remote path with invalid resources
skupper.v2.resource:
path: "{{ role_path }}/files/site_invalid.yml"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
state: absent
platform: podman
register: _result
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/targets/resource/tasks/nonkube/resource.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: Create Site A resources based on definition
skupper.v2.resource:
def: "{{ lookup('ansible.builtin.file', 'site_a.yml') }}"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
platform: podman
register: _result
- name: Assert that resources have been created
Expand All @@ -19,7 +19,7 @@
- name: Create Site A resources based on definition (no changes expected)
skupper.v2.resource:
def: "{{ lookup('ansible.builtin.file', 'site_a.yml') }}"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
platform: podman
register: _result
- name: Assert that resources have not been changed
Expand All @@ -30,7 +30,7 @@
- name: Create Site A resources based on local path (no changes expected)
skupper.v2.resource:
path: "{{ role_path }}/files/site_a.yml"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
platform: podman
register: _result
- name: Assert that resources have not been changed
Expand All @@ -41,7 +41,7 @@
- name: Create Site A resources based on remote path (no changes expected)
skupper.v2.resource:
path: "{{ role_path }}/files/site_a.yml"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
remote: true
platform: podman
register: _result
Expand All @@ -53,7 +53,7 @@
- name: Override Site A resources based on local path
skupper.v2.resource:
path: "{{ role_path }}/files/site_a.yml"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
state: latest
platform: podman
register: _result
Expand All @@ -65,7 +65,7 @@
- name: Delete Site A resources based on remote path
skupper.v2.resource:
path: "{{ role_path }}/files/site_a.yml"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
state: absent
platform: podman
register: _result
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
- name: Retrieve expected resource from the filesystem (rootless)
ansible.builtin.set_fact:
_content: "{{ lookup('file', lookup('env', 'HOME') + '/.local/share/skupper/namespaces/' + namespace + '/input/resources/' + item.file) | from_yaml }}"
_content: "{{ lookup('file', lookup('env', 'HOME') + '/.local/share/skupper/namespaces/' +
namespace | string + '/input/resources/' + item.file) | from_yaml }}"
when: ansible_real_user_id != 0
- name: Retrieve expected resource from the filesystem (rootful)
ansible.builtin.set_fact:
_content: "{{ lookup('file', '/var/lib/skupper/namespaces/' + namespace + '/input/resources/' + item.file) | from_yaml }}"
_content: "{{ lookup('file', '/var/lib/skupper/namespaces/' + namespace | string + '/input/resources/' + item.file) | from_yaml }}"
when: ansible_real_user_id == 0
- name: Assert that the resource was successfully retrieved
ansible.builtin.assert:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
- name: Set the filename to be verified (rootless)
ansible.builtin.set_fact:
_filename: "{{ lookup('env', 'HOME') + '/.local/share/skupper/namespaces/' + namespace + '/input/resources/' + item.file }}"
_filename: "{{ lookup('env', 'HOME') + '/.local/share/skupper/namespaces/' + namespace | string + '/input/resources/' + item.file }}"
when: ansible_real_user_id != 0
- name: Set the filename to be verified (rootful)
ansible.builtin.set_fact:
_filename: "{{ '/var/lib/skupper/namespaces/' + namespace + '/input/resources/' + item.file }}"
_filename: "{{ '/var/lib/skupper/namespaces/' + namespace | string + '/input/resources/' + item.file }}"
when: ansible_real_user_id == 0
- name: Retrieve expected resource from the filesystem
ansible.builtin.stat:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/targets/system/tasks/action-reload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: Create Site A resources
skupper.v2.resource:
path: "{{ role_path }}/files/site_a.yml"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
platform: podman
- name: Get skupper-site-ca key file hash
ansible.builtin.set_fact:
Expand All @@ -11,7 +11,7 @@
- name: Run the reload action
skupper.v2.system:
action: reload
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
image: "{{ system_image }}"
register: _system
environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
- name: Create Site A resources
skupper.v2.resource:
path: "{{ role_path }}/files/site_a.yml"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
platform: podman
- name: Run the bundle action
skupper.v2.system:
action: shell-script
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
image: "{{ system_image }}"
register: _system
environment:
Expand All @@ -31,13 +31,13 @@
ansible.builtin.include_role:
name: delete_nonkube_namespace
- name: Installing the generated bundle
ansible.builtin.command: "{{ '/tmp/' + site_name + '-bundle.sh -n ' + namespace }}"
ansible.builtin.command: "{{ '/tmp/' + site_name + '-bundle.sh -n ' + namespace | string }}"
register: _bundle
changed_when: _bundle.rc == 0
- name: Validate namespace is running
ansible.builtin.include_tasks: validate-namespace-running.yml
- name: Deleting namespace using the bundle
ansible.builtin.command: "{{ '/tmp/' + site_name + '-bundle.sh -x -n ' + namespace }}"
ansible.builtin.command: "{{ '/tmp/' + site_name + '-bundle.sh -x -n ' + namespace | string }}"
register: _bundle
changed_when: _bundle.rc == 0
- name: Validate namespace has been deleted
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/targets/system/tasks/action-start.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
- name: Create Site A resources
skupper.v2.resource:
path: "{{ role_path }}/files/site_a.yml"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
platform: podman
- name: Run the start action
skupper.v2.system:
action: start
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
image: "{{ system_image }}"
register: _system
environment:
Expand Down Expand Up @@ -37,7 +37,7 @@
- name: Run the start action (no change)
skupper.v2.system:
action: start
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
image: "{{ system_image }}"
register: _system
environment:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/targets/system/tasks/action-stop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: Run the stop action
skupper.v2.system:
action: stop
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
image: "{{ system_image }}"
register: _system
- name: Assert stop action performed successfully
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/targets/system/tasks/action-tarball.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
- name: Create Site A resources
skupper.v2.resource:
path: "{{ role_path }}/files/site_a.yml"
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
platform: podman
- name: Run the tarball action
skupper.v2.system:
action: tarball
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
image: "{{ system_image }}"
register: _system
environment:
Expand Down Expand Up @@ -42,15 +42,15 @@
remote_src: true
- name: Installing the tarball bundle
ansible.builtin.command:
cmd: "{{ './install.sh -n ' + namespace }}"
cmd: "{{ './install.sh -n ' + namespace | string }}"
chdir: "{{ '/tmp/' + site_name + '-bundle' }}"
register: _bundle
changed_when: _bundle.rc == 0
- name: Validate namespace is running
ansible.builtin.include_tasks: validate-namespace-running.yml
- name: Deleting namespace using the bundle script
ansible.builtin.command:
cmd: "{{ './install.sh -x -n ' + namespace }}"
cmd: "{{ './install.sh -x -n ' + namespace | string }}"
chdir: "{{ '/tmp/' + site_name + '-bundle' }}"
register: _bundle
changed_when: _bundle.rc == 0
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/targets/system/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: Set facts for system module tests (rootless)
ansible.builtin.set_fact:
namespace_home: "{{ lookup('env', 'HOME') + '/.local/share/skupper/namespaces/' + namespace }}"
namespace_home: "{{ lookup('env', 'HOME') + '/.local/share/skupper/namespaces/' + namespace | string }}"
bundle_path: "{{ lookup('env', 'HOME') + '/.local/share/skupper/bundles/skupper-install-' + site_name + '.sh' }}"
tarball_path: "{{ lookup('env', 'HOME') + '/.local/share/skupper/bundles/skupper-install-' + site_name + '.tar.gz' }}"
when: ansible_real_user_id != 0
- name: Set facts for system module tests (rootful)
ansible.builtin.set_fact:
namespace_home: "{{ '/var/lib/skupper/namespaces/' + namespace }}"
namespace_home: "{{ '/var/lib/skupper/namespaces/' + namespace | string }}"
bundle_path: "{{ '/var/lib/skupper/bundles/skupper-install-' + site_name + '.sh' }}"
tarball_path: "{{ '/var/lib/skupper/bundles/skupper-install-' + site_name + '.tar.gz' }}"
when: ansible_real_user_id == 0
Expand All @@ -30,7 +30,7 @@
- name: Run the stop action
skupper.v2.system:
action: stop
namespace: "{{ namespace }}"
namespace: "{{ namespace | string }}"
failed_when: false
- name: Remove namespace files
ansible.builtin.include_role:
Expand Down
Loading
Loading