Skip to content

Commit

Permalink
Add IgnoreKubeNotFound helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmxs authored Feb 1, 2024
1 parent 1bfa6dc commit f79bba6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions util/helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
package util

import (
kerrors "k8s.io/apimachinery/pkg/util/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// Pointer returns the pointer of any type
func Pointer[T any](t T) *T {
return &t
}

// IgnoreKubeNotFound returns the error even if aggregated except not found
func IgnoreKubeNotFound(err error) error {
//nolint:errorlint // This is specific non wrapped error.
errs, ok := err.(kerrors.Aggregate)
if !ok {
return client.IgnoreNotFound(err)
}

for _, e := range errs.Errors() {
if client.IgnoreNotFound(e) != nil {
return err
}
}

return nil
}

0 comments on commit f79bba6

Please sign in to comment.