1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

Kyverno CLI test default manifest should use a less generic name ()

* Kyverno CLI test default manifest should use a less generic name

* fix Note

Co-authored-by: shuting <shutting06@gmail.com>
This commit is contained in:
Vyankatesh Kudtarkar 2021-12-17 12:01:34 +05:30 committed by GitHub
parent abb5bd2947
commit bbdfc21d73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -161,7 +161,7 @@ func Command() *cobra.Command {
return nil
},
}
cmd.Flags().StringVarP(&fileName, "file-name", "f", "test.yaml", "test filename")
cmd.Flags().StringVarP(&fileName, "file-name", "f", "kyverno-test.yaml", "test filename")
return cmd
}
@ -222,6 +222,7 @@ func testCommandExecute(dirPath []string, valuesFile string, fileName string) (r
fs := memfs.New()
rc = &resultCounts{}
var testYamlCount int
var testYamlNameCount int
if len(dirPath) == 0 {
return rc, sanitizederror.NewWithError(fmt.Sprintf("a directory is required"), err)
@ -267,8 +268,11 @@ func testCommandExecute(dirPath []string, valuesFile string, fileName string) (r
continue
}
if strings.Contains(file.Name(), fileName) {
if strings.Contains(file.Name(), fileName) || strings.Contains(file.Name(), "test.yaml") {
testYamlCount++
if strings.Contains(file.Name(), "test.yaml") {
testYamlNameCount++
}
policyresoucePath := strings.Trim(yamlFilePath, fileName)
bytes, err := ioutil.ReadAll(file)
if err != nil {
@ -291,6 +295,9 @@ func testCommandExecute(dirPath []string, valuesFile string, fileName string) (r
if testYamlCount == 0 {
fmt.Printf("\n No test yamls available \n")
}
if testYamlNameCount > 0 {
fmt.Printf("\n Note : test.yaml file name is deprecated in 1.6.0 release. Please provide test yaml file as kyverno-test.yaml \n")
}
} else {
path := filepath.Clean(dirPath[0])
@ -314,6 +321,8 @@ func testCommandExecute(dirPath []string, valuesFile string, fileName string) (r
func getLocalDirTestFiles(fs billy.Filesystem, path, fileName, valuesFile string, rc *resultCounts) []error {
var errors []error
var count int
var dirTestYamlNameCount int
files, err := ioutil.ReadDir(path)
if err != nil {
return []error{fmt.Errorf("failed to read %v: %v", path, err.Error())}
@ -323,7 +332,11 @@ func getLocalDirTestFiles(fs billy.Filesystem, path, fileName, valuesFile string
getLocalDirTestFiles(fs, filepath.Join(path, file.Name()), fileName, valuesFile, rc)
continue
}
if strings.Contains(file.Name(), fileName) {
if strings.Contains(file.Name(), fileName) || strings.Contains(file.Name(), "test.yaml") {
count++
if strings.Contains(file.Name(), "test.yaml") {
dirTestYamlNameCount++
}
// We accept the risk of including files here as we read the test dir only.
yamlFile, err := ioutil.ReadFile(filepath.Join(path, file.Name())) // #nosec G304
if err != nil {
@ -341,6 +354,12 @@ func getLocalDirTestFiles(fs billy.Filesystem, path, fileName, valuesFile string
}
}
}
if count == 0 {
fmt.Printf("\n No test yamls found. Please provide test yaml file as kyverno-test.yaml \n")
}
if dirTestYamlNameCount > 0 {
fmt.Printf("\n Note: test.yaml file name is deprecated in 1.6.0 release. Please provide test yaml file as kyverno-test.yaml \n")
}
return errors
}