-
Notifications
You must be signed in to change notification settings - Fork 50
Invalidate example cache keys more aggressively #3214
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -26,9 +26,12 @@ import ( | |||||
| "encoding/hex" | ||||||
| "encoding/json" | ||||||
| "fmt" | ||||||
| "maps" | ||||||
| "os" | ||||||
| "os/exec" | ||||||
| "path/filepath" | ||||||
| "runtime/debug" | ||||||
| "slices" | ||||||
| "strings" | ||||||
|
|
||||||
| "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" | ||||||
|
|
@@ -46,7 +49,6 @@ type examplesCache struct { | |||||
| ProviderName string `json:"providerName"` | ||||||
| PulumiVersion string `json:"pulumiVersion"` | ||||||
| SoftwareVersions map[string]string `json:"softwareVersions"` | ||||||
| BuildFileHashes map[string]string `json:"buildFileHashes"` | ||||||
| Plugins map[string]map[string]string `json:"plugins"` | ||||||
| CliConverterEnabled bool `json:"cliConverterEnabled"` | ||||||
| ProviderInfoHash string `json:"providerInfoHash"` | ||||||
|
|
@@ -121,18 +123,28 @@ func (*examplesCache) checksum(bytes []byte) string { | |||||
| return hex.EncodeToString(hash[:]) | ||||||
| } | ||||||
|
|
||||||
| // exampleKey determines the cache key to use for the given HCL. It's computed | ||||||
| // from the HCL, target language, our Pulumi & Bridge versions, and the | ||||||
| // provider's info. | ||||||
| func (ec *examplesCache) exampleKey(originalHCL, language string) string { | ||||||
| sep := "|" | ||||||
| var buf bytes.Buffer | ||||||
| fmt.Fprintf(&buf, "originalHCL=%v%s", originalHCL, sep) | ||||||
| fmt.Fprintf(&buf, "language=%v%s", language, sep) | ||||||
|
|
||||||
| fmt.Fprint(&buf, originalHCL) | ||||||
| fmt.Fprint(&buf, language) | ||||||
| fmt.Fprint(&buf, ec.ProviderInfoHash) | ||||||
|
|
||||||
| // Sorted for stable keys. | ||||||
| for _, key := range slices.Sorted(maps.Keys(ec.SoftwareVersions)) { | ||||||
| fmt.Fprint(&buf, key) | ||||||
| fmt.Fprint(&buf, ec.SoftwareVersions[key]) | ||||||
| } | ||||||
|
|
||||||
| return ec.checksum(buf.Bytes()) | ||||||
| } | ||||||
|
|
||||||
| func (ec *examplesCache) inferToolingVersions() { | ||||||
| ec.PulumiVersion = ec.inferPulumiVersion() | ||||||
| ec.Plugins = ec.inferPlugins() | ||||||
| ec.BuildFileHashes = ec.inferBuildFileHashes() | ||||||
| ec.CliConverterEnabled = cliConverterEnabled() | ||||||
| ec.SoftwareVersions = ec.inferSoftwareVersions() | ||||||
| } | ||||||
|
|
@@ -167,55 +179,30 @@ func (*examplesCache) inferPlugins() map[string]map[string]string { | |||||
| return rr | ||||||
| } | ||||||
|
|
||||||
| func (ec *examplesCache) inferBuildFileHashes() map[string]string { | ||||||
| candidates := []string{ | ||||||
| "go.work", | ||||||
| "go.work.sum", | ||||||
| } | ||||||
| rr := map[string]string{} | ||||||
| for _, c := range candidates { | ||||||
| rr[c] = ec.filehash(c) | ||||||
| } | ||||||
| return rr | ||||||
| } | ||||||
|
|
||||||
| func (ec *examplesCache) inferSoftwareVersions() map[string]string { | ||||||
| used := []string{ | ||||||
| "github.com/pulumi/pulumi/pkg/v3", | ||||||
| "github.com/pulumi/pulumi-terraform-bridge/v3", | ||||||
| "github.com/pulumi/pulumi-terraform-bridge/v3/pf", | ||||||
| v := map[string]string{} | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we're using it across the entire method, can we give
Suggested change
|
||||||
|
|
||||||
| bi, ok := debug.ReadBuildInfo() | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is honestly more because "bi" reminds me of the prefix from "binary" and could just be a personal preference. |
||||||
| if !ok { | ||||||
| return v | ||||||
| } | ||||||
| p := map[string]string{} | ||||||
| for _, u := range used { | ||||||
| cmd := exec.Command("go", "list", "-m", "-json", u) | ||||||
| cmd.Dir = "provider" | ||||||
| j, err := cmd.CombinedOutput() | ||||||
| if err != nil { | ||||||
| continue | ||||||
| } | ||||||
| type result struct { | ||||||
| Version string `json:"Version"` | ||||||
| Replace struct { | ||||||
| Version string `json:"Version"` | ||||||
| } `json:"Replace"` | ||||||
|
|
||||||
| for _, mod := range bi.Deps { | ||||||
| if mod.Replace != nil { | ||||||
| mod = mod.Replace | ||||||
| } | ||||||
| var r result | ||||||
| err = json.Unmarshal(j, &r) | ||||||
| contract.AssertNoErrorf(err, "go list -json -m <pkg> result parsing failed") | ||||||
| p[u] = r.Version | ||||||
| if r.Replace.Version != "" { | ||||||
| p[u] = r.Replace.Version | ||||||
|
|
||||||
| switch mod.Path { | ||||||
| case "github.com/pulumi/pulumi/pkg/v3", | ||||||
| "github.com/pulumi/pulumi/sdk/v3", | ||||||
| "github.com/pulumi/pulumi-terraform-bridge/v3": | ||||||
|
|
||||||
| v[mod.Path] = mod.Version | ||||||
| default: | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we return |
||||||
| } | ||||||
| } | ||||||
| return p | ||||||
| } | ||||||
|
|
||||||
| func (ec *examplesCache) filehash(p string) string { | ||||||
| bytes, err := os.ReadFile(p) | ||||||
| if err != nil { | ||||||
| return "" | ||||||
| } | ||||||
| return ec.checksum(bytes) | ||||||
| return v | ||||||
| } | ||||||
|
|
||||||
| func (ec *examplesCache) computeProviderInfoHash(info *tfbridge.ProviderInfo) { | ||||||
|
|
||||||
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 noticed that the way we calculate the plugins is via pulumi plugin ls which apparently does not take into account PATH manipulation.
The way we currently do it (using the
.pulumilocal folder) and the way we plan to do it (withmise) work by putting the plugins on the PATH. This might be something that we have to fix withpulumi plugin ls