Fix panic in counts

This commit is contained in:
Darren Shepherd 2020-03-25 18:15:21 -07:00
parent c4fc6869f2
commit 7b434b1338

View File

@ -54,12 +54,35 @@ type Summary struct {
Transitioning int `json:"transitioning,omitempty"`
}
func (s *Summary) DeepCopy() *Summary {
r := *s
if r.States != nil {
r.States = map[string]int{}
for k := range s.States {
r.States[k] = s.States[k]
}
}
return &r
}
type ItemCount struct {
Summary Summary `json:"summary,omitempty"`
Namespaces map[string]Summary `json:"namespaces,omitempty"`
Revision int `json:"revision,omitempty"`
}
func (i *ItemCount) DeepCopy() *ItemCount {
r := *i
r.Summary = *r.Summary.DeepCopy()
if r.Namespaces != nil {
r.Namespaces = map[string]Summary{}
for k, v := range i.Namespaces {
r.Namespaces[k] = *v.DeepCopy()
}
}
return &r
}
type Store struct {
empty.Store
ccache clustercache.ClusterCache
@ -157,15 +180,7 @@ func (s *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, w types.
counts[schema.ID] = itemCount
countsCopy := map[string]ItemCount{}
for k, v := range counts {
ns := map[string]Summary{}
for i, j := range v.Namespaces {
ns[i] = j
}
countsCopy[k] = ItemCount{
Summary: v.Summary,
Revision: v.Revision,
Namespaces: ns,
}
countsCopy[k] = *v.DeepCopy()
}
result <- types.APIEvent{