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

Copy the labels map before editing #4021

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions porch/pkg/cache/packagerevision.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ func (c *cachedPackageRevision) GetPackageRevision(ctx context.Context) (*v1alph
return nil, err
}
if c.isLatestRevision {
if rev.Labels == nil {
rev.Labels = map[string]string{}
// copy the labels in case the cached object is being read by another go routine
labels := make(map[string]string, len(rev.Labels))
for k, v := range rev.Labels {
labels[k] = v
}
rev.Labels[v1alpha1.LatestPackageRevisionKey] = v1alpha1.LatestPackageRevisionValue
labels[v1alpha1.LatestPackageRevisionKey] = v1alpha1.LatestPackageRevisionValue
rev.Labels = labels
}
return rev, nil
}
9 changes: 6 additions & 3 deletions porch/pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@ func (p *PackageRevision) GetPackageRevision(ctx context.Context) (*api.PackageR
}
repoPkgRev.Labels = p.packageRevisionMeta.Labels
if isLatest {
if repoPkgRev.Labels == nil {
repoPkgRev.Labels = make(map[string]string)
// copy the labels in case the cached object is being read by another go routine
labels := make(map[string]string, len(repoPkgRev.Labels))
for k, v := range repoPkgRev.Labels {
labels[k] = v
}
repoPkgRev.Labels[api.LatestPackageRevisionKey] = api.LatestPackageRevisionValue
labels[api.LatestPackageRevisionKey] = api.LatestPackageRevisionValue
repoPkgRev.Labels = labels
}
repoPkgRev.Annotations = p.packageRevisionMeta.Annotations
repoPkgRev.Finalizers = p.packageRevisionMeta.Finalizers
Expand Down
Loading