mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
k8s append_hash (#48830)
* Add append_hash functionality to k8s module append_hash adds a hash based on the contents of a ConfigMap or Secret to the name - this enables immutable ConfigMaps and Secrets. * Provide k8s_config_resource_name plugin The k8s_config_resource_name filter plugin provides a means of determining the name of ConfigMaps and Secrets created with append_hash * Add changelog fragment * fix failing tests * Update openshift version needed for append_hash
This commit is contained in:
committed by
John R Barker
parent
c3770bf6f2
commit
960ebd981f
40
lib/ansible/plugins/filter/k8s.py
Normal file
40
lib/ansible/plugins/filter/k8s.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) 2017 Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {
|
||||
'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'
|
||||
}
|
||||
|
||||
|
||||
try:
|
||||
from openshift.helper.hashes import generate_hash
|
||||
HAS_GENERATE_HASH = True
|
||||
except ImportError:
|
||||
HAS_GENERATE_HASH = False
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
|
||||
|
||||
def k8s_config_resource_name(resource):
|
||||
if not HAS_GENERATE_HASH:
|
||||
raise AnsibleFilterError("k8s_config_resource_name requires openshift>=0.7.2")
|
||||
try:
|
||||
return resource['metadata']['name'] + '-' + generate_hash(resource)
|
||||
except KeyError:
|
||||
raise AnsibleFilterError("resource must have a metadata.name key to generate a resource name")
|
||||
|
||||
|
||||
# ---- Ansible filters ----
|
||||
class FilterModule(object):
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
'k8s_config_resource_name': k8s_config_resource_name
|
||||
}
|
||||
Reference in New Issue
Block a user