1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-02-04 07:11:49 +00:00

Add support for kube yaml files with multi-documents (#724)

* Add support for multi doc kube yaml

Signed-off-by: nishipy <goodisonev4@gmail.com>

* Update to skip yamllint

Signed-off-by: nishipy <goodisonev4@gmail.com>

* Update ignores for sanity tests

Signed-off-by: nishipy <goodisonev4@gmail.com>

* Update discover_pods()

Signed-off-by: nishipy <goodisonev4@gmail.com>

* Update test for podman_play

Signed-off-by: nishipy <goodisonev4@gmail.com>

---------

Signed-off-by: nishipy <goodisonev4@gmail.com>
This commit is contained in:
nishipy 2024-03-23 20:55:44 +09:00 committed by GitHub
parent 890ae35360
commit 44b2ce69e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 91 additions and 8 deletions

View file

@ -249,12 +249,10 @@ class PodmanKubeManagement:
if self.module.params['kube_file']:
if HAS_YAML:
with open(self.module.params['kube_file']) as f:
pod = yaml.safe_load(f)
if 'metadata' in pod:
pod_name = pod['metadata'].get('name')
else:
self.module.fail_json(
"No metadata in Kube file!\n%s" % pod)
pods = list(yaml.safe_load_all(f))
for pod in pods:
if 'metadata' in pod and pod['kind'] in ['Deployment', 'Pod']:
pod_name = pod['metadata'].get('name')
else:
with open(self.module.params['kube_file']) as text:
# the following formats are matched for a kube name:
@ -266,7 +264,7 @@ class PodmanKubeManagement:
if re_pod:
pod_name = re_pod.group(1)
if not pod_name:
self.module.fail_json("Deployment doesn't have a name!")
self.module.fail_json("This Kube file doesn't have Pod or Deployment!")
# Find all pods
all_pods = ''
# In case of one pod or replicasets

View file

@ -0,0 +1,27 @@
kind: ConfigMap
metadata:
name: foo
data:
FOO: bar
---
apiVersion: v1
kind: Pod
metadata:
name: foobar
spec:
containers:
- command:
- top
name: container-1
image: alpine
envFrom:
- configMapRef:
name: foo
optional: false
---
apiVersion: v1
kind: ConfigMap
metadata:
name: foo2
data:
FOO2: bar2

View file

@ -145,4 +145,12 @@
size: 10mb
userns: host
kube_dir: /tmp
kube_file: play-pod.yaml
kube_file: play-pod.yaml
- name: Test play kube with multi doc yaml
include_tasks: play-multi-yaml.yml
vars:
ansible_python_interpreter: "/usr/bin/python"
kube_dir: /tmp
kube_file: multi-yaml.yml
target_container: foobar-container-1

View file

@ -0,0 +1,40 @@
---
- name: Test kube play wih multi doc yaml
block:
- name: Copy kube file
copy:
src: "{{ kube_file }}"
dest: "{{ kube_dir }}/{{ kube_file }}"
remote_src: false
- name: Create Pod with multi doc yaml
containers.podman.podman_play:
executable: "{{ test_executable | default('podman') }}"
kube_file: "{{ kube_dir }}/{{ kube_file }}"
state: started
recreate: true
register: play_pod
- name: Get pod info
containers.podman.podman_container_info:
executable: "{{ test_executable | default('podman') }}"
name: "{{ target_container }}"
register: info
- name: Check if an expected container is running
assert:
that:
- info.containers.0.State.Running == true
- '"FOO=bar" in info.containers.0.Config.Env'
- name: Cleanup pod
containers.podman.podman_play:
executable: "{{ test_executable | default('podman') }}"
kube_file: "{{ kube_dir }}/{{ kube_file }}"
state: absent
register: remove_pod
- name: Check if the pod was removed as expected
assert:
that:
- remove_pod is changed

View file

@ -1,2 +1,3 @@
tests/integration/targets/connection_buildah/runme.sh shellcheck:SC2086
tests/integration/targets/connection_podman/runme.sh shellcheck:SC2086
tests/integration/targets/podman_play/tasks/files/multi-yaml.yml yamllint!skip

View file

@ -1,2 +1,3 @@
tests/integration/targets/connection_buildah/runme.sh shellcheck:SC2086
tests/integration/targets/connection_podman/runme.sh shellcheck:SC2086
tests/integration/targets/podman_play/tasks/files/multi-yaml.yml yamllint!skip

View file

@ -1,2 +1,3 @@
tests/integration/targets/connection_buildah/runme.sh shellcheck:SC2086
tests/integration/targets/connection_podman/runme.sh shellcheck:SC2086
tests/integration/targets/podman_play/tasks/files/multi-yaml.yml yamllint!skip

View file

@ -1,2 +1,3 @@
tests/integration/targets/connection_buildah/runme.sh shellcheck:SC2086
tests/integration/targets/connection_podman/runme.sh shellcheck:SC2086
tests/integration/targets/podman_play/tasks/files/multi-yaml.yml yamllint!skip

View file

@ -1,2 +1,3 @@
tests/integration/targets/connection_buildah/runme.sh shellcheck:SC2086
tests/integration/targets/connection_podman/runme.sh shellcheck:SC2086
tests/integration/targets/podman_play/tasks/files/multi-yaml.yml yamllint!skip

View file

@ -1,2 +1,3 @@
tests/integration/targets/connection_buildah/runme.sh shellcheck:SC2086
tests/integration/targets/connection_podman/runme.sh shellcheck:SC2086
tests/integration/targets/podman_play/tasks/files/multi-yaml.yml yamllint!skip

View file

@ -1,2 +1,3 @@
tests/integration/targets/connection_buildah/runme.sh shellcheck:SC2086
tests/integration/targets/connection_podman/runme.sh shellcheck:SC2086
tests/integration/targets/podman_play/tasks/files/multi-yaml.yml yamllint!skip

View file

@ -1,2 +1,3 @@
tests/integration/targets/connection_buildah/runme.sh shellcheck:SC2086
tests/integration/targets/connection_podman/runme.sh shellcheck:SC2086
tests/integration/targets/podman_play/tasks/files/multi-yaml.yml yamllint!skip

View file

@ -1,2 +1,3 @@
tests/integration/targets/connection_buildah/runme.sh shellcheck:SC2086
tests/integration/targets/connection_podman/runme.sh shellcheck:SC2086
tests/integration/targets/podman_play/tasks/files/multi-yaml.yml yamllint!skip

View file

@ -1,2 +1,3 @@
tests/integration/targets/connection_buildah/runme.sh shellcheck:SC2086
tests/integration/targets/connection_podman/runme.sh shellcheck:SC2086
tests/integration/targets/podman_play/tasks/files/multi-yaml.yml yamllint!skip