diff --git a/api/kyverno/v1/clusterpolicy_types.go b/api/kyverno/v1/clusterpolicy_types.go index 2bed6ed1f4..31a651edc7 100644 --- a/api/kyverno/v1/clusterpolicy_types.go +++ b/api/kyverno/v1/clusterpolicy_types.go @@ -94,8 +94,7 @@ func (p *ClusterPolicy) IsReady() bool { // Validate implements programmatic validation // namespaced means that the policy is bound to a namespace and therefore // should not filter/generate cluster wide resources. -func (p *ClusterPolicy) Validate(clusterResources sets.String) field.ErrorList { - var errs field.ErrorList +func (p *ClusterPolicy) Validate(clusterResources sets.String) (errs field.ErrorList) { errs = append(errs, ValidatePolicyName(field.NewPath("name"), p.Name)...) errs = append(errs, p.Spec.Validate(field.NewPath("spec"), p.IsNamespaced(), clusterResources)...) return errs diff --git a/api/kyverno/v1/image_verification_types.go b/api/kyverno/v1/image_verification_types.go index 20cfdfc68e..9a8a5d51d9 100644 --- a/api/kyverno/v1/image_verification_types.go +++ b/api/kyverno/v1/image_verification_types.go @@ -42,8 +42,7 @@ type ImageVerification struct { } // Validate implements programmatic validation -func (i *ImageVerification) Validate(path *field.Path) field.ErrorList { - var errs field.ErrorList +func (i *ImageVerification) Validate(path *field.Path) (errs field.ErrorList) { hasKey := i.Key != "" hasRoots := i.Roots != "" hasSubject := i.Subject != "" diff --git a/api/kyverno/v1/match_resources_types.go b/api/kyverno/v1/match_resources_types.go index 23be5a7ccd..915dbc2146 100644 --- a/api/kyverno/v1/match_resources_types.go +++ b/api/kyverno/v1/match_resources_types.go @@ -31,8 +31,7 @@ type MatchResources struct { } // Validate implements programmatic validation -func (m *MatchResources) Validate(path *field.Path, namespaced bool, clusterResources sets.String) field.ErrorList { - var errs field.ErrorList +func (m *MatchResources) Validate(path *field.Path, namespaced bool, clusterResources sets.String) (errs field.ErrorList) { if len(m.Any) > 0 && len(m.All) > 0 { errs = append(errs, field.Invalid(path, m, "Can't specify any and all together")) } diff --git a/api/kyverno/v1/policy_types.go b/api/kyverno/v1/policy_types.go index eda4cbb91d..b6d5f34160 100755 --- a/api/kyverno/v1/policy_types.go +++ b/api/kyverno/v1/policy_types.go @@ -95,8 +95,7 @@ func (p *Policy) IsReady() bool { // Validate implements programmatic validation. // namespaced means that the policy is bound to a namespace and therefore // should not filter/generate cluster wide resources. -func (p *Policy) Validate(namespaced bool, clusterResources sets.String) field.ErrorList { - var errs field.ErrorList +func (p *Policy) Validate(namespaced bool, clusterResources sets.String) (errs field.ErrorList) { errs = append(errs, ValidatePolicyName(field.NewPath("name"), p.Name)...) errs = append(errs, p.Spec.Validate(field.NewPath("spec"), namespaced, clusterResources)...) return errs diff --git a/api/kyverno/v1/resource_description_types.go b/api/kyverno/v1/resource_description_types.go index 3f8d66bac7..e92802fe94 100644 --- a/api/kyverno/v1/resource_description_types.go +++ b/api/kyverno/v1/resource_description_types.go @@ -53,8 +53,7 @@ type ResourceDescription struct { } // Validate implements programmatic validation -func (r *ResourceDescription) Validate(path *field.Path, namespaced bool, clusterResources sets.String) field.ErrorList { - var errs field.ErrorList +func (r *ResourceDescription) Validate(path *field.Path, namespaced bool, clusterResources sets.String) (errs field.ErrorList) { if r.Name != "" && len(r.Names) > 0 { errs = append(errs, field.Invalid(path, r, "Both name and names can not be specified together")) } diff --git a/api/kyverno/v1/rule_types.go b/api/kyverno/v1/rule_types.go index 2e6c756b98..7225a1f83a 100644 --- a/api/kyverno/v1/rule_types.go +++ b/api/kyverno/v1/rule_types.go @@ -115,8 +115,7 @@ func (r *Rule) SetAnyAllConditions(in apiextensions.JSON) { } // ValidateRuleType checks only one type of rule is defined per rule -func (r *Rule) ValidateRuleType(path *field.Path) field.ErrorList { - var errs field.ErrorList +func (r *Rule) ValidateRuleType(path *field.Path) (errs field.ErrorList) { ruleTypes := []bool{r.HasMutate(), r.HasValidate(), r.HasGenerate(), r.HasVerifyImages()} count := 0 for _, v := range ruleTypes { @@ -298,8 +297,7 @@ func (r *Rule) ValidateMathExcludeConflict(path *field.Path) (errs field.ErrorLi } // Validate implements programmatic validation -func (r *Rule) Validate(path *field.Path, namespaced bool, clusterResources sets.String) field.ErrorList { - var errs field.ErrorList +func (r *Rule) Validate(path *field.Path, namespaced bool, clusterResources sets.String) (errs field.ErrorList) { errs = append(errs, r.ValidateRuleType(path)...) errs = append(errs, r.ValidateMathExcludeConflict(path)...) errs = append(errs, r.MatchResources.Validate(path.Child("match"), namespaced, clusterResources)...) diff --git a/api/kyverno/v1/spec_types.go b/api/kyverno/v1/spec_types.go index a7d73ee9a6..ffb86afe63 100644 --- a/api/kyverno/v1/spec_types.go +++ b/api/kyverno/v1/spec_types.go @@ -133,8 +133,7 @@ func (s *Spec) BackgroundProcessingEnabled() bool { } // ValidateRuleNames checks if the rule names are unique across a policy -func (s *Spec) ValidateRuleNames(path *field.Path) field.ErrorList { - var errs field.ErrorList +func (s *Spec) ValidateRuleNames(path *field.Path) (errs field.ErrorList) { names := sets.NewString() for i, rule := range s.Rules { rulePath := path.Index(i) @@ -147,8 +146,7 @@ func (s *Spec) ValidateRuleNames(path *field.Path) field.ErrorList { } // ValidateRules implements programmatic validation of Rules -func (s *Spec) ValidateRules(path *field.Path, namespaced bool, clusterResources sets.String) field.ErrorList { - var errs field.ErrorList +func (s *Spec) ValidateRules(path *field.Path, namespaced bool, clusterResources sets.String) (errs field.ErrorList) { errs = append(errs, s.ValidateRuleNames(path)...) for i, rule := range s.Rules { errs = append(errs, rule.Validate(path.Index(i), namespaced, clusterResources)...) @@ -157,8 +155,7 @@ func (s *Spec) ValidateRules(path *field.Path, namespaced bool, clusterResources } // Validate implements programmatic validation -func (s *Spec) Validate(path *field.Path, namespaced bool, clusterResources sets.String) field.ErrorList { - var errs field.ErrorList +func (s *Spec) Validate(path *field.Path, namespaced bool, clusterResources sets.String) (errs field.ErrorList) { errs = append(errs, s.ValidateRules(path.Child("rules"), namespaced, clusterResources)...) if namespaced && len(s.ValidationFailureActionOverrides) > 0 { errs = append(errs, field.Forbidden(path.Child("validationFailureActionOverrides"), "Use of validationFailureActionOverrides is supported only with ClusterPolicy")) diff --git a/api/kyverno/v1/user_info_types.go b/api/kyverno/v1/user_info_types.go index e63392e120..e51bbe4075 100644 --- a/api/kyverno/v1/user_info_types.go +++ b/api/kyverno/v1/user_info_types.go @@ -24,8 +24,7 @@ type UserInfo struct { } // ValidateSubjects implements programmatic validation of Subjects -func (u *UserInfo) ValidateSubjects(path *field.Path) field.ErrorList { - var errs field.ErrorList +func (u *UserInfo) ValidateSubjects(path *field.Path) (errs field.ErrorList) { for index, subject := range u.Subjects { entry := path.Index(index) if subject.Kind == "" { @@ -42,8 +41,7 @@ func (u *UserInfo) ValidateSubjects(path *field.Path) field.ErrorList { } // ValidateRoles implements programmatic validation of Roles -func (u *UserInfo) ValidateRoles(path *field.Path) field.ErrorList { - var errs field.ErrorList +func (u *UserInfo) ValidateRoles(path *field.Path) (errs field.ErrorList) { for i, r := range u.Roles { role := strings.Split(r, ":") if len(role) != 2 { @@ -54,8 +52,7 @@ func (u *UserInfo) ValidateRoles(path *field.Path) field.ErrorList { } // Validate implements programmatic validation -func (u *UserInfo) Validate(path *field.Path) field.ErrorList { - var errs field.ErrorList +func (u *UserInfo) Validate(path *field.Path) (errs field.ErrorList) { errs = append(errs, u.ValidateSubjects(path.Child("subjects"))...) errs = append(errs, u.ValidateRoles(path.Child("roles"))...) return errs diff --git a/api/kyverno/v1/utils.go b/api/kyverno/v1/utils.go index f86488eb3d..0be1ae8712 100755 --- a/api/kyverno/v1/utils.go +++ b/api/kyverno/v1/utils.go @@ -30,8 +30,7 @@ func ToJSON(in apiextensions.JSON) *apiextv1.JSON { } // ValidatePolicyName validates policy name -func ValidatePolicyName(path *field.Path, name string) field.ErrorList { - var errs field.ErrorList +func ValidatePolicyName(path *field.Path, name string) (errs field.ErrorList) { // policy name is stored in the label of the report change request if len(name) > 63 { errs = append(errs, field.TooLong(path, name, 63))