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

Correctly merge provided opts for k8s resources #850

Merged
merged 1 commit into from
Oct 16, 2019

Conversation

lblackstone
Copy link
Member

@lblackstone lblackstone commented Oct 16, 2019

Proposed changes

It seems like the construct we were using in case of empty opts was not working properly for the auto-aliases. This change fixes the linked issue, but I don't quite understand what the problem was.

We were not merging user-provided opts properly in k8s resources. The bug reported in #849 was caused by mutating the provided opts object in multiple resources, which resulted in every resource being aliased to every other resource type sharing that object.

This also fixes the same issue for additionalSecretOutputs.

Related issues (optional)

Fixes #849

@@ -85,7 +85,6 @@ import { getVersion } from "../../version";
{{#Aliases}}
{ parent: opts.parent, type: "{{.}}", name: name },
{{/Aliases}}
...((opts && opts.aliases) || []),
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this will cause us to drop any user-specified aliases. I don't think we want that. Did you try changing ((opts && opts.alaises) || []) to ...(opts.aliases || [])?

Copy link
Member Author

Choose a reason for hiding this comment

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

            { parent: opts.parent, type: "kubernetes:apps/v1:Deployment", name: name },
            { parent: opts.parent, type: "kubernetes:apps/v1beta1:Deployment", name: name },
            { parent: opts.parent, type: "kubernetes:apps/v1beta2:Deployment", name: name },
            { parent: opts.parent, type: "kubernetes:extensions/v1beta1:Deployment", name: name },
            ...(opts.aliases || []),
        ];

still causes a panic.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I'll bet know what the issue is. We're mutating an object that is passed in by the caller. We shouldn't do that. In the case of the original bug, I think we're adding aliases for multiple resources to the same opts dictionary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, you're right. I've updated the PR to fix. Looks like we were already handling this properly in the Python SDK.

@lblackstone lblackstone changed the title Fix auto-alias for empty opts Correctly merge provided opts for k8s resources Oct 16, 2019
@lblackstone
Copy link
Member Author

@pgavlin @CyrusNajmabadi Can you verify that I'm merging the opts properly now? Relevant part of the PR is https://github.com/pulumi/pulumi-kubernetes/pull/850/files#diff-9ccac45941821640b7c297dea985a016 (kind.ts.mustache) -- the rest is generated from that.

]
})

super(MutatingWebhookConfiguration.__pulumiType, name, props, _opts);
Copy link
Member

Choose a reason for hiding this comment

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

Indentation looks off above.

Also, our lint rules should disallow use of let and require const here.

Copy link
Member

Choose a reason for hiding this comment

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

Also - it's pretty ugly to emit all this merging and empty lists and spread across lines. I get that this is generated code - but it is code users will see frequently on Go To Definition - are there reasonable ways to clean this all up a bit?

Copy link
Member

@lukehoban lukehoban Oct 16, 2019

Choose a reason for hiding this comment

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

Specifically I'm talking about things like this which I see all over the generated output now:

        let _opts = pulumi.mergeOptions(opts, {
            additionalSecretOutputs: [
            ],
            aliases: [
            ]
        })

Copy link
Member Author

Choose a reason for hiding this comment

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

Indentation looks off above.

Also, our lint rules should disallow use of let and require const here.

Fixed

Also - it's pretty ugly to emit all this merging and empty lists and spread across lines. I get that this is generated code - but it is code users will see frequently on Go To Definition - are there reasonable ways to clean this all up a bit?

There may be a way to do so with mustache templates, but I couldn't figure out how when I added the auto-alias feature.

@lblackstone
Copy link
Member Author

@lukehoban Since your comments were on style/formatting, I'm going to merge now in the interest of making the fix available to test. I can follow up for any further comments.

@lblackstone lblackstone merged commit 558e731 into master Oct 16, 2019
@pulumi-bot pulumi-bot deleted the lblackstone/alias-fix branch October 16, 2019 22:46
additionalSecretOutputs: [
],
aliases: [
]
Copy link
Contributor

Choose a reason for hiding this comment

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

this is super unfortunate.

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.

Bugs and crashes from resource auto-aliasing.
4 participants