mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-03-28 14:23:04 +00:00
When adding a Secret and using stringData, check_mode will always show changes. An existing resource fetched from Kubernetes will have the stringData already base64 encoded and merged into the data attribute. This change performs the base64 encoding and merging with the provided definition to more accurately represent the current state of the cluster. This change only affects check_mode. When making any changes to the cluster the stringData is passed along as provided in the definition. Closes #282.
40 lines
1013 B
Python
40 lines
1013 B
Python
# -*- coding: utf-8 -*-
|
|
# Copyright: (c) 2021, 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
|
|
|
|
|
|
from ansible_collections.community.kubernetes.plugins.module_utils.common import (
|
|
_encode_stringdata,
|
|
)
|
|
|
|
|
|
def test_encode_stringdata_modifies_definition():
|
|
definition = {
|
|
"apiVersion": "v1",
|
|
"kind": "Secret",
|
|
"type": "Opaque",
|
|
"stringData": {
|
|
"mydata": "ansiβle"
|
|
}
|
|
}
|
|
res = _encode_stringdata(definition)
|
|
assert "stringData" not in res
|
|
assert res["data"]["mydata"] == "YW5zac6ybGU="
|
|
|
|
|
|
def test_encode_stringdata_does_not_modify_data():
|
|
definition = {
|
|
"apiVersion": "v1",
|
|
"kind": "Secret",
|
|
"type": "Opaque",
|
|
"data": {
|
|
"mydata": "Zm9vYmFy"
|
|
}
|
|
}
|
|
res = _encode_stringdata(definition)
|
|
assert res["data"]["mydata"] == "Zm9vYmFy"
|