-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
Diff for pulumi-azuread with merge commit 8ef9b34 |
Diff for pulumi-random with merge commit 8ef9b34 |
Diff for pulumi-kubernetes with merge commit 8ef9b34 |
Diff for pulumi-gcp with merge commit 8ef9b34 |
Diff for pulumi-azure with merge commit 8ef9b34 |
Diff for pulumi-aws with merge commit 8ef9b34 |
pkg/codegen/go/gen.go
Outdated
// 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) |
There was a problem hiding this comment.
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?
pulumi/pkg/codegen/dotnet/gen.go
Line 1037 in 684d7aa
fmt.Fprintf(w, " Version = Utilities.Version,\n") |
pulumi/pkg/codegen/nodejs/gen.go
Lines 868 to 870 in 684d7aa
fmt.Fprintf(w, " if (!opts.version) {\n") | |
fmt.Fprintf(w, " opts = pulumi.mergeOptions(opts, { version: utilities.getVersion()});\n") | |
fmt.Fprintf(w, " }\n") |
pulumi/pkg/codegen/python/gen.go
Lines 1219 to 1220 in 684d7aa
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Diff for pulumi-azure-native with merge commit 8ef9b34 |
Codecov Report
@@ 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 Continue to review full report at Codecov.
|
Diff for pulumi-azuread with merge commit c96f0e8 |
Diff for pulumi-random with merge commit c96f0e8 |
Diff for pulumi-kubernetes with merge commit c96f0e8 |
Diff for pulumi-gcp with merge commit c96f0e8 |
Diff for pulumi-random with merge commit dd1ebb0 |
Diff for pulumi-azuread with merge commit dd1ebb0 |
Diff for pulumi-kubernetes with merge commit dd1ebb0 |
Diff for pulumi-gcp with merge commit dd1ebb0 |
Diff for pulumi-azure with merge commit c96f0e8 |
Diff for pulumi-aws with merge commit c96f0e8 |
Diff for pulumi-azure with merge commit dd1ebb0 |
Diff for pulumi-aws with merge commit dd1ebb0 |
Diff for pulumi-azure-native with merge commit c96f0e8 |
Diff for pulumi-azure-native with merge commit dd1ebb0 |
Diff for pulumi-azuread with merge commit a67b5dd |
Diff for pulumi-kubernetes with merge commit a67b5dd |
Diff for pulumi-gcp with merge commit a67b5dd |
Diff for pulumi-azure with merge commit a67b5dd |
Diff for pulumi-aws with merge commit a67b5dd |
Diff for pulumi-azure-native with merge commit a67b5dd |
} | ||
|
||
// PkgResourceDefaultOpts provides package level defaults to pulumi.OptionResource. | ||
func PkgResourceDefaultOpts(opts []pulumi.ResourceOption) []pulumi.ResourceOption { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
...egen/internal/test/testdata/azure-native-nested-types/go/azure/documentdb/pulumiUtilities.go
Outdated
Show resolved
Hide resolved
pkg/codegen/go/gen.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
Diff for pulumi-random with merge commit e3a3f82 |
Diff for pulumi-azuread with merge commit e3a3f82 |
Diff for pulumi-kubernetes with merge commit e3a3f82 |
Diff for pulumi-gcp with merge commit e3a3f82 |
Diff for pulumi-azure with merge commit e3a3f82 |
Diff for pulumi-aws with merge commit e3a3f82 |
Diff for pulumi-azure-native with merge commit e3a3f82 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Diff for pulumi-random with merge commit c4490e1 |
Diff for pulumi-azuread with merge commit c4490e1 |
Diff for pulumi-kubernetes with merge commit c4490e1 |
Diff for pulumi-gcp with merge commit c4490e1 |
Diff for pulumi-azure with merge commit c4490e1 |
Diff for pulumi-aws with merge commit c4490e1 |
Diff for pulumi-azure-native with merge commit c4490e1 |
Description
Fixes # (issue)
Embed
PluginDownloadURL
s in resource creation requests from codegen.Checklist