Deployment Controller - don't copy pods in getPodMapForDeployment
As the benchmark shows it speeds up the method~x4 and reduces memory consumption ~x20. ``` benchmark old ns/op new ns/op delta BenchmarkGetPodMapForDeployment-12 276121 72591 -73.71% benchmark old allocs new allocs delta BenchmarkGetPodMapForDeployment-12 241 238 -1.24% benchmark old bytes new bytes delta BenchmarkGetPodMapForDeployment-12 554025 28956 -94.77% ```
This commit is contained in:
@@ -88,7 +88,7 @@ func TestOldPodsRunning(t *testing.T) {
|
||||
|
||||
newRS *apps.ReplicaSet
|
||||
oldRSs []*apps.ReplicaSet
|
||||
podMap map[types.UID]*v1.PodList
|
||||
podMap map[types.UID][]*v1.Pod
|
||||
|
||||
hasOldPodsRunning bool
|
||||
}{
|
||||
@@ -115,18 +115,16 @@ func TestOldPodsRunning(t *testing.T) {
|
||||
{
|
||||
name: "old RSs with zero status replicas but pods in terminal state are present",
|
||||
oldRSs: []*apps.ReplicaSet{newRSWithStatus("rs-1", 0, 0, nil)},
|
||||
podMap: map[types.UID]*v1.PodList{
|
||||
podMap: map[types.UID][]*v1.Pod{
|
||||
"uid-1": {
|
||||
Items: []v1.Pod{
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodFailed,
|
||||
},
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodFailed,
|
||||
},
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodSucceeded,
|
||||
},
|
||||
},
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodSucceeded,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -136,13 +134,11 @@ func TestOldPodsRunning(t *testing.T) {
|
||||
{
|
||||
name: "old RSs with zero status replicas but pod in unknown phase present",
|
||||
oldRSs: []*apps.ReplicaSet{newRSWithStatus("rs-1", 0, 0, nil)},
|
||||
podMap: map[types.UID]*v1.PodList{
|
||||
podMap: map[types.UID][]*v1.Pod{
|
||||
"uid-1": {
|
||||
Items: []v1.Pod{
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodUnknown,
|
||||
},
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodUnknown,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -152,13 +148,11 @@ func TestOldPodsRunning(t *testing.T) {
|
||||
{
|
||||
name: "old RSs with zero status replicas with pending pod present",
|
||||
oldRSs: []*apps.ReplicaSet{newRSWithStatus("rs-1", 0, 0, nil)},
|
||||
podMap: map[types.UID]*v1.PodList{
|
||||
podMap: map[types.UID][]*v1.Pod{
|
||||
"uid-1": {
|
||||
Items: []v1.Pod{
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodPending,
|
||||
},
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodPending,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -168,13 +162,11 @@ func TestOldPodsRunning(t *testing.T) {
|
||||
{
|
||||
name: "old RSs with zero status replicas with running pod present",
|
||||
oldRSs: []*apps.ReplicaSet{newRSWithStatus("rs-1", 0, 0, nil)},
|
||||
podMap: map[types.UID]*v1.PodList{
|
||||
podMap: map[types.UID][]*v1.Pod{
|
||||
"uid-1": {
|
||||
Items: []v1.Pod{
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodRunning,
|
||||
},
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodRunning,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -184,30 +176,24 @@ func TestOldPodsRunning(t *testing.T) {
|
||||
{
|
||||
name: "old RSs with zero status replicas but pods in terminal state and pending are present",
|
||||
oldRSs: []*apps.ReplicaSet{newRSWithStatus("rs-1", 0, 0, nil)},
|
||||
podMap: map[types.UID]*v1.PodList{
|
||||
podMap: map[types.UID][]*v1.Pod{
|
||||
"uid-1": {
|
||||
Items: []v1.Pod{
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodFailed,
|
||||
},
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodFailed,
|
||||
},
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodSucceeded,
|
||||
},
|
||||
},
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodSucceeded,
|
||||
},
|
||||
},
|
||||
},
|
||||
"uid-2": {
|
||||
Items: []v1.Pod{},
|
||||
},
|
||||
"uid-2": {},
|
||||
"uid-3": {
|
||||
Items: []v1.Pod{
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodPending,
|
||||
},
|
||||
{
|
||||
Status: v1.PodStatus{
|
||||
Phase: v1.PodPending,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -232,14 +218,12 @@ func rsWithUID(uid string) *apps.ReplicaSet {
|
||||
return rs
|
||||
}
|
||||
|
||||
func podMapWithUIDs(uids []string) map[types.UID]*v1.PodList {
|
||||
podMap := make(map[types.UID]*v1.PodList)
|
||||
func podMapWithUIDs(uids []string) map[types.UID][]*v1.Pod {
|
||||
podMap := make(map[types.UID][]*v1.Pod)
|
||||
for _, uid := range uids {
|
||||
podMap[types.UID(uid)] = &v1.PodList{
|
||||
Items: []v1.Pod{
|
||||
{ /* supposedly a pod */ },
|
||||
{ /* supposedly another pod pod */ },
|
||||
},
|
||||
podMap[types.UID(uid)] = []*v1.Pod{
|
||||
{ /* supposedly a pod */ },
|
||||
{ /* supposedly another pod pod */ },
|
||||
}
|
||||
}
|
||||
return podMap
|
||||
|
Reference in New Issue
Block a user