Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to treat secrets as mutable #3164

Merged
merged 6 commits into from
Aug 21, 2024

Conversation

MaienM
Copy link
Contributor

@MaienM MaienM commented Aug 14, 2024

Proposed changes

This introduces the flag enableSecretMutable which does for Secrets what the existing enableConfigMapMutable flag does for ConfigMaps. See #1926 for the motivation for this flag. Changes to the type field will still trigger a replacement as this field is immutable.

Related issues (optional)

Fixes #2291.
Fixes #3181.

Copy link

PR is now waiting for a maintainer to run the acceptance tests.
Note for the maintainer: To run the acceptance tests, please comment /run-acceptance-tests on the PR

@MaienM MaienM force-pushed the feature/enable-secret-mutable-flag branch from 9f88514 to 4deb10c Compare August 14, 2024 01:15
Copy link

PR is now waiting for a maintainer to run the acceptance tests.
Note for the maintainer: To run the acceptance tests, please comment /run-acceptance-tests on the PR

@blampe
Copy link
Contributor

blampe commented Aug 16, 2024

/run-acceptance-tests

@pulumi-bot
Copy link
Contributor

@blampe
Copy link
Contributor

blampe commented Aug 16, 2024

Thank you for the contribution! A couple test failures but looks reasonable overall. We'll review this as a team next week.

=== RUN   TestPatchToDiff/Secret_resources_trigger_a_replace_when_enableSecretMutable_is_not_set.
    diff_test.go:331: 
        	Error Trace:	/home/runner/work/pulumi-kubernetes/pulumi-kubernetes/provider/pkg/provider/diff_test.go:331
        	Error:      	Not equal: 
        	            	expected: map[string]*pulumirpc.PropertyDiff{"data.property1":(*pulumirpc.PropertyDiff)(0xc000893a70)}
        	            	actual  : map[string]*pulumirpc.PropertyDiff{"data.property1":(*pulumirpc.PropertyDiff)(0xc000748360)}
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -13,3 +13,3 @@
        	            	   unknownFields: ([]uint8) <nil>,
        	            	-  Kind: (pulumirpc.PropertyDiff_Kind) 5,
        	            	+  Kind: (pulumirpc.PropertyDiff_Kind) 4,
        	            	   InputDiff: (bool) false
        	Test:       	TestPatchToDiff/Secret_resources_trigger_a_replace_when_enableSecretMutable_is_not_set.
=== RUN   TestPatchToDiff/Secret_resources_don't_trigger_a_replace_when_mutable.
=== RUN   TestPatchToDiff/Secret_resources_trigger_a_replace_when_type_changes_even_if_enableSecretMutable_is_set.
    diff_test.go:331: 
        	Error Trace:	/home/runner/work/pulumi-kubernetes/pulumi-kubernetes/provider/pkg/provider/diff_test.go:331
        	Error:      	Not equal: 
        	            	expected: map[string]*pulumirpc.PropertyDiff{"data.property1":(*pulumirpc.PropertyDiff)(0xc000893a70)}
        	            	actual  : map[string]*pulumirpc.PropertyDiff{"type":(*pulumirpc.PropertyDiff)(0xc0007492c0)}
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1,3 +1,3 @@
        	            	 (map[string]*pulumirpc.PropertyDiff) (len=1) {
        	            	- (string) (len=14) "data.property1": (*pulumirpc.PropertyDiff)({
        	            	+ (string) (len=4) "type": (*pulumirpc.PropertyDiff)({
        	            	   state: (impl.MessageState) {
        	Test:       	TestPatchToDiff/Secret_resources_trigger_a_replace_when_type_changes_even_if_enableSecretMutable_is_set.

@MaienM MaienM force-pushed the feature/enable-secret-mutable-flag branch from 4deb10c to 30cc20b Compare August 16, 2024 21:05
Copy link

PR is now waiting for a maintainer to run the acceptance tests.
Note for the maintainer: To run the acceptance tests, please comment /run-acceptance-tests on the PR

This does for `Secret`s what the existing `enableConfigMapMutable` flag
does for `ConfigMap`s.
@MaienM MaienM force-pushed the feature/enable-secret-mutable-flag branch from 30cc20b to 4001e00 Compare August 16, 2024 21:06
Copy link

PR is now waiting for a maintainer to run the acceptance tests.
Note for the maintainer: To run the acceptance tests, please comment /run-acceptance-tests on the PR

@MaienM
Copy link
Contributor Author

MaienM commented Aug 16, 2024

Fixed! One of those was some sloppy copy-pasting in the test itself, the other was an actual logic error that I introduced when I re-marked the type field as always immutable.

Copy link

PR is now waiting for a maintainer to run the acceptance tests.
Note for the maintainer: To run the acceptance tests, please comment /run-acceptance-tests on the PR

@blampe
Copy link
Contributor

blampe commented Aug 19, 2024

/run-acceptance-tests

@pulumi-bot
Copy link
Contributor

Copy link
Contributor

@rquitales rquitales left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for the PR!

Comment on lines 27 to 29
if clients.IsSecret(obj) && !k.enableSecretMutable {
props = append(props, properties{".type", ".stringData", ".data"}...)
} else if kindFields, kindExists := version[gvk.Kind]; kindExists {
Copy link
Contributor

Choose a reason for hiding this comment

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

@MaienM it just occurred to me while adding some detail to #3179 that we should probably respect the immutable field.

In other words, if the secret has immutable: true it should preserve the existing behavior even if the provider has enableSecretMutable. Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, yeah, it's not like trying to treat it as mutable will even work in that case. The same applies to ConfigMaps though, right? I don't think those handle that either right now, that's what I based this code on after all.

I can make a change to handle that, should I also make the same change for ConfigMaps while I'm at it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made the change for this for both Secrets and ConfigMaps. I put the change for the ConfigMaps in a separate commit because I wasn't sure whether you wanted that one, so you can just get rid of that commit if you don't.

Copy link
Contributor

Choose a reason for hiding this comment

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

@MaienM thank you again for the great contribution! I'm very happy this prompted us to uncover the immutable incompatibility and that you were able to fix it while you were in here. I added an E2E test case partly as a sanity check and party to cement the behavior we expect here.

So much has changed with Pulumi and k8s since this behavior was originally introduced that it would make much more sense IMO to make this the default behavior at some point in the future (#3179). I added a note to the changelog to that effect, since it's a potentially disruptive behavioral change.

After I merge this it will be available as a pre-release if you'd like to play around with it.

Copy link

PR is now waiting for a maintainer to run the acceptance tests.
Note for the maintainer: To run the acceptance tests, please comment /run-acceptance-tests on the PR

Copy link

PR is now waiting for a maintainer to run the acceptance tests.
Note for the maintainer: To run the acceptance tests, please comment /run-acceptance-tests on the PR

@blampe blampe force-pushed the feature/enable-secret-mutable-flag branch from 5d5621e to 9affcae Compare August 21, 2024 17:23
Copy link

PR is now waiting for a maintainer to run the acceptance tests.
Note for the maintainer: To run the acceptance tests, please comment /run-acceptance-tests on the PR

@blampe blampe force-pushed the feature/enable-secret-mutable-flag branch from 9affcae to 278cc10 Compare August 21, 2024 17:23
Copy link

PR is now waiting for a maintainer to run the acceptance tests.
Note for the maintainer: To run the acceptance tests, please comment /run-acceptance-tests on the PR

@blampe
Copy link
Contributor

blampe commented Aug 21, 2024

/run-acceptance-tests

@pulumi-bot
Copy link
Contributor

@blampe blampe merged commit 2ec7a1a into pulumi:master Aug 21, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants