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

Enable image substitution in the background mode #1846

Merged
merged 2 commits into from
Apr 28, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/policy/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func applyPolicy(policy kyverno.ClusterPolicy, resource unstructured.Unstructure
logger.Error(err, "failed to add namespace to ctx")
}

if err := ctx.AddImageInfo(&resource); err != nil {
logger.Error(err, "unable to add image info to variables context")
}

engineResponseMutation, err = mutation(policy, resource, logger, resCache, ctx, namespaceLabels)
if err != nil {
logger.Error(err, "failed to process mutation rule")
Expand Down
2 changes: 1 addition & 1 deletion pkg/policy/background.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func ContainsVariablesOtherThanObject(policy kyverno.ClusterPolicy) error {
return fmt.Errorf("invalid variable used at path: spec/rules[%d]/exclude/%s", idx, path)
}

filterVars := []string{"request.object", "request.namespace"}
filterVars := []string{"request.object", "request.namespace", "images"}
ctx := context.NewContext(filterVars...)

for _, contextEntry := range rule.Context {
Expand Down
2 changes: 1 addition & 1 deletion pkg/policy/background_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@ func Test_Validation_invalid_backgroundPolicy(t *testing.T) {
err := json.Unmarshal(rawPolicy, &policy)
assert.NilError(t, err)
err = ContainsVariablesOtherThanObject(policy)
assert.Assert(t, strings.Contains(err.Error(), "variable serviceAccountName cannot be used, allowed variables: [request.object request.namespace mycm]"))
assert.Assert(t, strings.Contains(err.Error(), "variable serviceAccountName cannot be used, allowed variables: [request.object request.namespace images mycm]"))
}