Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
Fix ReplicaType key for filtering pods and services (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
alculquicondor authored Aug 12, 2021
1 parent 6c9fe11 commit 7d3b7d9
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/controller.v1/common/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (jc *JobController) FilterPodsForReplicaType(pods []*v1.Pod, replicaType ap
var result []*v1.Pod

selector := labels.SelectorFromValidatedSet(labels.Set{
apiv1.ReplicaIndexLabel: string(replicaType),
apiv1.ReplicaTypeLabel: string(replicaType),
})

// TODO(#149): Remove deprecated selector.
Expand Down
45 changes: 45 additions & 0 deletions pkg/controller.v1/common/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,48 @@ func TestCalculatePodSliceSize(t *testing.T) {
assert.Equal(t, tc.expectedSize, result)
}
}

func TestFilterPodsForReplicaType(t *testing.T) {
pods := []*v1.Pod{
{
ObjectMeta: metav1.ObjectMeta{
Name: "a",
Labels: map[string]string{apiv1.ReplicaTypeLabel: "foo"},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "b",
Labels: map[string]string{apiv1.ReplicaTypeLabel: "bar"},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "c",
Labels: map[string]string{apiv1.ReplicaTypeLabelDeprecated: "foo"},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "d",
Labels: map[string]string{apiv1.ReplicaTypeLabelDeprecated: "bar"},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "e",
Labels: map[string]string{
apiv1.ReplicaTypeLabel: "foo",
apiv1.ReplicaTypeLabelDeprecated: "bar",
},
},
},
}
c := &JobController{}
got, err := c.FilterPodsForReplicaType(pods, "foo")
if err != nil {
t.Fatalf("FilterPodsForReplicaType returned error: %v", err)
}
want := []*v1.Pod{pods[0], pods[2], pods[4]}
assert.Equal(t, want, got)
}
2 changes: 1 addition & 1 deletion pkg/controller.v1/common/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (jc *JobController) FilterServicesForReplicaType(services []*v1.Service, re
var result []*v1.Service

selector := labels.SelectorFromValidatedSet(labels.Set{
apiv1.ReplicaIndexLabel: string(replicaType),
apiv1.ReplicaTypeLabel: string(replicaType),
})

// TODO(#149): Remove deprecated selector.
Expand Down
44 changes: 44 additions & 0 deletions pkg/controller.v1/common/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,47 @@ func TestJobController_CreateNewService(t *testing.T) {
})
}
}
func TestFilterServicesForReplicaType(t *testing.T) {
services := []*v1.Service{
{
ObjectMeta: metav1.ObjectMeta{
Name: "a",
Labels: map[string]string{apiv1.ReplicaTypeLabel: "foo"},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "b",
Labels: map[string]string{apiv1.ReplicaTypeLabel: "bar"},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "c",
Labels: map[string]string{apiv1.ReplicaTypeLabelDeprecated: "foo"},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "d",
Labels: map[string]string{apiv1.ReplicaTypeLabelDeprecated: "bar"},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "e",
Labels: map[string]string{
apiv1.ReplicaTypeLabel: "foo",
apiv1.ReplicaTypeLabelDeprecated: "bar",
},
},
},
}
c := &JobController{}
got, err := c.FilterServicesForReplicaType(services, "foo")
if err != nil {
t.Fatalf("FilterPodsForReplicaType returned error: %v", err)
}
want := []*v1.Service{services[0], services[2], services[4]}
assert.Equal(t, want, got)
}

0 comments on commit 7d3b7d9

Please sign in to comment.