mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-15 12:17:56 +00:00
chore: enable ifshort linter (#3945)
Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
parent
daddae27b4
commit
840307fc69
7 changed files with 11 additions and 18 deletions
|
@ -20,6 +20,7 @@ linters:
|
||||||
- gosimple
|
- gosimple
|
||||||
- govet
|
- govet
|
||||||
- grouper
|
- grouper
|
||||||
|
- ifshort
|
||||||
- importas
|
- importas
|
||||||
- ineffassign
|
- ineffassign
|
||||||
- makezero
|
- makezero
|
||||||
|
|
|
@ -53,11 +53,9 @@ func (c *Controller) MarkUR(ur *kyvernov1beta1.UpdateRequest) (*kyvernov1beta1.U
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) UnmarkUR(ur *kyvernov1beta1.UpdateRequest) error {
|
func (c *Controller) UnmarkUR(ur *kyvernov1beta1.UpdateRequest) error {
|
||||||
_, err := c.PatchHandler(ur, "")
|
if _, err := c.PatchHandler(ur, ""); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ur.Spec.Type == kyvernov1beta1.Mutate && ur.Status.State == kyvernov1beta1.Completed {
|
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{})
|
return c.kyvernoClient.KyvernoV1beta1().UpdateRequests(config.KyvernoNamespace()).Delete(context.TODO(), ur.GetName(), metav1.DeleteOptions{})
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init() error {
|
func Init() error {
|
||||||
certs := fulcio.GetRoots()
|
if fulcio.GetRoots() == nil {
|
||||||
if certs == nil {
|
|
||||||
return fmt.Errorf("failed to initialize Fulcio roots")
|
return fmt.Errorf("failed to initialize Fulcio roots")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,7 @@ func (ctx *MockContext) Query(query string) (interface{}, error) {
|
||||||
var emptyResult interface{}
|
var emptyResult interface{}
|
||||||
|
|
||||||
// compile the query
|
// compile the query
|
||||||
_, err := jmespath.New(query)
|
if _, err := jmespath.New(query); err != nil {
|
||||||
if err != nil {
|
|
||||||
return emptyResult, fmt.Errorf("invalid JMESPath query %s: %v", query, err)
|
return emptyResult, fmt.Errorf("invalid JMESPath query %s: %v", query, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@ type buffer struct {
|
||||||
// UnmarshalJSON writes the slice of bytes to an internal buffer
|
// UnmarshalJSON writes the slice of bytes to an internal buffer
|
||||||
func (buff buffer) UnmarshalJSON(b []byte) error {
|
func (buff buffer) UnmarshalJSON(b []byte) error {
|
||||||
buff.Reset()
|
buff.Reset()
|
||||||
_, err := buff.Write(b)
|
|
||||||
if err != nil {
|
if _, err := buff.Write(b); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -296,10 +296,8 @@ func hasAnchor(key string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasAnchors(pattern *yaml.RNode, isAnchor func(key string) bool) bool {
|
func hasAnchors(pattern *yaml.RNode, isAnchor func(key string) bool) bool {
|
||||||
ynode := pattern.YNode()
|
ynode := pattern.YNode() // nolint:ifshort
|
||||||
kind := ynode.Kind
|
if ynode.Kind == yaml.MappingNode {
|
||||||
|
|
||||||
if kind == yaml.MappingNode {
|
|
||||||
fields, err := pattern.Fields()
|
fields, err := pattern.Fields()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
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
|
v := ynode.Value
|
||||||
return anchor.ContainsCondition(v)
|
return anchor.ContainsCondition(v)
|
||||||
} else if kind == yaml.SequenceNode {
|
} else if ynode.Kind == yaml.SequenceNode {
|
||||||
elements, _ := pattern.Elements()
|
elements, _ := pattern.Elements()
|
||||||
for _, e := range elements {
|
for _, e := range elements {
|
||||||
if hasAnchors(e, isAnchor) {
|
if hasAnchors(e, isAnchor) {
|
||||||
|
|
|
@ -277,8 +277,7 @@ func buildSuccessMessage(r unstructured.Unstructured) string {
|
||||||
return "mutated resource"
|
return "mutated resource"
|
||||||
}
|
}
|
||||||
|
|
||||||
ns := r.GetNamespace()
|
if r.GetNamespace() == "" {
|
||||||
if ns == "" {
|
|
||||||
return fmt.Sprintf("mutated %s/%s", r.GetKind(), r.GetName())
|
return fmt.Sprintf("mutated %s/%s", r.GetKind(), r.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue