mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-27 11:53:53 +00:00
Introduce PodHasNetwork condition for pods
Signed-off-by: Deep Debroy <ddebroy@gmail.com>
This commit is contained in:
@@ -21,7 +21,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
)
|
||||
|
||||
func TestGenerateContainersReadyCondition(t *testing.T) {
|
||||
@@ -417,6 +422,77 @@ func TestGeneratePodInitializedCondition(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneratePodHasNetworkCondition(t *testing.T) {
|
||||
for desc, test := range map[string]struct {
|
||||
pod *v1.Pod
|
||||
status *kubecontainer.PodStatus
|
||||
expected v1.PodCondition
|
||||
}{
|
||||
"Empty pod status": {
|
||||
pod: &v1.Pod{},
|
||||
status: &kubecontainer.PodStatus{},
|
||||
expected: v1.PodCondition{
|
||||
Status: v1.ConditionFalse,
|
||||
},
|
||||
},
|
||||
"Pod sandbox status not ready": {
|
||||
pod: &v1.Pod{},
|
||||
status: &kubecontainer.PodStatus{
|
||||
SandboxStatuses: []*runtimeapi.PodSandboxStatus{
|
||||
{
|
||||
Metadata: &runtimeapi.PodSandboxMetadata{Attempt: uint32(0)},
|
||||
State: runtimeapi.PodSandboxState_SANDBOX_NOTREADY,
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: v1.PodCondition{
|
||||
Status: v1.ConditionFalse,
|
||||
},
|
||||
},
|
||||
"Pod sandbox status ready but no IP configured": {
|
||||
pod: &v1.Pod{},
|
||||
status: &kubecontainer.PodStatus{
|
||||
SandboxStatuses: []*runtimeapi.PodSandboxStatus{
|
||||
{
|
||||
Network: &runtimeapi.PodSandboxNetworkStatus{
|
||||
Ip: "",
|
||||
},
|
||||
Metadata: &runtimeapi.PodSandboxMetadata{Attempt: uint32(0)},
|
||||
State: runtimeapi.PodSandboxState_SANDBOX_READY,
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: v1.PodCondition{
|
||||
Status: v1.ConditionFalse,
|
||||
},
|
||||
},
|
||||
"Pod sandbox status ready and IP configured": {
|
||||
pod: &v1.Pod{},
|
||||
status: &kubecontainer.PodStatus{
|
||||
SandboxStatuses: []*runtimeapi.PodSandboxStatus{
|
||||
{
|
||||
Network: &runtimeapi.PodSandboxNetworkStatus{
|
||||
Ip: "10.0.0.10",
|
||||
},
|
||||
Metadata: &runtimeapi.PodSandboxMetadata{Attempt: uint32(0)},
|
||||
State: runtimeapi.PodSandboxState_SANDBOX_READY,
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: v1.PodCondition{
|
||||
Status: v1.ConditionTrue,
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(desc, func(t *testing.T) {
|
||||
test.expected.Type = kubetypes.PodHasNetwork
|
||||
condition := GeneratePodHasNetworkCondition(test.pod, test.status)
|
||||
require.Equal(t, test.expected.Type, condition.Type)
|
||||
require.Equal(t, test.expected.Status, condition.Status)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func getPodCondition(conditionType v1.PodConditionType, status v1.ConditionStatus, reason, message string) v1.PodCondition {
|
||||
return v1.PodCondition{
|
||||
Type: conditionType,
|
||||
|
||||
Reference in New Issue
Block a user