1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

chore: enable ifshort linter (#3945)

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-05-17 20:55:13 +02:00 committed by GitHub
parent daddae27b4
commit 840307fc69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 18 deletions

View file

@ -20,6 +20,7 @@ linters:
- gosimple
- govet
- grouper
- ifshort
- importas
- ineffassign
- makezero

View file

@ -53,11 +53,9 @@ func (c *Controller) MarkUR(ur *kyvernov1beta1.UpdateRequest) (*kyvernov1beta1.U
}
func (c *Controller) UnmarkUR(ur *kyvernov1beta1.UpdateRequest) error {
_, err := c.PatchHandler(ur, "")
if err != nil {
if _, err := c.PatchHandler(ur, ""); err != nil {
return err
}
if ur.Spec.Type == kyvernov1beta1.Mutate && ur.Status.State == kyvernov1beta1.Completed {
return c.kyvernoClient.KyvernoV1beta1().UpdateRequests(config.KyvernoNamespace()).Delete(context.TODO(), ur.GetName(), metav1.DeleteOptions{})
}

View file

@ -7,10 +7,8 @@ import (
)
func Init() error {
certs := fulcio.GetRoots()
if certs == nil {
if fulcio.GetRoots() == nil {
return fmt.Errorf("failed to initialize Fulcio roots")
}
return nil
}

View file

@ -41,8 +41,7 @@ func (ctx *MockContext) Query(query string) (interface{}, error) {
var emptyResult interface{}
// compile the query
_, err := jmespath.New(query)
if err != nil {
if _, err := jmespath.New(query); err != nil {
return emptyResult, fmt.Errorf("invalid JMESPath query %s: %v", query, err)
}

View file

@ -11,8 +11,8 @@ type buffer struct {
// UnmarshalJSON writes the slice of bytes to an internal buffer
func (buff buffer) UnmarshalJSON(b []byte) error {
buff.Reset()
_, err := buff.Write(b)
if err != nil {
if _, err := buff.Write(b); err != nil {
return err
}
return nil

View file

@ -296,10 +296,8 @@ func hasAnchor(key string) bool {
}
func hasAnchors(pattern *yaml.RNode, isAnchor func(key string) bool) bool {
ynode := pattern.YNode()
kind := ynode.Kind
if kind == yaml.MappingNode {
ynode := pattern.YNode() // nolint:ifshort
if ynode.Kind == yaml.MappingNode {
fields, err := pattern.Fields()
if err != nil {
return false
@ -317,10 +315,10 @@ func hasAnchors(pattern *yaml.RNode, isAnchor func(key string) bool) bool {
}
}
}
} else if kind == yaml.ScalarNode {
} else if ynode.Kind == yaml.ScalarNode {
v := ynode.Value
return anchor.ContainsCondition(v)
} else if kind == yaml.SequenceNode {
} else if ynode.Kind == yaml.SequenceNode {
elements, _ := pattern.Elements()
for _, e := range elements {
if hasAnchors(e, isAnchor) {

View file

@ -277,8 +277,7 @@ func buildSuccessMessage(r unstructured.Unstructured) string {
return "mutated resource"
}
ns := r.GetNamespace()
if ns == "" {
if r.GetNamespace() == "" {
return fmt.Sprintf("mutated %s/%s", r.GetKind(), r.GetName())
}