kube-router/utils/pod_cidr.go
Murali Reddy a4e773bd91 edit README and handle external (outside from cluster) access to nodeport services
by masqurading the traffic so the return traffic from the pod hits the node before
going to the client
2017-04-18 03:37:46 +05:30

25 lines
701 B
Go

package utils
import (
"fmt"
"github.com/containernetworking/cni/libcni"
"github.com/containernetworking/cni/plugins/ipam/host-local/backend/allocator"
)
func GetPodCidrDetails(cniConfFilePath string) (string, int, error) {
netconfig, err := libcni.ConfFromFile(cniConfFilePath)
if err != nil {
return "", 0, fmt.Errorf("Failed to load CNI conf: %s", err.Error())
}
var ipamConfig *allocator.IPAMConfig
ipamConfig, _, err = allocator.LoadIPAMConfig(netconfig.Bytes, "")
if err != nil {
return "", 0, fmt.Errorf("Failed to get IPAM details from the CNI conf file: %s", err.Error())
}
cidrlen, _ := ipamConfig.Subnet.Mask.Size()
return ipamConfig.Subnet.IP.String(), cidrlen, nil
}