1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

fix: concurrent map read and map write when applying a validate.podSecurity rule (#11012)

Signed-off-by: Liang Deng <283304489@qq.com>
This commit is contained in:
Liang Deng 2024-09-05 01:05:10 +08:00 committed by GitHub
parent 3412109bab
commit cac7b21225
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,5 +1,7 @@
package utils
import "sync"
var PSS_baseline_control_names = []string{
"HostProcess",
"Host Namespaces",
@ -110,17 +112,21 @@ var PSS_control_name_to_ids = map[string][]string{
},
}
// reverse mapping of PSS_control_name_to_ids
var pss_control_id_to_name = map[string]string{}
var pssControlIDToNameOnce = sync.OnceValue(initPSSControlNameToIdsMapping)
func PSSControlIDToName(id string) string {
if len(pss_control_id_to_name) == 0 {
// initialize reverse mapping of PSS_control_name_to_ids
func initPSSControlNameToIdsMapping() map[string]string {
pss_control_id_to_name := make(map[string]string)
for name, ids := range PSS_control_name_to_ids {
for _, id := range ids {
pss_control_id_to_name[id] = name
}
}
}
return pss_control_id_to_name
}
func PSSControlIDToName(id string) string {
pss_control_id_to_name := pssControlIDToNameOnce()
return pss_control_id_to_name[id]
}