github.com/cilium/cilium@v1.16.2/pkg/k8s/synced/apigroups.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package synced 5 6 import ( 7 "github.com/cilium/cilium/pkg/lock" 8 ) 9 10 // APIGroups is a lockable map to hold which k8s API Groups we have 11 // enabled/in-use 12 // Note: We can replace it with a Go 1.9 map once we require that version 13 type APIGroups struct { 14 lock.RWMutex 15 apis map[string]bool 16 } 17 18 func (m *APIGroups) AddAPI(api string) { 19 m.Lock() 20 defer m.Unlock() 21 if m.apis == nil { 22 m.apis = make(map[string]bool) 23 } 24 m.apis[api] = true 25 } 26 27 func (m *APIGroups) RemoveAPI(api string) { 28 m.Lock() 29 defer m.Unlock() 30 delete(m.apis, api) 31 } 32 33 func (m *APIGroups) GetGroups() []string { 34 m.RLock() 35 defer m.RUnlock() 36 groups := make([]string, 0, len(m.apis)) 37 for k := range m.apis { 38 groups = append(groups, k) 39 } 40 return groups 41 }