1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-04-15 00:36:28 +00:00

fix: golangci-lint warnings in cmd (#3843)

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

Co-authored-by: Vyankatesh Kudtarkar <vyankateshkd@gmail.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-05-09 18:55:35 +02:00 committed by GitHub
parent ba4413b25c
commit cea7a7e11e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 17 deletions

View file

@ -83,7 +83,7 @@ func buildPolicyResults(infos []policyreport.Info) map[string][]report.PolicyRep
if ns != "" {
appname = fmt.Sprintf("policyreport-ns-%s", ns)
} else {
appname = fmt.Sprintf(clusterpolicyreport)
appname = clusterpolicyreport
}
for _, infoResult := range info.Results {

View file

@ -303,7 +303,7 @@ func testCommandExecute(dirPath []string, fileName string, gitBranch string, tes
}
if len(dirPath) == 0 {
return rc, sanitizederror.NewWithError(fmt.Sprintf("a directory is required"), err)
return rc, sanitizederror.NewWithError("a directory is required", err)
}
if len(testCase) != 0 {

View file

@ -588,7 +588,6 @@ func PrintMutatedOutput(mutateLogPath string, mutateLogPathIsDir bool, yaml stri
// GetPoliciesFromPaths - get policies according to the resource path
func GetPoliciesFromPaths(fs billy.Filesystem, dirPath []string, isGit bool, policyResourcePath string) (policies []v1.PolicyInterface, err error) {
var errors []error
if isGit {
for _, pp := range dirPath {
filep, err := fs.Open(filepath.Join(policyResourcePath, pp))
@ -608,8 +607,7 @@ func GetPoliciesFromPaths(fs billy.Filesystem, dirPath []string, isGit bool, pol
}
policiesFromFile, errFromFile := utils.GetPolicy(policyBytes)
if errFromFile != nil {
err := fmt.Errorf("failed to process : %v", errFromFile.Error())
errors = append(errors, err)
fmt.Printf("failed to process : %v", errFromFile.Error())
continue
}
policies = append(policies, policiesFromFile...)
@ -987,9 +985,9 @@ func GetPatchedResourceFromPath(fs billy.Filesystem, path string, isGit bool, po
if isGit {
if len(path) > 0 {
filep, err := fs.Open(filepath.Join(policyResourcePath, path))
if err != nil {
fmt.Printf("Unable to open patchedResource file: %s. \nerror: %s", path, err)
filep, fileErr := fs.Open(filepath.Join(policyResourcePath, path))
if fileErr != nil {
fmt.Printf("Unable to open patchedResource file: %s. \nerror: %s", path, fileErr)
}
patchedResourceBytes, err = ioutil.ReadAll(filep)
}

View file

@ -119,7 +119,6 @@ func whenClusterIsFalse(resourcePaths []string, policyReport bool) ([]*unstructu
func GetResourcesWithTest(fs billy.Filesystem, policies []v1.PolicyInterface, resourcePaths []string, isGit bool, policyResourcePath string) ([]*unstructured.Unstructured, error) {
resources := make([]*unstructured.Unstructured, 0)
var resourceTypesMap = make(map[string]bool)
var resourceTypes []string
for _, policy := range policies {
for _, rule := range autogen.ComputeRules(policy) {
for _, kind := range rule.MatchResources.Kinds {
@ -127,9 +126,6 @@ func GetResourcesWithTest(fs billy.Filesystem, policies []v1.PolicyInterface, re
}
}
}
for kind := range resourceTypesMap {
resourceTypes = append(resourceTypes, kind)
}
if len(resourcePaths) > 0 {
for _, resourcePath := range resourcePaths {
var resourceBytes []byte
@ -140,7 +136,7 @@ func GetResourcesWithTest(fs billy.Filesystem, policies []v1.PolicyInterface, re
fmt.Printf("Unable to open resource file: %s. error: %s", resourcePath, err)
continue
}
resourceBytes, err = ioutil.ReadAll(filep)
resourceBytes, _ = ioutil.ReadAll(filep)
} else {
resourceBytes, err = getFileBytes(resourcePath)
}
@ -279,10 +275,12 @@ func convertResourceToUnstructured(resourceYaml []byte) (*unstructured.Unstructu
}
// GetPatchedResource converts raw bytes to unstructured object
func GetPatchedResource(patchResourceBytes []byte) (patchedResource unstructured.Unstructured, err error) {
func GetPatchedResource(patchResourceBytes []byte) (unstructured.Unstructured, error) {
getPatchedResource, err := GetResource(patchResourceBytes)
patchedResource = *getPatchedResource[0]
if err != nil {
return unstructured.Unstructured{}, err
}
patchedResource := *getPatchedResource[0]
return patchedResource, nil
}

View file

@ -53,7 +53,6 @@ const (
clusterPolicyReportKind string = "ClusterPolicyReport"
reportChangeRequestKind string = "ReportChangeRequest"
clusterReportChangeRequestKind string = "ClusterReportChangeRequest"
clusterPolicyViolation string = "ClusterPolicyViolation"
convertGenerateRequest string = "ConvertGenerateRequest"
)