github.com/imran-kn/cilium-fork@v1.6.9/pkg/policy/groups/controllers.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 cilium_v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2" 19 ) 20 21 const ( 22 maxConcurrentUpdates = 4 23 ) 24 25 // UpdateCNPInformation retrieves all the CNP that has currently a derivative 26 // policy and creates the new derivatives policies with the latest information 27 // from providers. To avoid issues with rate-limiting this function will 28 // execute the addDerivative function with a max number of concurrent calls, 29 // defined on maxConcurrentUpdates. 30 func UpdateCNPInformation() { 31 32 cnpToUpdate := groupsCNPCache.GetAllCNP() 33 sem := make(chan bool, maxConcurrentUpdates) 34 for _, cnp := range cnpToUpdate { 35 sem <- true 36 go func(cnp *cilium_v2.CiliumNetworkPolicy) { 37 defer func() { <-sem }() 38 addDerivativeCNP(cnp) 39 40 }(cnp) 41 } 42 }