mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 11:13:48 +00:00
Add HostIPs for kubelet
This commit is contained in:
parent
dacb689002
commit
e6bdd224c1
@ -1732,7 +1732,7 @@ func (kl *Kubelet) generateAPIPodStatus(pod *v1.Pod, podStatus *kubecontainer.Po
|
|||||||
Type: v1.PodScheduled,
|
Type: v1.PodScheduled,
|
||||||
Status: v1.ConditionTrue,
|
Status: v1.ConditionTrue,
|
||||||
})
|
})
|
||||||
// set HostIP and initialize PodIP/PodIPs for host network pods
|
// set HostIP/HostIPs and initialize PodIP/PodIPs for host network pods
|
||||||
if kl.kubeClient != nil {
|
if kl.kubeClient != nil {
|
||||||
hostIPs, err := kl.getHostIPsAnyWay()
|
hostIPs, err := kl.getHostIPsAnyWay()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1746,6 +1746,13 @@ func (kl *Kubelet) generateAPIPodStatus(pod *v1.Pod, podStatus *kubecontainer.Po
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.HostIP = hostIPs[0].String()
|
s.HostIP = hostIPs[0].String()
|
||||||
|
if utilfeature.DefaultFeatureGate.Enabled(features.PodHostIPs) {
|
||||||
|
s.HostIPs = []v1.HostIP{{IP: s.HostIP}}
|
||||||
|
if len(hostIPs) == 2 {
|
||||||
|
s.HostIPs = append(s.HostIPs, v1.HostIP{IP: hostIPs[1].String()})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// HostNetwork Pods inherit the node IPs as PodIPs. They are immutable once set,
|
// HostNetwork Pods inherit the node IPs as PodIPs. They are immutable once set,
|
||||||
// other than that if the node becomes dual-stack, we add the secondary IP.
|
// other than that if the node becomes dual-stack, we add the secondary IP.
|
||||||
if kubecontainer.IsHostNetworkPod(pod) {
|
if kubecontainer.IsHostNetworkPod(pod) {
|
||||||
|
@ -3244,6 +3244,7 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
|||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
enablePodHostIPs bool // enable PodHostIPs feature gate
|
||||||
pod *v1.Pod
|
pod *v1.Pod
|
||||||
currentStatus *kubecontainer.PodStatus
|
currentStatus *kubecontainer.PodStatus
|
||||||
unreadyContainer []string
|
unreadyContainer []string
|
||||||
@ -3329,9 +3330,11 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
|||||||
runningState("containerB"),
|
runningState("containerB"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
enablePodHostIPs: true,
|
||||||
expected: v1.PodStatus{
|
expected: v1.PodStatus{
|
||||||
Phase: v1.PodRunning,
|
Phase: v1.PodRunning,
|
||||||
HostIP: "127.0.0.1",
|
HostIP: "127.0.0.1",
|
||||||
|
HostIPs: []v1.HostIP{{IP: "127.0.0.1"}, {IP: "::1"}},
|
||||||
QOSClass: v1.PodQOSBestEffort,
|
QOSClass: v1.PodQOSBestEffort,
|
||||||
Conditions: []v1.PodCondition{
|
Conditions: []v1.PodCondition{
|
||||||
{Type: v1.PodInitialized, Status: v1.ConditionTrue},
|
{Type: v1.PodInitialized, Status: v1.ConditionTrue},
|
||||||
@ -3367,9 +3370,11 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
|||||||
runningState("containerB"),
|
runningState("containerB"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
enablePodHostIPs: true,
|
||||||
expected: v1.PodStatus{
|
expected: v1.PodStatus{
|
||||||
Phase: v1.PodRunning,
|
Phase: v1.PodRunning,
|
||||||
HostIP: "127.0.0.1",
|
HostIP: "127.0.0.1",
|
||||||
|
HostIPs: []v1.HostIP{{IP: "127.0.0.1"}, {IP: "::1"}},
|
||||||
QOSClass: v1.PodQOSBestEffort,
|
QOSClass: v1.PodQOSBestEffort,
|
||||||
Conditions: []v1.PodCondition{
|
Conditions: []v1.PodCondition{
|
||||||
{Type: v1.PodInitialized, Status: v1.ConditionTrue},
|
{Type: v1.PodInitialized, Status: v1.ConditionTrue},
|
||||||
@ -3406,9 +3411,11 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
|||||||
runningState("containerB"),
|
runningState("containerB"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
enablePodHostIPs: true,
|
||||||
expected: v1.PodStatus{
|
expected: v1.PodStatus{
|
||||||
Phase: v1.PodSucceeded,
|
Phase: v1.PodSucceeded,
|
||||||
HostIP: "127.0.0.1",
|
HostIP: "127.0.0.1",
|
||||||
|
HostIPs: []v1.HostIP{{IP: "127.0.0.1"}, {IP: "::1"}},
|
||||||
QOSClass: v1.PodQOSBestEffort,
|
QOSClass: v1.PodQOSBestEffort,
|
||||||
Conditions: []v1.PodCondition{
|
Conditions: []v1.PodCondition{
|
||||||
{Type: v1.PodInitialized, Status: v1.ConditionTrue, Reason: "PodCompleted"},
|
{Type: v1.PodInitialized, Status: v1.ConditionTrue, Reason: "PodCompleted"},
|
||||||
@ -3449,9 +3456,11 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
|||||||
Reason: "Test",
|
Reason: "Test",
|
||||||
Message: "test",
|
Message: "test",
|
||||||
},
|
},
|
||||||
|
enablePodHostIPs: true,
|
||||||
expected: v1.PodStatus{
|
expected: v1.PodStatus{
|
||||||
Phase: v1.PodSucceeded,
|
Phase: v1.PodSucceeded,
|
||||||
HostIP: "127.0.0.1",
|
HostIP: "127.0.0.1",
|
||||||
|
HostIPs: []v1.HostIP{{IP: "127.0.0.1"}, {IP: "::1"}},
|
||||||
QOSClass: v1.PodQOSBestEffort,
|
QOSClass: v1.PodQOSBestEffort,
|
||||||
Conditions: []v1.PodCondition{
|
Conditions: []v1.PodCondition{
|
||||||
{Type: v1.PodInitialized, Status: v1.ConditionTrue, Reason: "PodCompleted"},
|
{Type: v1.PodInitialized, Status: v1.ConditionTrue, Reason: "PodCompleted"},
|
||||||
@ -3501,9 +3510,11 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
|||||||
Reason: "Test",
|
Reason: "Test",
|
||||||
Message: "test",
|
Message: "test",
|
||||||
},
|
},
|
||||||
|
enablePodHostIPs: true,
|
||||||
expected: v1.PodStatus{
|
expected: v1.PodStatus{
|
||||||
Phase: v1.PodSucceeded,
|
Phase: v1.PodSucceeded,
|
||||||
HostIP: "127.0.0.1",
|
HostIP: "127.0.0.1",
|
||||||
|
HostIPs: []v1.HostIP{{IP: "127.0.0.1"}, {IP: "::1"}},
|
||||||
QOSClass: v1.PodQOSBestEffort,
|
QOSClass: v1.PodQOSBestEffort,
|
||||||
Conditions: []v1.PodCondition{
|
Conditions: []v1.PodCondition{
|
||||||
{Type: v1.PodInitialized, Status: v1.ConditionTrue, Reason: "PodCompleted"},
|
{Type: v1.PodInitialized, Status: v1.ConditionTrue, Reason: "PodCompleted"},
|
||||||
@ -3542,9 +3553,11 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
|||||||
waitingState("containerB"),
|
waitingState("containerB"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
enablePodHostIPs: true,
|
||||||
expected: v1.PodStatus{
|
expected: v1.PodStatus{
|
||||||
Phase: v1.PodPending,
|
Phase: v1.PodPending,
|
||||||
HostIP: "127.0.0.1",
|
HostIP: "127.0.0.1",
|
||||||
|
HostIPs: []v1.HostIP{{IP: "127.0.0.1"}, {IP: "::1"}},
|
||||||
QOSClass: v1.PodQOSBestEffort,
|
QOSClass: v1.PodQOSBestEffort,
|
||||||
Conditions: []v1.PodCondition{
|
Conditions: []v1.PodCondition{
|
||||||
{Type: v1.PodInitialized, Status: v1.ConditionTrue},
|
{Type: v1.PodInitialized, Status: v1.ConditionTrue},
|
||||||
@ -3594,11 +3607,13 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
|||||||
runningState("containerB"),
|
runningState("containerB"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
enablePodHostIPs: true,
|
||||||
expected: v1.PodStatus{
|
expected: v1.PodStatus{
|
||||||
Phase: v1.PodPending,
|
Phase: v1.PodPending,
|
||||||
Reason: "Test",
|
Reason: "Test",
|
||||||
Message: "test",
|
Message: "test",
|
||||||
HostIP: "127.0.0.1",
|
HostIP: "127.0.0.1",
|
||||||
|
HostIPs: []v1.HostIP{{IP: "127.0.0.1"}, {IP: "::1"}},
|
||||||
QOSClass: v1.PodQOSBestEffort,
|
QOSClass: v1.PodQOSBestEffort,
|
||||||
Conditions: []v1.PodCondition{
|
Conditions: []v1.PodCondition{
|
||||||
{Type: v1.PodInitialized, Status: v1.ConditionTrue},
|
{Type: v1.PodInitialized, Status: v1.ConditionTrue},
|
||||||
@ -3654,9 +3669,11 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
|||||||
runningState("containerB"),
|
runningState("containerB"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
enablePodHostIPs: true,
|
||||||
expected: v1.PodStatus{
|
expected: v1.PodStatus{
|
||||||
Phase: v1.PodRunning,
|
Phase: v1.PodRunning,
|
||||||
HostIP: "127.0.0.1",
|
HostIP: "127.0.0.1",
|
||||||
|
HostIPs: []v1.HostIP{{IP: "127.0.0.1"}, {IP: "::1"}},
|
||||||
QOSClass: v1.PodQOSBestEffort,
|
QOSClass: v1.PodQOSBestEffort,
|
||||||
Conditions: []v1.PodCondition{
|
Conditions: []v1.PodCondition{
|
||||||
{Type: v1.PodInitialized, Status: v1.ConditionTrue},
|
{Type: v1.PodInitialized, Status: v1.ConditionTrue},
|
||||||
@ -3679,6 +3696,7 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
|||||||
for _, enablePodReadyToStartContainersCondition := range []bool{false, true} {
|
for _, enablePodReadyToStartContainersCondition := range []bool{false, true} {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodDisruptionConditions, test.enablePodDisruptionConditions)()
|
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodDisruptionConditions, test.enablePodDisruptionConditions)()
|
||||||
|
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodHostIPs, test.enablePodHostIPs)()
|
||||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodReadyToStartContainersCondition, enablePodReadyToStartContainersCondition)()
|
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodReadyToStartContainersCondition, enablePodReadyToStartContainersCondition)()
|
||||||
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
||||||
defer testKubelet.Cleanup()
|
defer testKubelet.Cleanup()
|
||||||
|
@ -109,6 +109,7 @@ func init() {
|
|||||||
const (
|
const (
|
||||||
testKubeletHostname = "127.0.0.1"
|
testKubeletHostname = "127.0.0.1"
|
||||||
testKubeletHostIP = "127.0.0.1"
|
testKubeletHostIP = "127.0.0.1"
|
||||||
|
testKubeletHostIPv6 = "::1"
|
||||||
|
|
||||||
// TODO(harry) any global place for these two?
|
// TODO(harry) any global place for these two?
|
||||||
// Reasonable size range of all container images. 90%ile of images on dockerhub drops into this range.
|
// Reasonable size range of all container images. 90%ile of images on dockerhub drops into this range.
|
||||||
@ -232,6 +233,10 @@ func newTestKubeletWithImageList(
|
|||||||
Type: v1.NodeInternalIP,
|
Type: v1.NodeInternalIP,
|
||||||
Address: testKubeletHostIP,
|
Address: testKubeletHostIP,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Type: v1.NodeInternalIP,
|
||||||
|
Address: testKubeletHostIPv6,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
VolumesAttached: []v1.AttachedVolume{
|
VolumesAttached: []v1.AttachedVolume{
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user