github.com/imran-kn/cilium-fork@v1.6.9/pkg/policy/groups/cache.go (about) 1 // Copyright 2018 Authors of Cilium 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package groups 16 17 import ( 18 "sync" 19 20 cilium_v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2" 21 ) 22 23 var groupsCNPCache = groupsCNPCacheMap{} 24 25 type groupsCNPCacheMap struct { 26 sync.Map 27 } 28 29 func (cnpCache *groupsCNPCacheMap) UpdateCNP(cnp *cilium_v2.CiliumNetworkPolicy) { 30 cnpCache.Store(cnp.ObjectMeta.UID, cnp) 31 } 32 33 func (cnpCache *groupsCNPCacheMap) DeleteCNP(cnp *cilium_v2.CiliumNetworkPolicy) { 34 cnpCache.Delete(cnp.ObjectMeta.UID) 35 } 36 37 func (cnpCache *groupsCNPCacheMap) GetAllCNP() []*cilium_v2.CiliumNetworkPolicy { 38 result := []*cilium_v2.CiliumNetworkPolicy{} 39 cnpCache.Range(func(k, v interface{}) bool { 40 result = append(result, v.(*cilium_v2.CiliumNetworkPolicy)) 41 return true 42 }) 43 return result 44 }