Skip to content

Conversation

@jamiedel818
Copy link

@jamiedel818 jamiedel818 commented Oct 9, 2025

This pull requests extends Pentagon's secret mapping config to allow for extra labels to be added to the generated Kubernetes secret(s).

additionalSecretLabels can optionally be added to a mapping config. additionalSecretLabels will be merged with the top level default label config value.

Extended existing test cases to account for scenarios where no additional labels have been provided, ensuring the default label still exists. Introduced new test cases where additional labels are provided, ensuring the default label still exists.

reflector.go Outdated
Comment on lines 190 to 191
labels := make(map[string]string)
maps.Copy(labels, mapping.AdditionalSecretLabels)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is equivalent to labels := maps.Clone(mapping.AdditionalSecretLabels)

Another option would be to only replace the make call with the map literal it's replacing (map[string]string{LabelKey: r.labelValue}). Then it's clear that we don't expect to have additional labels most of the time.

Copy link
Author

@jamiedel818 jamiedel818 Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I just pushed a change that uses the latter approach you suggested to maintain clarity.

Copy link
Collaborator

@sergiosalvatore sergiosalvatore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the back and forth...

reflector.go Outdated
Comment on lines 190 to 191
labels := map[string]string{LabelKey: r.labelValue}
maps.Copy(labels, mapping.AdditionalSecretLabels)
Copy link
Collaborator

@sergiosalvatore sergiosalvatore Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know David already commented on this code, but I think it actually needs to be written the other way in order to not mess with the reconciliation logic here and here.

Suggested change
labels := map[string]string{LabelKey: r.labelValue}
maps.Copy(labels, mapping.AdditionalSecretLabels)
labels := maps.Clone(mapping.AdditionalSecretLabels)
labels[LabelKey] = r.labelValue

This ensures that the label key that pentagon uses to find its secrets is always set and can't be accidentally overwritten. I'd suggest adding a test that confirms this. I suppose we can also add some extra validation to the config to make sure that the user isn't trying to overwrite the pentagon label with one of their own.

Copy link
Author

@jamiedel818 jamiedel818 Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When writing the tests for this I noticed that if AdditionalSecretLabels is not passed in the config, making it nil, the result of labels := maps.Clone(mapping.AdditionalSecretLabels) is nil.

To avoid this, I've decided to initialize AdditionalSecretLabels in SetDefaults if they are not specified by the user. This avoids any potential nil map panics in the code.

Otherwise, I can do a nil check on AdditionalSecretLabels in the reflector code after cloning.

Let me know what you think.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks... While what you did is perfectly fine, it might actually be more "ergonomic" to do a nil check in the reflector code and not bother defaulting it to an empty map in SetDefaults. That would allow you to avoid initializing it in the tests and everything "just works."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants