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

llbsolver: fix policy rule ordering #4014

Merged
merged 1 commit into from
Jul 12, 2023
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
16 changes: 5 additions & 11 deletions solver/llbsolver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -981,27 +981,21 @@ func loadEntitlements(b solver.Builder) (entitlements.Set, error) {
}

func loadSourcePolicy(b solver.Builder) (*spb.Policy, error) {
set := make(map[spb.Rule]struct{}, 0)
var srcPol spb.Policy
err := b.EachValue(context.TODO(), keySourcePolicy, func(v interface{}) error {
x, ok := v.(spb.Policy)
if !ok {
return errors.Errorf("invalid source policy %T", v)
}
for _, f := range x.Rules {
set[*f] = struct{}{}
r := *f
srcPol.Rules = append(srcPol.Rules, &r)
Copy link
Member

Choose a reason for hiding this comment

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

I guess we should copy Version over as well?

Copy link
Member

Choose a reason for hiding this comment

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

sigh and rules have pointers in them I guess we need to dereference.

Copy link
Member Author

Choose a reason for hiding this comment

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

sigh and rules have pointers in them I guess we need to dereference.

Do we need to make sure these are copied? I just left it like this because that is what old code did?

Copy link
Member

Choose a reason for hiding this comment

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

This is probably fine since nothing is modifying the policies.

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 added Version just for completeness. Especially for the common case where EachVertex only returns one value. I think as a follow-up, returning the policy array would make more sense here.

}
srcPol.Version = x.Version
return nil
})
if err != nil {
return nil, err
}
var srcPol *spb.Policy
if len(set) > 0 {
srcPol = &spb.Policy{}
for k := range set {
k := k
srcPol.Rules = append(srcPol.Rules, &k)
}
}
return srcPol, nil
return &srcPol, nil
}