mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Merge pull request #389 from brendandburns/podip
Add PodIP to the info returned for a pod.
This commit is contained in:
commit
06ac51e6e5
@ -198,6 +198,7 @@ type PodState struct {
|
||||
Status PodStatus `json:"status,omitempty" yaml:"status,omitempty"`
|
||||
Host string `json:"host,omitempty" yaml:"host,omitempty"`
|
||||
HostIP string `json:"hostIP,omitempty" yaml:"hostIP,omitempty"`
|
||||
PodIP string `json:"podIP,omitempty" yaml:"podIP,omitempty"`
|
||||
|
||||
// The key of this map is the *name* of the container within the manifest; it has one
|
||||
// entry per container in the manifest. The value of this map is currently the output
|
||||
|
@ -89,6 +89,16 @@ func (storage *PodRegistryStorage) fillPodInfo(pod *api.Pod) {
|
||||
return
|
||||
}
|
||||
pod.CurrentState.Info = info
|
||||
netContainerInfo, ok := info["net"]
|
||||
if ok {
|
||||
if netContainerInfo.NetworkSettings != nil {
|
||||
pod.CurrentState.PodIP = netContainerInfo.NetworkSettings.IPAddress
|
||||
} else {
|
||||
glog.Warningf("No network settings: %#v", netContainerInfo)
|
||||
}
|
||||
} else {
|
||||
glog.Warningf("Couldn't find network container in %v", info)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -278,3 +278,69 @@ func TestCreatePod(t *testing.T) {
|
||||
// Do nothing, this is expected.
|
||||
}
|
||||
}
|
||||
|
||||
type FakePodInfoGetter struct {
|
||||
info api.PodInfo
|
||||
err error
|
||||
}
|
||||
|
||||
func (f *FakePodInfoGetter) GetPodInfo(host, podID string) (api.PodInfo, error) {
|
||||
return f.info, f.err
|
||||
}
|
||||
|
||||
func TestFillPodInfo(t *testing.T) {
|
||||
expectedIP := "1.2.3.4"
|
||||
fakeGetter := FakePodInfoGetter{
|
||||
info: map[string]docker.Container{
|
||||
"net": {
|
||||
ID: "foobar",
|
||||
Path: "bin/run.sh",
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
IPAddress: expectedIP,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
storage := PodRegistryStorage{
|
||||
podCache: &fakeGetter,
|
||||
}
|
||||
|
||||
pod := api.Pod{}
|
||||
|
||||
storage.fillPodInfo(&pod)
|
||||
|
||||
if !reflect.DeepEqual(fakeGetter.info, pod.CurrentState.Info) {
|
||||
t.Errorf("Expected: %#v, Got %#v", fakeGetter.info, pod.CurrentState.Info)
|
||||
}
|
||||
|
||||
if pod.CurrentState.PodIP != expectedIP {
|
||||
t.Errorf("Expected %s, Got %s", expectedIP, pod.CurrentState.PodIP)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFillPodInfoNoData(t *testing.T) {
|
||||
expectedIP := ""
|
||||
fakeGetter := FakePodInfoGetter{
|
||||
info: map[string]docker.Container{
|
||||
"net": {
|
||||
ID: "foobar",
|
||||
Path: "bin/run.sh",
|
||||
},
|
||||
},
|
||||
}
|
||||
storage := PodRegistryStorage{
|
||||
podCache: &fakeGetter,
|
||||
}
|
||||
|
||||
pod := api.Pod{}
|
||||
|
||||
storage.fillPodInfo(&pod)
|
||||
|
||||
if !reflect.DeepEqual(fakeGetter.info, pod.CurrentState.Info) {
|
||||
t.Errorf("Expected %#v, Got %#v", fakeGetter.info, pod.CurrentState.Info)
|
||||
}
|
||||
|
||||
if pod.CurrentState.PodIP != expectedIP {
|
||||
t.Errorf("Expected %s, Got %s", expectedIP, pod.CurrentState.PodIP)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user