Skip to content

Commit

Permalink
Merge branch 'main' into fix_mutate_existing_force_reconciliation
Browse files Browse the repository at this point in the history
  • Loading branch information
realshuting authored Dec 20, 2023
2 parents 98c0ae5 + d113876 commit db7a347
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 5 deletions.
4 changes: 3 additions & 1 deletion cmd/cli/kubectl-kyverno/commands/apply/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/command"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/deprecations"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/log"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/output/color"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/policy"
Expand Down Expand Up @@ -136,9 +137,10 @@ func (c *ApplyCommandConfig) applyCommandHelper(out io.Writer) (*processor.Resul
if err != nil {
return nil, nil, skipInvalidPolicies, nil, fmt.Errorf("failed to load request info (%w)", err)
}
deprecations.CheckUserInfo(out, c.UserInfoPath, info)
userInfo = &info.RequestInfo
}
variables, err := variables.New(nil, "", c.ValuesFile, nil, c.Variables...)
variables, err := variables.New(out, nil, "", c.ValuesFile, nil, c.Variables...)
if err != nil {
return nil, nil, skipInvalidPolicies, nil, fmt.Errorf("failed to decode yaml (%w)", err)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/cli/kubectl-kyverno/commands/test/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/go-git/go-billy/v5"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/apis/v1alpha1"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/command"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/deprecations"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/output/color"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/output/table"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/report"
Expand Down Expand Up @@ -103,6 +104,7 @@ func testCommandExecute(
var table table.Table
for _, test := range tests {
if test.Err == nil {
deprecations.CheckTest(out, test.Path, test.Test)
// filter results
var filteredResults []v1alpha1.TestResult
for _, res := range test.Test.Results {
Expand Down
5 changes: 3 additions & 2 deletions cmd/cli/kubectl-kyverno/commands/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/deprecations"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/log"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/path"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/policy"
Expand Down Expand Up @@ -38,7 +39,7 @@ func runTest(out io.Writer, testCase test.TestCase, registryAccess bool, auditWa
var dClient dclient.Interface
// values/variables
fmt.Fprintln(out, " Loading values/variables", "...")
vars, err := variables.New(testCase.Fs, testDir, testCase.Test.Variables, testCase.Test.Values)
vars, err := variables.New(out, testCase.Fs, testDir, testCase.Test.Variables, testCase.Test.Values)
if err != nil {
err = fmt.Errorf("failed to decode yaml (%w)", err)
return nil, err
Expand All @@ -51,6 +52,7 @@ func runTest(out io.Writer, testCase test.TestCase, registryAccess bool, auditWa
if err != nil {
return nil, fmt.Errorf("Error: failed to load request info (%s)", err)
}
deprecations.CheckUserInfo(out, testCase.Test.UserInfo, info)
userInfo = &info.RequestInfo
}
// policies
Expand Down Expand Up @@ -137,7 +139,6 @@ func runTest(out io.Writer, testCase test.TestCase, registryAccess bool, auditWa
// execute engine
var engineResponses []engineapi.EngineResponse
var resultCounts processor.ResultCounts

for _, resource := range uniques {
processor := processor.PolicyProcessor{
Store: &store,
Expand Down
52 changes: 52 additions & 0 deletions cmd/cli/kubectl-kyverno/deprecations/check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package deprecations

import (
"fmt"
"io"

"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/apis/v1alpha1"
)

func CheckUserInfo(out io.Writer, path string, resource *v1alpha1.UserInfo) bool {
if resource != nil {
if resource.APIVersion == "" || resource.Kind == "" {
if out != nil {
fmt.Fprintf(out, "\nWARNING: user infos file (%s) uses a deprecated schema that will be removed in 1.13\n", path)
}
return true
}
}
return false
}

func CheckValues(out io.Writer, path string, resource *v1alpha1.Values) bool {
if resource != nil {
if resource.APIVersion == "" || resource.Kind == "" {
if out != nil {
fmt.Fprintf(out, "\nWARNING: values file (%s) uses a deprecated schema that will be removed in 1.13\n", path)
}
return true
}
}
return false
}

func CheckTest(out io.Writer, path string, resource *v1alpha1.Test) bool {
if resource != nil {
if resource.APIVersion == "" || resource.Kind == "" || resource.Name != "" {
if out != nil {
fmt.Fprintf(out, "\nWARNING: test file (%s) uses a deprecated schema that will be removed in 1.13\n", path)
}
return true
}
for _, result := range resource.Results {
if result.TestResultDeprecated.Status != "" || result.TestResultDeprecated.Namespace != "" || result.TestResultDeprecated.Resource != "" {
if out != nil {
fmt.Fprintf(out, "\nWARNING: test file (%s) uses a deprecated schema that will be removed in 1.13\n", path)
}
return true
}
}
}
return false
}
5 changes: 4 additions & 1 deletion cmd/cli/kubectl-kyverno/variables/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ package variables

import (
"fmt"
"io"
"path/filepath"

"github.com/go-git/go-billy/v5"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/apis/v1alpha1"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/deprecations"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/values"
)

func New(fs billy.Filesystem, resourcePath string, path string, vals *v1alpha1.ValuesSpec, vars ...string) (*Variables, error) {
func New(out io.Writer, fs billy.Filesystem, resourcePath string, path string, vals *v1alpha1.ValuesSpec, vars ...string) (*Variables, error) {
// if we already have values, skip the file
if vals == nil && path != "" {
v, err := values.Load(fs, filepath.Join(resourcePath, path))
if err != nil {
return nil, fmt.Errorf("unable to load variable file: %s (%w)", path, err)
}
deprecations.CheckValues(out, path, v)
vals = &v.ValuesSpec
}
variables := Variables{
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/kubectl-kyverno/variables/new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func TestNew(t *testing.T) {
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := New(tt.fs, tt.resourcePath, tt.path, tt.vals, tt.vars...)
got, err := New(nil, tt.fs, tt.resourcePath, tt.path, tt.vals, tt.vars...)
if (err != nil) != tt.wantErr {
t.Errorf("New() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down

0 comments on commit db7a347

Please sign in to comment.