Skip to content

Commit

Permalink
Merge pull request #4742 from x13n/eq
Browse files Browse the repository at this point in the history
Skip pod hostname when comparing PodSpecs
  • Loading branch information
k8s-ci-robot authored Mar 16, 2022
2 parents 2b84cf6 + 109765b commit 054c52a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
19 changes: 13 additions & 6 deletions cluster-autoscaler/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,18 @@ func FilterOutNodes(nodes []*apiv1.Node, nodesToFilterOut []*apiv1.Node) []*apiv
// an equivalence group per pod which is undesirable.
// Projected volumes do not impact scheduling so we should ignore them
func PodSpecSemanticallyEqual(p1 apiv1.PodSpec, p2 apiv1.PodSpec) bool {
p1Spec := sanitizeProjectedVolumesAndMounts(p1)
p2Spec := sanitizeProjectedVolumesAndMounts(p2)
p1Spec := sanitizePodSpec(p1)
p2Spec := sanitizePodSpec(p2)
return apiequality.Semantic.DeepEqual(p1Spec, p2Spec)
}

// sanitizeProjectedVolumesAndMounts returns a pod spec with projected volumes
// and their mounts removed
func sanitizeProjectedVolumesAndMounts(podSpec apiv1.PodSpec) apiv1.PodSpec {
func sanitizePodSpec(podSpec apiv1.PodSpec) apiv1.PodSpec {
dropProjectedVolumesAndMounts(&podSpec)
dropHostname(&podSpec)
return podSpec
}

func dropProjectedVolumesAndMounts(podSpec *apiv1.PodSpec) {
projectedVolumeNames := map[string]bool{}
var volumes []apiv1.Volume
for _, v := range podSpec.Volumes {
Expand All @@ -90,5 +94,8 @@ func sanitizeProjectedVolumesAndMounts(podSpec apiv1.PodSpec) apiv1.PodSpec {
}
podSpec.Containers[i].VolumeMounts = volumeMounts
}
return podSpec
}

func dropHostname(podSpec *apiv1.PodSpec) {
podSpec.Hostname = ""
}
14 changes: 12 additions & 2 deletions cluster-autoscaler/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ func TestPodSpecSemanticallyEqual(t *testing.T) {
},
},
},
{
name: "two pods with different hostnames",
p1Spec: apiv1.PodSpec{
Hostname: "foo",
},
p2Spec: apiv1.PodSpec{
Hostname: "bar",
},
result: true,
},
}

for _, tt := range tests {
Expand All @@ -83,7 +93,7 @@ func TestPodSpecSemanticallyEqual(t *testing.T) {
}
}

func TestSanitizeProjectedVolumesAndMounts(t *testing.T) {
func TestSanitizePodSpec(t *testing.T) {
projectedSAVol := test.BuildServiceTokenProjectedVolumeSource("path")

tests := []struct {
Expand Down Expand Up @@ -170,7 +180,7 @@ func TestSanitizeProjectedVolumesAndMounts(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := sanitizeProjectedVolumesAndMounts(tt.inputPodSpec)
got := sanitizePodSpec(tt.inputPodSpec)
assert.True(t, assert.ObjectsAreEqualValues(tt.outputPodSpec, got), "\ngot: %#v\nwant: %#v", got, tt.outputPodSpec)
})
}
Expand Down

0 comments on commit 054c52a

Please sign in to comment.