diff --git a/go.mod b/go.mod index ea7af92..7b3ab42 100644 --- a/go.mod +++ b/go.mod @@ -2,10 +2,10 @@ module github.com/kubewarden/ingress-policy go 1.22 -toolchain go1.23.3 +toolchain go1.23.4 require ( - github.com/deckarep/golang-set/v2 v2.6.0 + github.com/deckarep/golang-set/v2 v2.7.0 github.com/kubewarden/gjson v1.7.2 github.com/kubewarden/k8s-objects v1.29.0-kw1 github.com/kubewarden/policy-sdk-go v0.11.0 diff --git a/go.sum b/go.sum index 14c3e27..88c8cb2 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ github.com/deckarep/golang-set/v2 v2.5.0 h1:hn6cEZtQ0h3J8kFrHR/NrzyOoTnjgW1+FmNJ github.com/deckarep/golang-set/v2 v2.5.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM= github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= +github.com/deckarep/golang-set/v2 v2.7.0 h1:gIloKvD7yH2oip4VLhsv3JyLLFnC0Y2mlusgcvJYW5k= +github.com/deckarep/golang-set/v2 v2.7.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/kubewarden/gjson v1.7.2 h1:+cLRfPqyvjwrkgE68cGdNfUy1Z6L45DjvuFH9/ofwQ0= github.com/kubewarden/gjson v1.7.2/go.mod h1:jSlxpubGqBG5HHe4v8kwcc8z1JF2reJ7AJAUojw66AY= github.com/kubewarden/k8s-objects v1.27.0-kw2 h1:6ZA72SFtDSbCupwxlIyJimUzN0nSweMCUx5jUEnoxkw= diff --git a/vendor/github.com/deckarep/golang-set/v2/README.md b/vendor/github.com/deckarep/golang-set/v2/README.md index 921f0ce..bb691b1 100644 --- a/vendor/github.com/deckarep/golang-set/v2/README.md +++ b/vendor/github.com/deckarep/golang-set/v2/README.md @@ -6,6 +6,15 @@ The missing `generic` set collection for the Go language. Until Go has sets built-in...use this. +## Psst +* Hi there, 👋! Do you use or have interest in the [Zig programming language](https://ziglang.org/) created by Andrew Kelley? If so, the golang-set project has a new sibling project: [ziglang-set](https://github.com/deckarep/ziglang-set)! Come check it out! + +## Update 12/3/2024 +* Packaged version: `2.7.0` fixes a long-standing bug with *JSON Unmarshaling*. A large refactor in the interest of performance +introduced this bug and there was no way around it but to revert the code back to how it was previously. The performance +difference was likely negligible to begin with. JSON Marshaling and Unmarshaling is now properly supported again without +needing to do workarounds. + ## Update 3/5/2023 * Packaged version: `2.2.0` release includes a refactor to minimize pointer indirection, better method documentation standards and a few constructor convenience methods to increase ergonomics when appending items `Append` or creating a new set from an exist `Map`. * supports `new generic` syntax diff --git a/vendor/github.com/deckarep/golang-set/v2/threadsafe.go b/vendor/github.com/deckarep/golang-set/v2/threadsafe.go index ad7a834..93f20c8 100644 --- a/vendor/github.com/deckarep/golang-set/v2/threadsafe.go +++ b/vendor/github.com/deckarep/golang-set/v2/threadsafe.go @@ -29,7 +29,7 @@ import "sync" type threadSafeSet[T comparable] struct { sync.RWMutex - uss threadUnsafeSet[T] + uss *threadUnsafeSet[T] } func newThreadSafeSet[T comparable]() *threadSafeSet[T] { @@ -123,7 +123,7 @@ func (t *threadSafeSet[T]) Union(other Set[T]) Set[T] { t.RLock() o.RLock() - unsafeUnion := t.uss.Union(o.uss).(threadUnsafeSet[T]) + unsafeUnion := t.uss.Union(o.uss).(*threadUnsafeSet[T]) ret := &threadSafeSet[T]{uss: unsafeUnion} t.RUnlock() o.RUnlock() @@ -136,7 +136,7 @@ func (t *threadSafeSet[T]) Intersect(other Set[T]) Set[T] { t.RLock() o.RLock() - unsafeIntersection := t.uss.Intersect(o.uss).(threadUnsafeSet[T]) + unsafeIntersection := t.uss.Intersect(o.uss).(*threadUnsafeSet[T]) ret := &threadSafeSet[T]{uss: unsafeIntersection} t.RUnlock() o.RUnlock() @@ -149,7 +149,7 @@ func (t *threadSafeSet[T]) Difference(other Set[T]) Set[T] { t.RLock() o.RLock() - unsafeDifference := t.uss.Difference(o.uss).(threadUnsafeSet[T]) + unsafeDifference := t.uss.Difference(o.uss).(*threadUnsafeSet[T]) ret := &threadSafeSet[T]{uss: unsafeDifference} t.RUnlock() o.RUnlock() @@ -162,7 +162,7 @@ func (t *threadSafeSet[T]) SymmetricDifference(other Set[T]) Set[T] { t.RLock() o.RLock() - unsafeDifference := t.uss.SymmetricDifference(o.uss).(threadUnsafeSet[T]) + unsafeDifference := t.uss.SymmetricDifference(o.uss).(*threadUnsafeSet[T]) ret := &threadSafeSet[T]{uss: unsafeDifference} t.RUnlock() o.RUnlock() @@ -177,7 +177,7 @@ func (t *threadSafeSet[T]) Clear() { func (t *threadSafeSet[T]) Remove(v T) { t.Lock() - delete(t.uss, v) + delete(*t.uss, v) t.Unlock() } @@ -190,12 +190,12 @@ func (t *threadSafeSet[T]) RemoveAll(i ...T) { func (t *threadSafeSet[T]) Cardinality() int { t.RLock() defer t.RUnlock() - return len(t.uss) + return len(*t.uss) } func (t *threadSafeSet[T]) Each(cb func(T) bool) { t.RLock() - for elem := range t.uss { + for elem := range *t.uss { if cb(elem) { break } @@ -208,7 +208,7 @@ func (t *threadSafeSet[T]) Iter() <-chan T { go func() { t.RLock() - for elem := range t.uss { + for elem := range *t.uss { ch <- elem } close(ch) @@ -224,7 +224,7 @@ func (t *threadSafeSet[T]) Iterator() *Iterator[T] { go func() { t.RLock() L: - for elem := range t.uss { + for elem := range *t.uss { select { case <-stopCh: break L @@ -253,7 +253,7 @@ func (t *threadSafeSet[T]) Equal(other Set[T]) bool { func (t *threadSafeSet[T]) Clone() Set[T] { t.RLock() - unsafeClone := t.uss.Clone().(threadUnsafeSet[T]) + unsafeClone := t.uss.Clone().(*threadUnsafeSet[T]) ret := &threadSafeSet[T]{uss: unsafeClone} t.RUnlock() return ret @@ -275,7 +275,7 @@ func (t *threadSafeSet[T]) Pop() (T, bool) { func (t *threadSafeSet[T]) ToSlice() []T { keys := make([]T, 0, t.Cardinality()) t.RLock() - for elem := range t.uss { + for elem := range *t.uss { keys = append(keys, elem) } t.RUnlock() diff --git a/vendor/github.com/deckarep/golang-set/v2/threadunsafe.go b/vendor/github.com/deckarep/golang-set/v2/threadunsafe.go index 8b17b01..7e3243b 100644 --- a/vendor/github.com/deckarep/golang-set/v2/threadunsafe.go +++ b/vendor/github.com/deckarep/golang-set/v2/threadunsafe.go @@ -34,14 +34,16 @@ import ( type threadUnsafeSet[T comparable] map[T]struct{} // Assert concrete type:threadUnsafeSet adheres to Set interface. -var _ Set[string] = (threadUnsafeSet[string])(nil) +var _ Set[string] = (*threadUnsafeSet[string])(nil) -func newThreadUnsafeSet[T comparable]() threadUnsafeSet[T] { - return make(threadUnsafeSet[T]) +func newThreadUnsafeSet[T comparable]() *threadUnsafeSet[T] { + t := make(threadUnsafeSet[T]) + return &t } -func newThreadUnsafeSetWithSize[T comparable](cardinality int) threadUnsafeSet[T] { - return make(threadUnsafeSet[T], cardinality) +func newThreadUnsafeSetWithSize[T comparable](cardinality int) *threadUnsafeSet[T] { + t := make(threadUnsafeSet[T], cardinality) + return &t } func (s threadUnsafeSet[T]) Add(v T) bool { @@ -50,57 +52,57 @@ func (s threadUnsafeSet[T]) Add(v T) bool { return prevLen != len(s) } -func (s threadUnsafeSet[T]) Append(v ...T) int { - prevLen := len(s) +func (s *threadUnsafeSet[T]) Append(v ...T) int { + prevLen := len(*s) for _, val := range v { - (s)[val] = struct{}{} + (*s)[val] = struct{}{} } - return len(s) - prevLen + return len(*s) - prevLen } // private version of Add which doesn't return a value -func (s threadUnsafeSet[T]) add(v T) { - s[v] = struct{}{} +func (s *threadUnsafeSet[T]) add(v T) { + (*s)[v] = struct{}{} } -func (s threadUnsafeSet[T]) Cardinality() int { - return len(s) +func (s *threadUnsafeSet[T]) Cardinality() int { + return len(*s) } -func (s threadUnsafeSet[T]) Clear() { +func (s *threadUnsafeSet[T]) Clear() { // Constructions like this are optimised by compiler, and replaced by // mapclear() function, defined in // https://github.com/golang/go/blob/29bbca5c2c1ad41b2a9747890d183b6dd3a4ace4/src/runtime/map.go#L993) - for key := range s { - delete(s, key) + for key := range *s { + delete(*s, key) } } -func (s threadUnsafeSet[T]) Clone() Set[T] { +func (s *threadUnsafeSet[T]) Clone() Set[T] { clonedSet := newThreadUnsafeSetWithSize[T](s.Cardinality()) - for elem := range s { + for elem := range *s { clonedSet.add(elem) } return clonedSet } -func (s threadUnsafeSet[T]) Contains(v ...T) bool { +func (s *threadUnsafeSet[T]) Contains(v ...T) bool { for _, val := range v { - if _, ok := s[val]; !ok { + if _, ok := (*s)[val]; !ok { return false } } return true } -func (s threadUnsafeSet[T]) ContainsOne(v T) bool { - _, ok := s[v] +func (s *threadUnsafeSet[T]) ContainsOne(v T) bool { + _, ok := (*s)[v] return ok } -func (s threadUnsafeSet[T]) ContainsAny(v ...T) bool { +func (s *threadUnsafeSet[T]) ContainsAny(v ...T) bool { for _, val := range v { - if _, ok := s[val]; ok { + if _, ok := (*s)[val]; ok { return true } } @@ -108,16 +110,16 @@ func (s threadUnsafeSet[T]) ContainsAny(v ...T) bool { } // private version of Contains for a single element v -func (s threadUnsafeSet[T]) contains(v T) (ok bool) { - _, ok = s[v] +func (s *threadUnsafeSet[T]) contains(v T) (ok bool) { + _, ok = (*s)[v] return ok } -func (s threadUnsafeSet[T]) Difference(other Set[T]) Set[T] { - o := other.(threadUnsafeSet[T]) +func (s *threadUnsafeSet[T]) Difference(other Set[T]) Set[T] { + o := other.(*threadUnsafeSet[T]) diff := newThreadUnsafeSet[T]() - for elem := range s { + for elem := range *s { if !o.contains(elem) { diff.add(elem) } @@ -125,21 +127,21 @@ func (s threadUnsafeSet[T]) Difference(other Set[T]) Set[T] { return diff } -func (s threadUnsafeSet[T]) Each(cb func(T) bool) { - for elem := range s { +func (s *threadUnsafeSet[T]) Each(cb func(T) bool) { + for elem := range *s { if cb(elem) { break } } } -func (s threadUnsafeSet[T]) Equal(other Set[T]) bool { - o := other.(threadUnsafeSet[T]) +func (s *threadUnsafeSet[T]) Equal(other Set[T]) bool { + o := other.(*threadUnsafeSet[T]) if s.Cardinality() != other.Cardinality() { return false } - for elem := range s { + for elem := range *s { if !o.contains(elem) { return false } @@ -147,19 +149,19 @@ func (s threadUnsafeSet[T]) Equal(other Set[T]) bool { return true } -func (s threadUnsafeSet[T]) Intersect(other Set[T]) Set[T] { - o := other.(threadUnsafeSet[T]) +func (s *threadUnsafeSet[T]) Intersect(other Set[T]) Set[T] { + o := other.(*threadUnsafeSet[T]) intersection := newThreadUnsafeSet[T]() // loop over smaller set if s.Cardinality() < other.Cardinality() { - for elem := range s { + for elem := range *s { if o.contains(elem) { intersection.add(elem) } } } else { - for elem := range o { + for elem := range *o { if s.contains(elem) { intersection.add(elem) } @@ -168,24 +170,24 @@ func (s threadUnsafeSet[T]) Intersect(other Set[T]) Set[T] { return intersection } -func (s threadUnsafeSet[T]) IsEmpty() bool { +func (s *threadUnsafeSet[T]) IsEmpty() bool { return s.Cardinality() == 0 } -func (s threadUnsafeSet[T]) IsProperSubset(other Set[T]) bool { +func (s *threadUnsafeSet[T]) IsProperSubset(other Set[T]) bool { return s.Cardinality() < other.Cardinality() && s.IsSubset(other) } -func (s threadUnsafeSet[T]) IsProperSuperset(other Set[T]) bool { +func (s *threadUnsafeSet[T]) IsProperSuperset(other Set[T]) bool { return s.Cardinality() > other.Cardinality() && s.IsSuperset(other) } -func (s threadUnsafeSet[T]) IsSubset(other Set[T]) bool { - o := other.(threadUnsafeSet[T]) +func (s *threadUnsafeSet[T]) IsSubset(other Set[T]) bool { + o := other.(*threadUnsafeSet[T]) if s.Cardinality() > other.Cardinality() { return false } - for elem := range s { + for elem := range *s { if !o.contains(elem) { return false } @@ -193,14 +195,14 @@ func (s threadUnsafeSet[T]) IsSubset(other Set[T]) bool { return true } -func (s threadUnsafeSet[T]) IsSuperset(other Set[T]) bool { +func (s *threadUnsafeSet[T]) IsSuperset(other Set[T]) bool { return other.IsSubset(s) } -func (s threadUnsafeSet[T]) Iter() <-chan T { +func (s *threadUnsafeSet[T]) Iter() <-chan T { ch := make(chan T) go func() { - for elem := range s { + for elem := range *s { ch <- elem } close(ch) @@ -209,12 +211,12 @@ func (s threadUnsafeSet[T]) Iter() <-chan T { return ch } -func (s threadUnsafeSet[T]) Iterator() *Iterator[T] { +func (s *threadUnsafeSet[T]) Iterator() *Iterator[T] { iterator, ch, stopCh := newIterator[T]() go func() { L: - for elem := range s { + for elem := range *s { select { case <-stopCh: break L @@ -229,9 +231,9 @@ func (s threadUnsafeSet[T]) Iterator() *Iterator[T] { // Pop returns a popped item in case set is not empty, or nil-value of T // if set is already empty -func (s threadUnsafeSet[T]) Pop() (v T, ok bool) { - for item := range s { - delete(s, item) +func (s *threadUnsafeSet[T]) Pop() (v T, ok bool) { + for item := range *s { + delete(*s, item) return item, true } return v, false @@ -256,16 +258,16 @@ func (s threadUnsafeSet[T]) String() string { return fmt.Sprintf("Set{%s}", strings.Join(items, ", ")) } -func (s threadUnsafeSet[T]) SymmetricDifference(other Set[T]) Set[T] { - o := other.(threadUnsafeSet[T]) +func (s *threadUnsafeSet[T]) SymmetricDifference(other Set[T]) Set[T] { + o := other.(*threadUnsafeSet[T]) sd := newThreadUnsafeSet[T]() - for elem := range s { + for elem := range *s { if !o.contains(elem) { sd.add(elem) } } - for elem := range o { + for elem := range *o { if !s.contains(elem) { sd.add(elem) } @@ -283,7 +285,7 @@ func (s threadUnsafeSet[T]) ToSlice() []T { } func (s threadUnsafeSet[T]) Union(other Set[T]) Set[T] { - o := other.(threadUnsafeSet[T]) + o := other.(*threadUnsafeSet[T]) n := s.Cardinality() if o.Cardinality() > n { @@ -294,10 +296,10 @@ func (s threadUnsafeSet[T]) Union(other Set[T]) Set[T] { for elem := range s { unionedSet.add(elem) } - for elem := range o { + for elem := range *o { unionedSet.add(elem) } - return unionedSet + return &unionedSet } // MarshalJSON creates a JSON array from the set, it marshals all elements @@ -318,7 +320,7 @@ func (s threadUnsafeSet[T]) MarshalJSON() ([]byte, error) { // UnmarshalJSON recreates a set from a JSON array, it only decodes // primitive types. Numbers are decoded as json.Number. -func (s threadUnsafeSet[T]) UnmarshalJSON(b []byte) error { +func (s *threadUnsafeSet[T]) UnmarshalJSON(b []byte) error { var i []T err := json.Unmarshal(b, &i) if err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index ffdd2c2..120facd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/deckarep/golang-set/v2 v2.6.0 +# github.com/deckarep/golang-set/v2 v2.7.0 ## explicit; go 1.18 github.com/deckarep/golang-set/v2 # github.com/go-openapi/strfmt v0.21.3 => github.com/kubewarden/strfmt v0.1.3