From cec59c5a619dea547758590d380b9370cfcb7f30 Mon Sep 17 00:00:00 2001 From: Jonathan Crowther Date: Fri, 1 Mar 2024 11:56:18 -0500 Subject: [PATCH] Implement custom DeepCopy for Count --- go.mod | 1 - go.sum | 2 -- pkg/resources/counts/buffer.go | 3 +-- pkg/resources/counts/counts.go | 11 +++++++++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 3db23d79..23e34957 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,6 @@ require ( github.com/stretchr/testify v1.8.4 github.com/urfave/cli v1.22.14 github.com/urfave/cli/v2 v2.25.7 - golang.design/x/reflect v0.0.0-20220504060917-02c43be63f3b golang.org/x/sync v0.5.0 gopkg.in/yaml.v3 v3.0.1 k8s.io/api v0.28.6 diff --git a/go.sum b/go.sum index 65284e65..11cb33ad 100644 --- a/go.sum +++ b/go.sum @@ -396,8 +396,6 @@ go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqe go.opentelemetry.io/proto/otlp v0.19.0 h1:IVN6GR+mhC4s5yfcTbmzHYODqvWAp3ZedA2SJPI1Nnw= go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= -golang.design/x/reflect v0.0.0-20220504060917-02c43be63f3b h1:lkOPTy76R9NZ6FeDQWkDj3NsLtD8Csc9AAFYEl3kiME= -golang.design/x/reflect v0.0.0-20220504060917-02c43be63f3b/go.mod h1:QXG482h3unP32W/YwIPOc+09bvY447B7T+iLjC/JPcA= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= diff --git a/pkg/resources/counts/buffer.go b/pkg/resources/counts/buffer.go index be2ed851..9578f593 100644 --- a/pkg/resources/counts/buffer.go +++ b/pkg/resources/counts/buffer.go @@ -4,7 +4,6 @@ import ( "time" "github.com/rancher/apiserver/pkg/types" - "golang.design/x/reflect" ) // debounceDuration determines how long events will be held before they are sent to the consumer @@ -50,7 +49,7 @@ func debounceCounts(result chan types.APIEvent, input chan Count) { } case <-t.C: if currentCount != nil { - result <- toAPIEvent(reflect.DeepCopy(*currentCount)) + result <- toAPIEvent(*currentCount.DeepCopy()) currentCount = nil } } diff --git a/pkg/resources/counts/counts.go b/pkg/resources/counts/counts.go index 9a210eab..c3d75e98 100644 --- a/pkg/resources/counts/counts.go +++ b/pkg/resources/counts/counts.go @@ -48,6 +48,17 @@ type Count struct { Counts map[string]ItemCount `json:"counts"` } +func (c *Count) DeepCopy() *Count { + r := *c + if r.Counts != nil { + r.Counts = map[string]ItemCount{} + for k, v := range c.Counts { + r.Counts[k] = *v.DeepCopy() + } + } + return &r +} + type Summary struct { Count int `json:"count,omitempty"` States map[string]int `json:"states,omitempty"`