Skip to content

Commit

Permalink
fix(source_test.go): add missing pod status tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nefelim4ag committed Aug 29, 2023
1 parent f696c51 commit 2a1f7a4
Showing 1 changed file with 63 additions and 3 deletions.
66 changes: 63 additions & 3 deletions source/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,7 @@ func TestServiceSourceNodePortServices(t *testing.T) {
phases []v1.PodPhase
conditions []v1.PodCondition
labelSelector labels.Selector
deletionTimestamp []*metav1.Time
}{
{
title: "annotated NodePort services return an endpoint with IP addresses of the cluster's nodes",
Expand Down Expand Up @@ -1818,7 +1819,8 @@ func TestServiceSourceNodePortServices(t *testing.T) {
podNames: []string{"pod-0"},
nodeIndex: []int{1},
phases: []v1.PodPhase{v1.PodRunning},
conditions: []v1.PodCondition{{Type: v1.PodReady, Status: v1.ConditionTrue}},
conditions: []v1.PodCondition{{Type: v1.PodReady, Status: v1.ConditionFalse}},
deletionTimestamp: []*metav1.Time{{}},
},
{
title: "annotated NodePort services with ExternalTrafficPolicy=Local and multiple pods on a single node return an endpoint with unique IP addresses of the cluster's nodes where pods is running only",
Expand Down Expand Up @@ -1862,9 +1864,10 @@ func TestServiceSourceNodePortServices(t *testing.T) {
nodeIndex: []int{1, 1},
phases: []v1.PodPhase{v1.PodRunning, v1.PodRunning},
conditions: []v1.PodCondition{
{Type: v1.PodReady, Status: v1.ConditionTrue},
{Type: v1.PodReady, Status: v1.ConditionTrue},
{Type: v1.PodReady, Status: v1.ConditionFalse},
{Type: v1.PodReady, Status: v1.ConditionFalse},
},
deletionTimestamp: []*metav1.Time{{},{}},
},
{
title: "annotated NodePort services with ExternalTrafficPolicy=Local return pods in Ready & Running state",
Expand Down Expand Up @@ -1908,6 +1911,62 @@ func TestServiceSourceNodePortServices(t *testing.T) {
{Type: v1.PodReady, Status: v1.ConditionTrue},
{Type: v1.PodReady, Status: v1.ConditionFalse},
},
deletionTimestamp: []*metav1.Time{{},{}},
},
{
title: "annotated NodePort services with ExternalTrafficPolicy=Local return pods in Ready & Running state & not in Terminating",
svcNamespace: "testing",
svcName: "foo",
svcType: v1.ServiceTypeNodePort,
svcTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeLocal,
labels: map[string]string{},
annotations: map[string]string{
hostnameAnnotationKey: "foo.example.org.",
},
expected: []*endpoint.Endpoint{
{DNSName: "_foo._tcp.foo.example.org", Targets: endpoint.Targets{"0 50 30192 foo.example.org"}, RecordType: endpoint.RecordTypeSRV},
{DNSName: "foo.example.org", Targets: endpoint.Targets{"54.10.11.1"}, RecordType: endpoint.RecordTypeA},
},
nodes: []*v1.Node{{
ObjectMeta: metav1.ObjectMeta{
Name: "node1",
},
Status: v1.NodeStatus{
Addresses: []v1.NodeAddress{
{Type: v1.NodeExternalIP, Address: "54.10.11.1"},
{Type: v1.NodeInternalIP, Address: "10.0.1.1"},
},
},
}, {
ObjectMeta: metav1.ObjectMeta{
Name: "node2",
},
Status: v1.NodeStatus{
Addresses: []v1.NodeAddress{
{Type: v1.NodeExternalIP, Address: "54.10.11.2"},
{Type: v1.NodeInternalIP, Address: "10.0.1.2"},
},
},
}, {
ObjectMeta: metav1.ObjectMeta{
Name: "node3",
},
Status: v1.NodeStatus{
Addresses: []v1.NodeAddress{
{Type: v1.NodeExternalIP, Address: "54.10.11.3"},
{Type: v1.NodeInternalIP, Address: "10.0.1.3"},
},
},
}},
podNames: []string{"pod-0", "pod-1", "pod-2"},
nodeIndex: []int{0, 1, 2},
phases: []v1.PodPhase{v1.PodRunning, v1.PodRunning, v1.PodRunning},
conditions: []v1.PodCondition{
{Type: v1.PodReady, Status: v1.ConditionTrue},
{Type: v1.PodReady, Status: v1.ConditionFalse},
{Type: v1.PodReady, Status: v1.ConditionTrue},
},
deletionTimestamp: []*metav1.Time{nil, nil, {}},
},
{
title: "access=private annotation NodePort services return an endpoint with private IP addresses of the cluster's nodes",
Expand Down Expand Up @@ -2199,6 +2258,7 @@ func TestServiceSourceNodePortServices(t *testing.T) {
Name: podname,
Labels: tc.labels,
Annotations: tc.annotations,
DeletionTimestamp: tc.deletionTimestamp[i],
},
Status: v1.PodStatus{
Phase: tc.phases[i],
Expand Down

0 comments on commit 2a1f7a4

Please sign in to comment.