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

targetEnforcementAction key should take care of the object kind #510

Merged
merged 1 commit into from
Jan 15, 2025
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
12 changes: 8 additions & 4 deletions constraint/pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,10 @@ func (c *Client) RemoveData(ctx context.Context, data interface{}) (*types.Respo
return resp, &errMap
}

func (c *Client) actionKey(constraint *unstructured.Unstructured) string {
return fmt.Sprintf("%s.%s", constraint.GetKind(), constraint.GetName())
}

// Review makes sure the provided object satisfies constraints applicable for specific enforcement points.
// On error, the responses return value will still be populated so that
// partial results can be analyzed.
Expand Down Expand Up @@ -689,8 +693,8 @@ func (c *Client) Review(ctx context.Context, obj interface{}, opts ...reviews.Re
for _, matchResult := range matchingConstraints {
if matchResult.error == nil {
targetConstraints = append(targetConstraints, matchResult.constraint)
targetScopedEnforcementActions[matchResult.constraint.GetName()] = matchResult.scopedEnforcementActions
targetEnforcementAction[matchResult.constraint.GetName()] = matchResult.enforcementAction
targetScopedEnforcementActions[c.actionKey(matchResult.constraint)] = matchResult.scopedEnforcementActions
targetEnforcementAction[c.actionKey(matchResult.constraint)] = matchResult.enforcementAction
} else {
autorejections[target] = append(autorejections[target], matchResult)
}
Expand All @@ -711,10 +715,10 @@ func (c *Client) Review(ctx context.Context, obj interface{}, opts ...reviews.Re
}

for i := range resp.Results {
if val, ok := scopedEnforcementActionsByTarget[target][resp.Results[i].Constraint.GetName()]; ok {
if val, ok := scopedEnforcementActionsByTarget[target][c.actionKey(resp.Results[i].Constraint)]; ok {
resp.Results[i].ScopedEnforcementActions = val
}
if val, ok := enforcementActionByTarget[target][resp.Results[i].Constraint.GetName()]; ok {
if val, ok := enforcementActionByTarget[target][c.actionKey(resp.Results[i].Constraint)]; ok {
resp.Results[i].EnforcementAction = val
}
}
Expand Down
Loading