* Convert to runtime.Object to smaller structs This adds conversion for all the objects we want to keep in the cache. It keeps the minimum for CoreDNS to function and throws away the rest. The conversion: api.Endpoints -> object.Endpoints api.Pod -> object.Pod api.Serivce -> object.Service We needed to copy some client-go stuff to insert a conversion function into NewIndexInformers. Some unrelated cleanups in the watch functionality as that needed to be touched because of the above translation of objects. Signed-off-by: Miek Gieben <miek@miek.nl> * Reduce test line-count Signed-off-by: Miek Gieben <miek@miek.nl> * ....and fix test Signed-off-by: Miek Gieben <miek@miek.nl> * Drop use of append Signed-off-by: Miek Gieben <miek@miek.nl> * cosmetic changes Signed-off-by: Miek Gieben <miek@miek.nl> * that was a typo Signed-off-by: Miek Gieben <miek@miek.nl> * re-introduce append here We can't really use len() here because we don't know the number before hand. Signed-off-by: Miek Gieben <miek@miek.nl> * comment in better place Signed-off-by: Miek Gieben <miek@miek.nl> * Make the timestamp a bool; thats where it is used for Signed-off-by: Miek Gieben <miek@miek.nl> * Set incoming object to nil Explicataliy discard the converted object; we did a deep copy it's not needed anymore. Signed-off-by: Miek Gieben <miek@miek.nl> * Per Chris's comment Signed-off-by: Miek Gieben <miek@miek.nl>
41 lines
702 B
Go
41 lines
702 B
Go
package kubernetes
|
|
|
|
import (
|
|
"net"
|
|
)
|
|
|
|
func localPodIP() net.IP {
|
|
addrs, err := net.InterfaceAddrs()
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
for _, addr := range addrs {
|
|
ip, _, _ := net.ParseCIDR(addr.String())
|
|
ip = ip.To4()
|
|
if ip == nil || ip.IsLoopback() {
|
|
continue
|
|
}
|
|
return ip
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (k *Kubernetes) localNodeName() string {
|
|
localIP := k.interfaceAddrsFunc()
|
|
if localIP == nil {
|
|
return ""
|
|
}
|
|
|
|
// Find endpoint matching localIP
|
|
for _, ep := range k.APIConn.EpIndexReverse(localIP.String()) {
|
|
for _, eps := range ep.Subsets {
|
|
for _, addr := range eps.Addresses {
|
|
if localIP.Equal(net.ParseIP(addr.IP)) {
|
|
return addr.NodeName
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return ""
|
|
}
|