in pkg/cni/conf/confmanager.go [212:249]
func (mgr *Manager) managePluginFromConf(file string) (map[string]interface{}, error) {
bytes, err := os.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("failed to read cni config file %s: %w", file, err)
}
rawConf, rawList := make(map[string]interface{}), make(map[string]interface{})
if err = json.Unmarshal(bytes, &rawConf); err != nil {
return nil, fmt.Errorf("failed to unmarshal cni config from file %s: %w", file, err)
}
networkName, ok := rawConf["name"]
if !ok {
return nil, fmt.Errorf("failed to find network name in %s", file)
}
rawList["name"] = networkName
delete(rawConf, "name")
cniVersion, ok := rawConf["cniVersion"]
if ok {
cniVersion, ok = cniVersion.(string)
if !ok {
return nil, fmt.Errorf("cniVersion (%v) is not in string format", cniVersion)
}
rawList["cniVersion"] = cniVersion
delete(rawConf, "cniVersion")
}
var plugins []interface{}
plugins = append(plugins, rawConf)
plugins = append(plugins, map[string]interface{}{
"type": consts.KubeEgressCNIName,
"ipam": map[string]interface{}{"type": consts.KubeEgressIPAMCNIName},
"excludedCIDRs": mgr.exceptionCidrs,
"socketPath": fmt.Sprintf("localhost:%d", mgr.grpcPort),
})
rawList["plugins"] = plugins
return rawList, nil
}