mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
kubernetes: port k8s.folder_absent
Achieve complete feature parity between k8s and kubernetes states. Signed-off-by: Flavio Castelli <fcastelli@suse.com>
This commit is contained in:
parent
64e37b6e20
commit
043865bbcb
@ -121,7 +121,8 @@ def label_folder_absent(
|
||||
apiserver=None):
|
||||
'''
|
||||
.. deprecated:: Nitrogen
|
||||
This state is going to be dropped.
|
||||
This state has been moved to :py:func:`kubernetes.node_label_folder_absent
|
||||
<salt.states.kubernetes.node_label_folder_absent`.
|
||||
|
||||
Ensure the label folder doesn't exist on the kube node.
|
||||
|
||||
@ -139,9 +140,10 @@ def label_folder_absent(
|
||||
ret = __salt__['k8s.folder_absent'](name, node, apiserver)
|
||||
|
||||
msg = (
|
||||
'The k8s.folder_present state has been dropped. '
|
||||
'Update your SLS to use the new '
|
||||
'The k8s.label_folder_absent state has been replaced by '
|
||||
'kubernetes.node_label_folder_absent. Update your SLS to use the new '
|
||||
'function name to get rid of this warning.'
|
||||
|
||||
)
|
||||
salt.utils.warn_until('Fluorine', msg)
|
||||
ret.setdefault('warnings', []).append(msg)
|
||||
|
@ -876,6 +876,57 @@ def node_label_absent(name, node, **kwargs):
|
||||
return ret
|
||||
|
||||
|
||||
def node_label_folder_absent(name, node, **kwargs):
|
||||
'''
|
||||
Ensures the label folder doesn't exist on the specified node.
|
||||
|
||||
name
|
||||
The name of label folder
|
||||
|
||||
node
|
||||
The name of the node
|
||||
'''
|
||||
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': False,
|
||||
'comment': ''}
|
||||
labels = __salt__['kubernetes.node_labels'](node, **kwargs)
|
||||
|
||||
folder = name.strip("/") + "/"
|
||||
labels_to_drop = []
|
||||
new_labels = []
|
||||
for label in labels:
|
||||
if label.startswith(folder):
|
||||
labels_to_drop.append(label)
|
||||
else:
|
||||
new_labels.append(label)
|
||||
|
||||
if not labels_to_drop:
|
||||
ret['result'] = True if not __opts__['test'] else None
|
||||
ret['comment'] = 'The label folder does not exist'
|
||||
return ret
|
||||
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'The label folder is going to be deleted'
|
||||
ret['result'] = None
|
||||
return ret
|
||||
|
||||
for label in labels_to_drop:
|
||||
__salt__['kubernetes.node_remove_label'](
|
||||
node_name=node,
|
||||
label_name=label,
|
||||
**kwargs)
|
||||
|
||||
ret['result'] = True
|
||||
ret['changes'] = {
|
||||
'kubernetes.node_label_folder_absent': {
|
||||
'new': new_labels, 'old': labels.keys()}}
|
||||
ret['comment'] = 'Label folder removed from node'
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def node_label_present(
|
||||
name,
|
||||
node,
|
||||
|
Loading…
Reference in New Issue
Block a user