1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-30 19:35:06 +00:00

fix: golangci-lint warnings in pkg (#3846)

* fix: golangci-lint warnings in cmd

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

* fix: golangci-lint warnings in pkg

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-10 11:24:27 +02:00 committed by GitHub
parent 967ad7cb8e
commit e2cf6cea5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 30 deletions

View file

@ -245,22 +245,6 @@ func FetchAttestations(imageRef string, imageVerify v1.ImageVerification) ([]map
return nil, errors.Wrap(err, "loading credentials")
}
var opts []remote.Option
ro := options.RegistryOptions{}
opts, err = ro.ClientOpts(ctx)
if err != nil {
return nil, errors.Wrap(err, "constructing client options")
}
opts = append(opts, remote.WithRemoteOptions(gcrremote.WithAuthFromKeychain(registryclient.DefaultKeychain)))
if imageVerify.Repository != "" {
signatureRepo, err := name.NewRepository(imageVerify.Repository)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse signature repository %s", imageVerify.Repository)
}
opts = append(opts, remote.WithTargetRepository(signatureRepo))
}
ref, err := name.ParseReference(imageRef)
if err != nil {
return nil, errors.Wrap(err, "failed to parse image")

View file

@ -187,7 +187,7 @@ func (o *Controller) ParseCRD(crd unstructured.Unstructured) {
parsedSchema, err := openapiv2.NewSchema(&schema, compiler.NewContext("schema", &schema, nil))
if err != nil {
v3valueFound := isOpenV3Error(err)
if v3valueFound == false {
if !v3valueFound {
log.Log.Error(err, "failed to parse crd schema", "name", crdName)
}
return

View file

@ -151,7 +151,7 @@ func (o *Controller) ValidatePolicyMutation(policy v1.PolicyInterface) error {
spec.SetRules(rules)
k := o.gvkToDefinitionName.GetKind(kind)
resource, _ := o.generateEmptyResource(o.definitions.GetSchema(k)).(map[string]interface{})
if resource == nil || len(resource) == 0 {
if len(resource) == 0 {
log.Log.V(2).Info("unable to validate resource. OpenApi definition not found", "kind", kind)
return nil
}

View file

@ -615,7 +615,7 @@ func isLabelAndAnnotationsString(rule kyverno.Rule) bool {
patternMap, ok := pattern.(map[string]interface{})
if ok {
ret := checkMetadata(patternMap)
if ret == false {
if !ret {
return ret
}
}
@ -734,13 +734,13 @@ func validateConditions(conditions apiextensions.JSON, schemaKey string) (string
"conditions": true,
}
if !allowedSchemaKeys[schemaKey] {
return fmt.Sprintf(schemaKey), fmt.Errorf("wrong schema key found for validating the conditions. Conditions can only occur under one of ['preconditions', 'conditions'] keys in the policy schema")
return schemaKey, fmt.Errorf("wrong schema key found for validating the conditions. Conditions can only occur under one of ['preconditions', 'conditions'] keys in the policy schema")
}
// conditions are currently in the form of []interface{}
kyvernoConditions, err := utils.ApiextensionsJsonToKyvernoConditions(conditions)
if err != nil {
return fmt.Sprintf("%s", schemaKey), err
return schemaKey, err
}
switch typedConditions := kyvernoConditions.(type) {
case kyverno.AnyAllConditions:
@ -838,8 +838,6 @@ func validateRuleContext(rule kyverno.Rule) error {
return nil
}
contextNames := make([]string, 0)
for _, entry := range rule.Context {
if entry.Name == "" {
return fmt.Errorf("a name is required for context entries")
@ -849,7 +847,6 @@ func validateRuleContext(rule kyverno.Rule) error {
return fmt.Errorf("entry name %s is invalid as it conflicts with a pre-defined variable %s", entry.Name, v)
}
}
contextNames = append(contextNames, entry.Name)
var err error
if entry.ConfigMap != nil && entry.APICall == nil && entry.ImageRegistry == nil && entry.Variable == nil {
@ -1022,7 +1019,7 @@ func podControllerAutoGenExclusion(policy kyverno.PolicyInterface) bool {
reorderVal := strings.Split(strings.ToLower(val), ",")
sort.Slice(reorderVal, func(i, j int) bool { return reorderVal[i] < reorderVal[j] })
if ok && reflect.DeepEqual(reorderVal, []string{"cronjob", "daemonset", "deployment", "job", "statefulset"}) == false {
if ok && !reflect.DeepEqual(reorderVal, []string{"cronjob", "daemonset", "deployment", "job", "statefulset"}) {
return true
}
return false

View file

@ -302,9 +302,7 @@ func stripNonPolicyFields(obj, newRes map[string]interface{}, logger logr.Logger
newRes["metadata"] = requiredMetadataInNewRes
}
if _, found := obj["status"]; found {
delete(obj, "status")
}
delete(obj, "status")
if _, found := obj["spec"]; found {
delete(obj["spec"].(map[string]interface{}), "tolerations")
@ -312,9 +310,9 @@ func stripNonPolicyFields(obj, newRes map[string]interface{}, logger logr.Logger
if dataMap, found := obj["data"]; found {
keyInData := make([]string, 0)
switch dataMap.(type) {
switch dataMap := dataMap.(type) {
case map[string]interface{}:
for k := range dataMap.(map[string]interface{}) {
for k := range dataMap {
keyInData = append(keyInData, k)
}
}