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

Protect declaredRuntimeMetadata with a sync.Mutex #2733

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions pkg/tfbridge/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package tfbridge

import (
"sync"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info"
"github.com/pulumi/pulumi-terraform-bridge/v3/unstable/metadata"
)
Expand All @@ -34,19 +36,27 @@ type MetadataInfo = info.Metadata
// `bytes` is the embedded metadata file.
func NewProviderMetadata(bytes []byte) *MetadataInfo { return info.NewProviderMetadata(bytes) }

var declaredRuntimeMetadata = map[string]struct{}{
var declaredRuntimeMetadata = struct {
keys map[string]struct{}
m sync.Mutex
}{keys: map[string]struct{}{
autoSettingsKey: {},
"mux": {},
}
}}

func declareRuntimeMetadata(label string) { declaredRuntimeMetadata[label] = struct{}{} }
func declareRuntimeMetadata(label string) {
declaredRuntimeMetadata.m.Lock()
defer declaredRuntimeMetadata.m.Unlock()
declaredRuntimeMetadata.keys[label] = struct{}{}
}

// trim the metadata to just the keys required for the runtime phase
// in the future this method might also substitute compressed contents within some keys
func ExtractRuntimeMetadata(info *MetadataInfo) *MetadataInfo {
data, _ := metadata.New(nil)

for k := range declaredRuntimeMetadata {
declaredRuntimeMetadata.m.Lock()
defer declaredRuntimeMetadata.m.Unlock()
for k := range declaredRuntimeMetadata.keys {
metadata.CloneKey(k, info.Data, data)
}

Expand Down
Loading