This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
4 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bugfixes: | ||
- k8s - fix check_mode always showing changes when using stringData on Secrets (https://github.com/ansible-collections/community.kubernetes/issues/282). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |