Skip to content

Commit

Permalink
Merge pull request #1846 from realshuting/background_image_properties
Browse files Browse the repository at this point in the history
Enable image substitution in the background mode
  • Loading branch information
JimBugwadia committed Apr 28, 2021
2 parents 0776b43 + e9c2d89 commit df6c896
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/policy/apply.go
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
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
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]"))
}

0 comments on commit df6c896

Please sign in to comment.