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

[sdk/go] Embed PluginDownloadURL during codegen #8690

Merged
merged 9 commits into from
Jan 11, 2022

Conversation

iwahbe
Copy link
Member

@iwahbe iwahbe commented Jan 5, 2022

Description

Fixes # (issue)

Embed PluginDownloadURLs in resource creation requests from codegen.

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

@iwahbe iwahbe requested a review from justinvp January 5, 2022 21:49
@iwahbe iwahbe self-assigned this Jan 5, 2022
@github-actions
Copy link

github-actions bot commented Jan 5, 2022

Diff for pulumi-azuread with merge commit 8ef9b34

@github-actions
Copy link

github-actions bot commented Jan 5, 2022

Diff for pulumi-random with merge commit 8ef9b34

@github-actions
Copy link

github-actions bot commented Jan 5, 2022

Diff for pulumi-kubernetes with merge commit 8ef9b34

@github-actions
Copy link

github-actions bot commented Jan 5, 2022

Diff for pulumi-gcp with merge commit 8ef9b34

@github-actions
Copy link

github-actions bot commented Jan 5, 2022

Diff for pulumi-azure with merge commit 8ef9b34

@github-actions
Copy link

github-actions bot commented Jan 5, 2022

Diff for pulumi-aws with merge commit 8ef9b34

pkg/codegen/go/gen.go Outdated Show resolved Hide resolved
// that if a user adds their own separate PluginDownloadURL, we won't
// override it.
if url := pkg.pkg.PluginDownloadURL; url != "" {
fmt.Fprintf(w, "\topts = append([]pulumi.ResourceOption{pulumi.PluginDownloadURL(%q)}, opts...)\n", url)
Copy link
Member

@justinvp justinvp Jan 5, 2022

Choose a reason for hiding this comment

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

@pgavlin, quick question that's orthogonal to this PR, but kind of related:

Shouldn't we be setting the default version in here like we do in the other languages, or am I missing something?

fmt.Fprintf(w, " Version = Utilities.Version,\n")

fmt.Fprintf(w, " if (!opts.version) {\n")
fmt.Fprintf(w, " opts = pulumi.mergeOptions(opts, { version: utilities.getVersion()});\n")
fmt.Fprintf(w, " }\n")

fmt.Fprintf(w, " if opts.version is None:\n")
fmt.Fprintf(w, " opts.version = _utilities.get_version()\n")

Maybe we didn't do this for Go because the version info for Go isn't readily available? (Although, we did later add PkgVersion used in resource module registrations; so perhaps we could consider using that, if it is desirable).

Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I'm not sure why we didn't do this in Go. It does seem like we should. I'm also not sure how we arrived at PkgVersion--any idea if there's a reason we didn't just embed the version statically? The reflection-based code used by PkgVersion is essentially static, I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't embed the version statically because we can't trust that the version supplied in the schema is correct. This is the same reason why #8521 exists, and is blocked. Injecting the version at codegen time would require changing how our provider makefile work.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yep, thank you for the reminder. I wonder if we should switch this to using a //go:embed and a parse in init so that we can get a real version. This would be akin to the solutions we use for the other language. More concretely, we could e.g. have the Go code generator emit a dummy version.txt file that is embedded into the package, then have the Makefile update the contents of that file with the actual server. The contents of the file would be parsed into a real version during the package's init function.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we are willing to touch every Makefile to actualize that change, I think we should instead attempt to find a safe way to embed version into the binary (if at all possible).

Copy link
Member

Choose a reason for hiding this comment

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

I think we should instead attempt to find a safe way to embed version into the binary (if at all possible).

I would love it if we could find a way to do this, but I'll admit that I'm pessimistic about making that happen any time soon. I think that taking a tactical fix--even though it requires updating Makefiles--is a chance for us to not let perfect be the enemy of better.

Copy link
Member

Choose a reason for hiding this comment

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

we could e.g. have the Go code generator emit a dummy version.txt file that is embedded into the package, then have the Makefile update the contents of that file with the actual server

I still don't quite follow how this would work for go modules. Say we generate an SDK for a foo provider, emitted at github.com/pulumi/pulumi-foo/sdk/go/foo. Versions are tagged with git tags (e.g. v1.2.3 and sdk/v1.2.3). Wouldn't we have to commit the version.txt file before tagging it? I don't see how the Makefile helps. When I use the foo module from my program, our Makefile is not involved.

Copy link
Member

Choose a reason for hiding this comment

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

That's a good point. For Go, it's the push to the git remote that's the publishing step, so even if we took my suggestion we'd still be emitting the wrong version.

@github-actions
Copy link

github-actions bot commented Jan 5, 2022

Diff for pulumi-azure-native with merge commit 8ef9b34

@codecov
Copy link

codecov bot commented Jan 5, 2022

Codecov Report

Merging #8690 (551f2fc) into master (9a5ba09) will increase coverage by 2.54%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8690      +/-   ##
==========================================
+ Coverage   58.83%   61.37%   +2.54%     
==========================================
  Files         557      500      -57     
  Lines       94165    85339    -8826     
  Branches     1385        0    -1385     
==========================================
- Hits        55398    52377    -3021     
+ Misses      35497    29869    -5628     
+ Partials     3270     3093     -177     
Impacted Files Coverage Δ
pkg/codegen/go/gen.go 89.70% <100.00%> (+0.50%) ⬆️
...dk/go/common/resource/plugin/langruntime_plugin.go 67.29% <0.00%> (-1.89%) ⬇️
sdk/nodejs/proto/engine_grpc_pb.js
sdk/nodejs/runtime/debuggable.ts
sdk/nodejs/runtime/closure/utils.ts
sdk/nodejs/proto/provider_grpc_pb.js
sdk/nodejs/proto/engine_pb.js
sdk/nodejs/runtime/settings.ts
sdk/nodejs/runtime/invoke.ts
sdk/nodejs/proto/resource_pb.js
... and 53 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9a5ba09...551f2fc. Read the comment docs.

@iwahbe iwahbe requested a review from justinvp January 6, 2022 01:33
@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-azuread with merge commit c96f0e8

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-random with merge commit c96f0e8

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-kubernetes with merge commit c96f0e8

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-gcp with merge commit c96f0e8

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-random with merge commit dd1ebb0

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-azuread with merge commit dd1ebb0

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-kubernetes with merge commit dd1ebb0

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-gcp with merge commit dd1ebb0

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-azure with merge commit c96f0e8

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-aws with merge commit c96f0e8

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-azure with merge commit dd1ebb0

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-aws with merge commit dd1ebb0

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-azure-native with merge commit c96f0e8

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-azure-native with merge commit dd1ebb0

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-azuread with merge commit a67b5dd

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-kubernetes with merge commit a67b5dd

@github-actions
Copy link

github-actions bot commented Jan 6, 2022

Diff for pulumi-gcp with merge commit a67b5dd

@github-actions
Copy link

github-actions bot commented Jan 7, 2022

Diff for pulumi-azure with merge commit a67b5dd

@github-actions
Copy link

github-actions bot commented Jan 7, 2022

Diff for pulumi-aws with merge commit a67b5dd

@github-actions
Copy link

github-actions bot commented Jan 7, 2022

Diff for pulumi-azure-native with merge commit a67b5dd

@iwahbe iwahbe requested a review from pgavlin January 7, 2022 02:13
pkg/codegen/go/gen.go Outdated Show resolved Hide resolved
pkg/codegen/go/gen.go Outdated Show resolved Hide resolved
}

// PkgResourceDefaultOpts provides package level defaults to pulumi.OptionResource.
func PkgResourceDefaultOpts(opts []pulumi.ResourceOption) []pulumi.ResourceOption {
Copy link
Member

Choose a reason for hiding this comment

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

I realize the existing PkgVersion is exported (capitalized), but I doubt that was intentional. I am wondering if these new functions should be unexported (lowercase)... I don't think anyone will need to be calling these as part of an SDK's public API directly.

(Separately, it might be worth revisiting PkgVersion, making it lowercase).

Copy link
Member Author

Choose a reason for hiding this comment

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

I capitalized Pkg%sDefaultOpts because I assumed there was a good reason why PkgVersion was capitalized. I can change that.

@@ -3526,7 +3531,7 @@ func GeneratePackage(tool string, pkg *schema.Package) (map[string][]byte, error
packageRegex = fmt.Sprintf("^%s(/v\\d+)?", pkg.importBasePath)
}

_, err := fmt.Fprintf(buffer, utilitiesFile, packageRegex)
_, err := fmt.Fprintf(buffer, UtilitiesFile(pkg), packageRegex)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to make sure pkg.needsUtils is set to true if there are any resources or invokes? Otherwise, is it possible the utilities file won't be emitted?

Copy link
Member Author

Choose a reason for hiding this comment

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

insertPkgDefaultsOptsCall sets pkg.needsUtils = true.

@iwahbe iwahbe requested a review from justinvp January 7, 2022 20:51
@github-actions
Copy link

github-actions bot commented Jan 7, 2022

Diff for pulumi-random with merge commit e3a3f82

@github-actions
Copy link

github-actions bot commented Jan 7, 2022

Diff for pulumi-azuread with merge commit e3a3f82

@github-actions
Copy link

github-actions bot commented Jan 7, 2022

Diff for pulumi-kubernetes with merge commit e3a3f82

@github-actions
Copy link

github-actions bot commented Jan 7, 2022

Diff for pulumi-gcp with merge commit e3a3f82

@github-actions
Copy link

github-actions bot commented Jan 7, 2022

Diff for pulumi-azure with merge commit e3a3f82

@github-actions
Copy link

github-actions bot commented Jan 7, 2022

Diff for pulumi-aws with merge commit e3a3f82

@github-actions
Copy link

github-actions bot commented Jan 7, 2022

Diff for pulumi-azure-native with merge commit e3a3f82

@iwahbe iwahbe changed the title Embed PluginDownloadURL during codegen [sdk/go] Embed PluginDownloadURL during codegen Jan 8, 2022
Copy link
Member

@justinvp justinvp left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions
Copy link

Diff for pulumi-random with merge commit c4490e1

@github-actions
Copy link

Diff for pulumi-azuread with merge commit c4490e1

@github-actions
Copy link

Diff for pulumi-kubernetes with merge commit c4490e1

@github-actions
Copy link

Diff for pulumi-gcp with merge commit c4490e1

@github-actions
Copy link

Diff for pulumi-azure with merge commit c4490e1

@github-actions
Copy link

Diff for pulumi-aws with merge commit c4490e1

@github-actions
Copy link

Diff for pulumi-azure-native with merge commit c4490e1

@iwahbe iwahbe merged commit 27f761d into master Jan 11, 2022
@pulumi-bot pulumi-bot deleted the iwahbe/go-codegen-embed-PluginDownloadURL branch January 11, 2022 01:38
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.

None yet

3 participants