mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
feat: add deprecation warnings in the CLI (#9222)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
438a53cb3d
commit
d1138764f5
6 changed files with 65 additions and 5 deletions
|
@ -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"
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
|
52
cmd/cli/kubectl-kyverno/deprecations/check.go
Normal file
52
cmd/cli/kubectl-kyverno/deprecations/check.go
Normal file
|
@ -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
|
||||
}
|
|
@ -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{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue