func resourceNameToIPString(name string) string {
	var ipstr string
	if strings.Contains(name, "--") || strings.Count(name, "-") > 3 {
		ipstr = strings.Replace(name, "-", ":", 7)
	} else {
		ipstr = strings.Replace(name, "-", ".", 3)
	}
	log.WithFields(log.Fields{
		"Name": name,
		"IP":   ipstr,
	}).Debug("Converting resource name to IP String")
	return ipstr
}
resourceNameToIPString converts a name used for a k8s resource to an IP address string.
This function does not check the validity of the result - it merely reverses the
character conversion used to convert an IP address to a k8s compatible name.
package resources
import (
	"fmt"
	"strings"
	"github.com/projectcalico/libcalico-go/lib/net"
	log "github.com/sirupsen/logrus"
)
func IPToResourceName(ip net.IP) string {
	name := ""
	if ip.To4() != nil {
		name = strings.Replace(ip.String(), ".", "-", 3)
	} else {
		ip6 := ip.To16()
		bytes := []string{}
		for i := 0; i < len(ip6); i += 2 {
			bytes = append(bytes, fmt.Sprintf("%.2x%.2x", ip6[i], ip6[i+1]))
		}
		name = strings.Join(bytes, "-")
	}
	log.WithFields(log.Fields{
		"Name": name,
		"IP":   ip.String(),
	}).Debug("Converting IP to resource name")
	return name
}
func ResourceNameToIP(name string) (*net.IP, error) {
	ip := net.ParseIP(resourceNameToIPString(name))
	if ip == nil {
		return nil, fmt.Errorf("invalid resource name %s: does not follow Calico IP name format", name)
	}
	return ip, nil
}