Fix Secret check_mode (#343)

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.
This commit is contained in:
Mike Graves
2021-01-14 11:05:11 -05:00
committed by GitHub
parent 003d802065
commit b26afc3518
4 changed files with 131 additions and 5 deletions

View File

@@ -0,0 +1,39 @@
# -*- 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"