Skip to content

Commit

Permalink
recursive option for kube ansible module (kubernetes-sigs#4273)
Browse files Browse the repository at this point in the history
kube ansible module can be used with recursive: true
which sill process the directory used in -f, --filename recursively
  • Loading branch information
etharendil authored and k8s-ci-robot committed Feb 26, 2019
1 parent 131c3d4 commit 063faaa
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions library/kube.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@
latest handles creating or updating based on existence,
reloaded handles updating resource(s) definition using definition file,
stopped handles stopping resource(s) based on other options.
recursive:
required: false
default: false
description:
- Process the directory used in -f, --filename recursively.
Useful when you want to manage related manifests organized
within the same directory.
requirements:
- kubectl
author: "Kenny Jones (@kenjones-cisco)"
Expand Down Expand Up @@ -120,12 +127,14 @@ def __init__(self, module):
if module.params.get('namespace'):
self.base_cmd.append('--namespace=' + module.params.get('namespace'))


self.all = module.params.get('all')
self.force = module.params.get('force')
self.name = module.params.get('name')
self.filename = [f.strip() for f in module.params.get('filename') or []]
self.resource = module.params.get('resource')
self.label = module.params.get('label')
self.recursive = module.params.get('recursive')

def _execute(self, cmd):
args = self.base_cmd + cmd
Expand Down Expand Up @@ -155,6 +164,9 @@ def create(self, check=True, force=True):
if force:
cmd.append('--force')

if self.recursive:
cmd.append('--recursive={}'.format(self.recursive))

if not self.filename:
self.module.fail_json(msg='filename required to create')

Expand All @@ -169,6 +181,9 @@ def replace(self, force=True):
if force:
cmd.append('--force')

if self.recursive:
cmd.append('--recursive={}'.format(self.recursive))

if not self.filename:
self.module.fail_json(msg='filename required to reload')

Expand All @@ -185,6 +200,8 @@ def delete(self):

if self.filename:
cmd.append('--filename=' + ','.join(self.filename))
if self.recursive:
cmd.append('--recursive={}'.format(self.recursive))
else:
if not self.resource:
self.module.fail_json(msg='resource required to delete without filename')
Expand All @@ -203,13 +220,18 @@ def delete(self):
if self.force:
cmd.append('--ignore-not-found')

if self.recursive:
cmd.append('--recursive={}'.format(self.recursive))

return self._execute(cmd)

def exists(self):
cmd = ['get']

if self.filename:
cmd.append('--filename=' + ','.join(self.filename))
if self.recursive:
cmd.append('--recursive={}'.format(self.recursive))
else:
if not self.resource:
self.module.fail_json(msg='resource required without filename')
Expand Down Expand Up @@ -242,6 +264,8 @@ def stop(self):

if self.filename:
cmd.append('--filename=' + ','.join(self.filename))
if self.recursive:
cmd.append('--recursive={}'.format(self.recursive))
else:
if not self.resource:
self.module.fail_json(msg='resource required to stop without filename')
Expand Down Expand Up @@ -278,6 +302,7 @@ def main():
all=dict(default=False, type='bool'),
log_level=dict(default=0, type='int'),
state=dict(default='present', choices=['present', 'absent', 'latest', 'reloaded', 'stopped']),
recursive=dict(default=False, type='bool'),
),
mutually_exclusive=[['filename', 'list']]
)
Expand Down

0 comments on commit 063faaa

Please sign in to comment.