mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-15 06:43:54 +00:00
feat: rename PodHasNetwork to PodReadyToStartContainers
This commit is contained in:
parent
f871d5fabe
commit
5f489a3327
@ -630,9 +630,9 @@ const (
|
||||
// owner: @ddebroy
|
||||
// alpha: v1.25
|
||||
//
|
||||
// Enables reporting of PodHasNetwork condition in pod status after pod
|
||||
// Enables reporting of PodReadyToStartContainersCondition condition in pod status after pod
|
||||
// sandbox creation and network configuration completes successfully
|
||||
PodHasNetworkCondition featuregate.Feature = "PodHasNetworkCondition"
|
||||
PodReadyToStartContainersCondition featuregate.Feature = "PodReadyToStartContainersCondition"
|
||||
|
||||
// owner: @Huang-Wei
|
||||
// kep: https://kep.k8s.io/3521
|
||||
@ -1043,7 +1043,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
|
||||
|
||||
PodDisruptionConditions: {Default: true, PreRelease: featuregate.Beta},
|
||||
|
||||
PodHasNetworkCondition: {Default: false, PreRelease: featuregate.Alpha},
|
||||
PodReadyToStartContainersCondition: {Default: false, PreRelease: featuregate.Alpha},
|
||||
|
||||
PodSchedulingReadiness: {Default: true, PreRelease: featuregate.Beta},
|
||||
|
||||
|
@ -1605,8 +1605,8 @@ func (kl *Kubelet) generateAPIPodStatus(pod *v1.Pod, podStatus *kubecontainer.Po
|
||||
}
|
||||
|
||||
// set all Kubelet-owned conditions
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.PodHasNetworkCondition) {
|
||||
s.Conditions = append(s.Conditions, status.GeneratePodHasNetworkCondition(pod, podStatus))
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.PodReadyToStartContainersCondition) {
|
||||
s.Conditions = append(s.Conditions, status.GeneratePodReadyToStartContainersCondition(pod, podStatus))
|
||||
}
|
||||
s.Conditions = append(s.Conditions, status.GeneratePodInitializedCondition(&pod.Spec, s.InitContainerStatuses, s.Phase))
|
||||
s.Conditions = append(s.Conditions, status.GeneratePodReadyCondition(&pod.Spec, s.Conditions, s.ContainerStatuses, s.Phase))
|
||||
|
@ -2819,16 +2819,16 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
||||
normalized_now := now.Rfc3339Copy()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
pod *v1.Pod
|
||||
currentStatus *kubecontainer.PodStatus
|
||||
unreadyContainer []string
|
||||
previousStatus v1.PodStatus
|
||||
isPodTerminal bool
|
||||
enablePodDisruptionConditions bool
|
||||
expected v1.PodStatus
|
||||
expectedPodDisruptionCondition v1.PodCondition
|
||||
expectedPodHasNetworkCondition v1.PodCondition
|
||||
name string
|
||||
pod *v1.Pod
|
||||
currentStatus *kubecontainer.PodStatus
|
||||
unreadyContainer []string
|
||||
previousStatus v1.PodStatus
|
||||
isPodTerminal bool
|
||||
enablePodDisruptionConditions bool
|
||||
expected v1.PodStatus
|
||||
expectedPodDisruptionCondition v1.PodCondition
|
||||
expectedPodReadyToStartContainersCondition v1.PodCondition
|
||||
}{
|
||||
{
|
||||
name: "pod disruption condition is copied over and the phase is set to failed when deleted; PodDisruptionConditions enabled",
|
||||
@ -2881,8 +2881,8 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
||||
Status: v1.ConditionTrue,
|
||||
LastTransitionTime: normalized_now,
|
||||
},
|
||||
expectedPodHasNetworkCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodHasNetwork,
|
||||
expectedPodReadyToStartContainersCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodReadyToStartContainers,
|
||||
Status: v1.ConditionTrue,
|
||||
},
|
||||
},
|
||||
@ -2920,8 +2920,8 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
||||
ready(waitingWithLastTerminationUnknown("containerB", 0)),
|
||||
},
|
||||
},
|
||||
expectedPodHasNetworkCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodHasNetwork,
|
||||
expectedPodReadyToStartContainersCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodReadyToStartContainers,
|
||||
Status: v1.ConditionTrue,
|
||||
},
|
||||
},
|
||||
@ -2958,8 +2958,8 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
||||
ready(waitingWithLastTerminationUnknown("containerB", 1)),
|
||||
},
|
||||
},
|
||||
expectedPodHasNetworkCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodHasNetwork,
|
||||
expectedPodReadyToStartContainersCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodReadyToStartContainers,
|
||||
Status: v1.ConditionTrue,
|
||||
},
|
||||
},
|
||||
@ -2997,8 +2997,8 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
||||
ready(waitingWithLastTerminationUnknown("containerB", 1)),
|
||||
},
|
||||
},
|
||||
expectedPodHasNetworkCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodHasNetwork,
|
||||
expectedPodReadyToStartContainersCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodReadyToStartContainers,
|
||||
Status: v1.ConditionFalse,
|
||||
},
|
||||
},
|
||||
@ -3042,8 +3042,8 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
||||
Reason: "Test",
|
||||
Message: "test",
|
||||
},
|
||||
expectedPodHasNetworkCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodHasNetwork,
|
||||
expectedPodReadyToStartContainersCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodReadyToStartContainers,
|
||||
Status: v1.ConditionFalse,
|
||||
},
|
||||
},
|
||||
@ -3094,8 +3094,8 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
||||
Reason: "Test",
|
||||
Message: "test",
|
||||
},
|
||||
expectedPodHasNetworkCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodHasNetwork,
|
||||
expectedPodReadyToStartContainersCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodReadyToStartContainers,
|
||||
Status: v1.ConditionFalse,
|
||||
},
|
||||
},
|
||||
@ -3133,8 +3133,8 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
||||
ready(waitingStateWithReason("containerB", "ContainerCreating")),
|
||||
},
|
||||
},
|
||||
expectedPodHasNetworkCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodHasNetwork,
|
||||
expectedPodReadyToStartContainersCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodReadyToStartContainers,
|
||||
Status: v1.ConditionTrue,
|
||||
},
|
||||
},
|
||||
@ -3187,8 +3187,8 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
||||
ready(withID(runningStateWithStartedAt("containerB", time.Unix(1, 0).UTC()), "://foo")),
|
||||
},
|
||||
},
|
||||
expectedPodHasNetworkCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodHasNetwork,
|
||||
expectedPodReadyToStartContainersCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodReadyToStartContainers,
|
||||
Status: v1.ConditionTrue,
|
||||
},
|
||||
},
|
||||
@ -3245,17 +3245,17 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
||||
ready(withID(runningStateWithStartedAt("containerB", time.Unix(2, 0).UTC()), "://c2")),
|
||||
},
|
||||
},
|
||||
expectedPodHasNetworkCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodHasNetwork,
|
||||
expectedPodReadyToStartContainersCondition: v1.PodCondition{
|
||||
Type: kubetypes.PodReadyToStartContainers,
|
||||
Status: v1.ConditionTrue,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
for _, enablePodHasNetworkCondition := range []bool{false, true} {
|
||||
for _, enablePodReadyToStartContainersCondition := range []bool{false, true} {
|
||||
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.PodHasNetworkCondition, enablePodHasNetworkCondition)()
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodReadyToStartContainersCondition, enablePodReadyToStartContainersCondition)()
|
||||
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
||||
defer testKubelet.Cleanup()
|
||||
kl := testKubelet.kubelet
|
||||
@ -3265,8 +3265,8 @@ func Test_generateAPIPodStatus(t *testing.T) {
|
||||
}
|
||||
expected := test.expected.DeepCopy()
|
||||
actual := kl.generateAPIPodStatus(test.pod, test.currentStatus, test.isPodTerminal)
|
||||
if enablePodHasNetworkCondition {
|
||||
expected.Conditions = append([]v1.PodCondition{test.expectedPodHasNetworkCondition}, expected.Conditions...)
|
||||
if enablePodReadyToStartContainersCondition {
|
||||
expected.Conditions = append([]v1.PodCondition{test.expectedPodReadyToStartContainersCondition}, expected.Conditions...)
|
||||
}
|
||||
if test.enablePodDisruptionConditions {
|
||||
expected.Conditions = append([]v1.PodCondition{test.expectedPodDisruptionCondition}, expected.Conditions...)
|
||||
|
@ -198,7 +198,7 @@ func GeneratePodInitializedCondition(spec *v1.PodSpec, containerStatuses []v1.Co
|
||||
}
|
||||
}
|
||||
|
||||
func GeneratePodHasNetworkCondition(pod *v1.Pod, podStatus *kubecontainer.PodStatus) v1.PodCondition {
|
||||
func GeneratePodReadyToStartContainersCondition(pod *v1.Pod, podStatus *kubecontainer.PodStatus) v1.PodCondition {
|
||||
newSandboxNeeded, _, _ := runtimeutil.PodSandboxChanged(pod, podStatus)
|
||||
// if a new sandbox does not need to be created for a pod, it indicates that
|
||||
// a sandbox for the pod with networking configured already exists.
|
||||
@ -206,12 +206,12 @@ func GeneratePodHasNetworkCondition(pod *v1.Pod, podStatus *kubecontainer.PodSta
|
||||
// fresh sandbox and configure networking for the sandbox.
|
||||
if !newSandboxNeeded {
|
||||
return v1.PodCondition{
|
||||
Type: kubetypes.PodHasNetwork,
|
||||
Type: kubetypes.PodReadyToStartContainers,
|
||||
Status: v1.ConditionTrue,
|
||||
}
|
||||
}
|
||||
return v1.PodCondition{
|
||||
Type: kubetypes.PodHasNetwork,
|
||||
Type: kubetypes.PodReadyToStartContainers,
|
||||
Status: v1.ConditionFalse,
|
||||
}
|
||||
}
|
||||
|
@ -422,7 +422,7 @@ func TestGeneratePodInitializedCondition(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneratePodHasNetworkCondition(t *testing.T) {
|
||||
func TestGeneratePodReadyToStartContainersCondition(t *testing.T) {
|
||||
for desc, test := range map[string]struct {
|
||||
pod *v1.Pod
|
||||
status *kubecontainer.PodStatus
|
||||
@ -485,8 +485,8 @@ func TestGeneratePodHasNetworkCondition(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(desc, func(t *testing.T) {
|
||||
test.expected.Type = kubetypes.PodHasNetwork
|
||||
condition := GeneratePodHasNetworkCondition(test.pod, test.status)
|
||||
test.expected.Type = kubetypes.PodReadyToStartContainers
|
||||
condition := GeneratePodReadyToStartContainersCondition(test.pod, test.status)
|
||||
require.Equal(t, test.expected.Type, condition.Type)
|
||||
require.Equal(t, test.expected.Status, condition.Status)
|
||||
})
|
||||
|
@ -589,8 +589,8 @@ func (m *manager) updateStatusInternal(pod *v1.Pod, status v1.PodStatus, forceUp
|
||||
// Set InitializedCondition.LastTransitionTime.
|
||||
updateLastTransitionTime(&status, &oldStatus, v1.PodInitialized)
|
||||
|
||||
// Set PodHasNetwork.LastTransitionTime.
|
||||
updateLastTransitionTime(&status, &oldStatus, kubetypes.PodHasNetwork)
|
||||
// Set PodReadyToStartContainersCondition.LastTransitionTime.
|
||||
updateLastTransitionTime(&status, &oldStatus, kubetypes.PodReadyToStartContainers)
|
||||
|
||||
// Set PodScheduledCondition.LastTransitionTime.
|
||||
updateLastTransitionTime(&status, &oldStatus, v1.PodScheduled)
|
||||
|
@ -43,8 +43,7 @@ const (
|
||||
// entries here should be moved to staging/src/k8s.io.api/core/v1/types.go
|
||||
// once the feature managing the condition graduates to Beta.
|
||||
const (
|
||||
// PodHasNetwork indicates networking has been configured successfully for the
|
||||
// pod and IP address(es) assigned. Images for containers specified in the pod
|
||||
// spec can be pulled and containers launched after this condition is true.
|
||||
PodHasNetwork = "PodHasNetwork"
|
||||
// PodReadyToStartContainers pod sandbox is successfully configured and
|
||||
// the pod is ready to launch containers.
|
||||
PodReadyToStartContainers = "PodReadyToStartContainers"
|
||||
)
|
||||
|
@ -37,8 +37,8 @@ func PodConditionByKubelet(conditionType v1.PodConditionType) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.PodHasNetworkCondition) {
|
||||
if conditionType == PodHasNetwork {
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.PodReadyToStartContainersCondition) {
|
||||
if conditionType == PodReadyToStartContainers {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
func TestPodConditionByKubelet(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodHasNetworkCondition, true)()
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodReadyToStartContainersCondition, true)()
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodDisruptionConditions, true)()
|
||||
|
||||
trueCases := []v1.PodConditionType{
|
||||
@ -34,7 +34,7 @@ func TestPodConditionByKubelet(t *testing.T) {
|
||||
v1.PodReady,
|
||||
v1.PodInitialized,
|
||||
v1.ContainersReady,
|
||||
PodHasNetwork,
|
||||
PodReadyToStartContainers,
|
||||
}
|
||||
|
||||
for _, tc := range trueCases {
|
||||
|
@ -47,10 +47,10 @@ var _ = SIGDescribe("Pod conditions managed by Kubelet", func() {
|
||||
f := framework.NewDefaultFramework("pod-conditions")
|
||||
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline
|
||||
|
||||
ginkgo.Context("including PodHasNetwork condition [Serial] [Feature:PodHasNetwork]", func() {
|
||||
ginkgo.Context("including PodReadyToStartContainers condition [Serial] [Feature:PodReadyToStartContainersCondition]", func() {
|
||||
tempSetCurrentKubeletConfig(f, func(ctx context.Context, initialConfig *kubeletconfig.KubeletConfiguration) {
|
||||
initialConfig.FeatureGates = map[string]bool{
|
||||
string(features.PodHasNetworkCondition): true,
|
||||
string(features.PodReadyToStartContainersCondition): true,
|
||||
}
|
||||
})
|
||||
ginkgo.It("a pod without init containers should report all conditions set in expected order after the pod is up", runPodReadyConditionsTest(f, false, true))
|
||||
@ -59,7 +59,7 @@ var _ = SIGDescribe("Pod conditions managed by Kubelet", func() {
|
||||
ginkgo.It("a pod failing to mount volumes and with init containers should report just the scheduled condition set", runPodFailingConditionsTest(f, true, true))
|
||||
})
|
||||
|
||||
ginkgo.Context("without PodHasNetwork condition", func() {
|
||||
ginkgo.Context("without PodReadyToStartContainersCondition condition", func() {
|
||||
ginkgo.It("a pod without init containers should report all conditions set in expected order after the pod is up", runPodReadyConditionsTest(f, false, false))
|
||||
ginkgo.It("a pod with init containers should report all conditions set in expected order after the pod is up", runPodReadyConditionsTest(f, true, false))
|
||||
ginkgo.It("a pod failing to mount volumes and without init containers should report scheduled and initialized conditions set", runPodFailingConditionsTest(f, false, false))
|
||||
@ -67,7 +67,7 @@ var _ = SIGDescribe("Pod conditions managed by Kubelet", func() {
|
||||
})
|
||||
})
|
||||
|
||||
func runPodFailingConditionsTest(f *framework.Framework, hasInitContainers, checkPodHasNetwork bool) func(ctx context.Context) {
|
||||
func runPodFailingConditionsTest(f *framework.Framework, hasInitContainers, checkPodReadyToStart bool) func(ctx context.Context) {
|
||||
return func(ctx context.Context) {
|
||||
ginkgo.By("creating a pod whose sandbox creation is blocked due to a missing volume")
|
||||
|
||||
@ -109,9 +109,9 @@ func runPodFailingConditionsTest(f *framework.Framework, hasInitContainers, chec
|
||||
scheduledTime, err := getTransitionTimeForPodConditionWithStatus(p, v1.PodScheduled, true)
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
// Verify PodHasNetwork is not set (since sandboxcreation is blocked)
|
||||
if checkPodHasNetwork {
|
||||
_, err := getTransitionTimeForPodConditionWithStatus(p, kubetypes.PodHasNetwork, false)
|
||||
// Verify PodReadyToStartContainers is not set (since sandboxcreation is blocked)
|
||||
if checkPodReadyToStart {
|
||||
_, err := getTransitionTimeForPodConditionWithStatus(p, kubetypes.PodReadyToStartContainers, false)
|
||||
framework.ExpectNoError(err)
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ func runPodFailingConditionsTest(f *framework.Framework, hasInitContainers, chec
|
||||
}
|
||||
}
|
||||
|
||||
func runPodReadyConditionsTest(f *framework.Framework, hasInitContainers, checkPodHasNetwork bool) func(ctx context.Context) {
|
||||
func runPodReadyConditionsTest(f *framework.Framework, hasInitContainers, checkPodReadyToStart bool) func(ctx context.Context) {
|
||||
return func(ctx context.Context) {
|
||||
ginkgo.By("creating a pod that successfully comes up in a ready/running state")
|
||||
|
||||
@ -157,23 +157,23 @@ func runPodReadyConditionsTest(f *framework.Framework, hasInitContainers, checkP
|
||||
|
||||
condBeforeContainersReadyTransitionTime := initializedTime
|
||||
errSubstrIfContainersReadyTooEarly := "is initialized"
|
||||
if checkPodHasNetwork {
|
||||
hasNetworkTime, err := getTransitionTimeForPodConditionWithStatus(p, kubetypes.PodHasNetwork, true)
|
||||
if checkPodReadyToStart {
|
||||
readyToStartContainersTime, err := getTransitionTimeForPodConditionWithStatus(p, kubetypes.PodReadyToStartContainers, true)
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
if hasInitContainers {
|
||||
// With init containers, verify the sequence of conditions is: Scheduled => HasNetwork => Initialized
|
||||
framework.ExpectNotEqual(hasNetworkTime.Before(scheduledTime), true, fmt.Sprintf("pod with init containers is initialized at: %v which is before pod has network at: %v", initializedTime, hasNetworkTime))
|
||||
framework.ExpectNotEqual(initializedTime.Before(hasNetworkTime), true, fmt.Sprintf("pod with init containers is initialized at: %v which is before pod has network at: %v", initializedTime, hasNetworkTime))
|
||||
// With init containers, verify the sequence of conditions is: Scheduled => PodReadyToStartContainers => Initialized
|
||||
framework.ExpectNotEqual(readyToStartContainersTime.Before(scheduledTime), true, fmt.Sprintf("pod with init containers is initialized at: %v which is before pod has ready to start at: %v", initializedTime, readyToStartContainersTime))
|
||||
framework.ExpectNotEqual(initializedTime.Before(readyToStartContainersTime), true, fmt.Sprintf("pod with init containers is initialized at: %v which is before pod has ready to start at: %v", initializedTime, readyToStartContainersTime))
|
||||
} else {
|
||||
// Without init containers, verify the sequence of conditions is: Scheduled => Initialized => HasNetwork
|
||||
condBeforeContainersReadyTransitionTime = hasNetworkTime
|
||||
errSubstrIfContainersReadyTooEarly = "has network"
|
||||
// Without init containers, verify the sequence of conditions is: Scheduled => Initialized => PodReadyToStartContainers
|
||||
condBeforeContainersReadyTransitionTime = readyToStartContainersTime
|
||||
errSubstrIfContainersReadyTooEarly = "ready to start"
|
||||
framework.ExpectNotEqual(initializedTime.Before(scheduledTime), true, fmt.Sprintf("pod without init containers initialized at: %v which is before pod scheduled at: %v", initializedTime, scheduledTime))
|
||||
framework.ExpectNotEqual(hasNetworkTime.Before(initializedTime), true, fmt.Sprintf("pod without init containers has network at: %v which is before pod is initialized at: %v", hasNetworkTime, initializedTime))
|
||||
framework.ExpectNotEqual(readyToStartContainersTime.Before(initializedTime), true, fmt.Sprintf("pod without init containers has ready to start at: %v which is before pod is initialized at: %v", readyToStartContainersTime, initializedTime))
|
||||
}
|
||||
} else {
|
||||
// In the absence of HasNetwork feature disabled, verify the sequence is: Scheduled => Initialized
|
||||
// In the absence of PodHasReadyToStartContainers feature disabled, verify the sequence is: Scheduled => Initialized
|
||||
framework.ExpectNotEqual(initializedTime.Before(scheduledTime), true, fmt.Sprintf("pod initialized at: %v which is before pod scheduled at: %v", initializedTime, scheduledTime))
|
||||
}
|
||||
// Verify the next condition to get set is ContainersReady
|
||||
|
Loading…
Reference in New Issue
Block a user