Skip to content

fix: hash the real content when ConfigMap data is not a map - #6262

Open
PragalvaXFREZ wants to merge 1 commit into
kubernetes-sigs:masterfrom
PragalvaXFREZ:fix-hasher-non-map-data
Open

fix: hash the real content when ConfigMap data is not a map#6262
PragalvaXFREZ wants to merge 1 commit into
kubernetes-sigs:masterfrom
PragalvaXFREZ:fix-hasher-non-map-data

Conversation

@PragalvaXFREZ

Copy link
Copy Markdown

getNodeValues collects the fields that feed the ConfigMap/Secret name suffix hash. For any non-scalar field it marshals the node to JSON and decodes it into a map[string]interface{}, discarding the decode error:

// data, binaryData and stringData are all maps
var v map[string]interface{}
json.Unmarshal(vs, &v)

The comment holds for the value kustomize generates itself, but a patches entry can replace data with any JSON value. When it is not an object the decode fails, v stays nil, and the hash is computed over "data": null. Every ConfigMap in that shape hashes to the same suffix no matter what it contains.

Two builds that differ only in content, using a JSON 6902 patch that replaces /data with a sequence:

data:
- A          ->  name: cm-dk855m5d49
data:
- B          ->  name: cm-dk855m5d49

The same pair with an object value behaves correctly, which shows the hash is computed after patches over the final content rather than over the pre-patch value:

data: {k: A}  ->  name: cm-c74h26c25g
data: {k: B}  ->  name: cm-t6kk6cfb8c

The suffix exists so that changed content produces a new object name. Here the content changes and the name does not, so a rollout is silently skipped, and two such ConfigMaps applied to one namespace collide.

Decoding into interface{} keeps every hash that is correct today byte identical, since a JSON object still decodes to map[string]interface{} and encodeConfigMap's values["binaryData"].(map[string]interface{}) assertion is unaffected. Only the currently broken non-object case changes. Confirmed by diffing kustomize build output from both binaries across ConfigMap (plain, with binaryData, empty) and Secret (Opaque, kubernetes.io/tls) generators: identical.

After the fix the two sequence cases hash to cm-9k92ch6bch and cm-td45tkc82d.

Adds a regression test to hasher_test.go; it fails on master with different data hashed identically: "dk855m5d49". TestConfigMapHash and TestSecretHash still pass, and the api module suite shows no new failures.

@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 9, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: PragalvaXFREZ
Once this PR has been reviewed and has the lgtm label, please assign varshaprasad96 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @PragalvaXFREZ!

It looks like this is your first PR to kubernetes-sigs/kustomize 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kustomize has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @PragalvaXFREZ. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 9, 2026
getNodeValues collects the fields that feed the ConfigMap/Secret name
suffix hash. For any non-scalar field it marshals the node to JSON and
decodes it into a map[string]interface{}, discarding the decode error:

	// data, binaryData and stringData are all maps
	var v map[string]interface{}
	json.Unmarshal(vs, &v)

The comment holds for the value kustomize generates itself, but a
patches entry can replace data with any JSON value. When it is not an
object the decode fails, v stays nil, and the hash is computed over
"data": null. Every ConfigMap in that shape hashes to the same suffix
no matter what it contains.

Two builds differing only in content, using a JSON 6902 patch that
replaces /data with a sequence:

	data:
	- A          ->  name: cm-dk855m5d49
	data:
	- B          ->  name: cm-dk855m5d49

The same pair with an object value is hashed correctly, which shows the
hash is computed after patches over the final content:

	data: {k: A}  ->  name: cm-c74h26c25g
	data: {k: B}  ->  name: cm-t6kk6cfb8c

The suffix exists so that changed content produces a new object name.
Here the content changes and the name does not, so a rollout is silently
skipped and two such ConfigMaps applied to one namespace collide.

Decoding into interface{} keeps every hash that is correct today byte
identical, since a JSON object still decodes to map[string]interface{}
and the values["binaryData"].(map[string]interface{}) assertion in
encodeConfigMap is unaffected. Only the broken non-object case changes.
Confirmed by diffing kustomize build output from both binaries across
ConfigMap (plain, with binaryData, empty) and Secret (Opaque,
kubernetes.io/tls) generators: identical.

After the fix the two sequence cases hash to cm-9k92ch6bch and
cm-td45tkc82d.

The added test fails on master with:

	different data hashed identically: "dk855m5d49"

Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
@PragalvaXFREZ
PragalvaXFREZ force-pushed the fix-hasher-non-map-data branch from 737a3d8 to 4d74d98 Compare September 9, 2026 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant