github.com/cilium/cilium@v1.16.2/pkg/policy/groups/controllers.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package groups 5 6 import ( 7 "context" 8 9 cilium_v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2" 10 "github.com/cilium/cilium/pkg/k8s/client" 11 ) 12 13 const ( 14 maxConcurrentUpdates = 4 15 ) 16 17 // UpdateCNPInformation retrieves all the CNP that has currently a derivative 18 // policy and creates the new derivatives policies with the latest information 19 // from providers. To avoid issues with rate-limiting this function will 20 // execute the addDerivative function with a max number of concurrent calls, 21 // defined on maxConcurrentUpdates. 22 func UpdateCNPInformation(clientset client.Clientset) { 23 cnpToUpdate := groupsCNPCache.GetAllCNP() 24 sem := make(chan bool, maxConcurrentUpdates) 25 for _, cnp := range cnpToUpdate { 26 sem <- true 27 go func(cnp *cilium_v2.CiliumNetworkPolicy) { 28 defer func() { <-sem }() 29 // We use the same cache for Clusterwide and Namespaced cilium policies 30 if cnp.ObjectMeta.Namespace == "" { 31 addDerivativePolicy(context.TODO(), clientset, cnp, true) 32 } else { 33 addDerivativePolicy(context.TODO(), clientset, cnp, false) 34 } 35 36 }(cnp) 37 } 38 }