Skip to content

Commit

Permalink
Fix the error of hostAliases when there are more than 2 hostnames (ku…
Browse files Browse the repository at this point in the history
…beflow#1209)

* Fix the error of hostAliases when there are more than 2 hostnames

* Fix the error of hostAliases when there are more than 2 hostnames

* "/spec/hostAliases/-" when existing hostAliases
  • Loading branch information
cdmikechen authored Mar 26, 2021
1 parent 0d363d8 commit 0f1afbd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 3 additions & 4 deletions pkg/webhook/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,12 +801,11 @@ func addHostAliases(pod *corev1.Pod, app *v1beta2.SparkApplication) []patchOpera
}

var ops []patchOperation
for _, v := range hostAliases {
if len(hostAliases) > 0 {
if first {
ops = append(ops, patchOperation{Op: "add", Path: "/spec/hostAliases", Value: []corev1.HostAlias{v}})
first = false
ops = append(ops, patchOperation{Op: "add", Path: "/spec/hostAliases", Value: hostAliases})
} else {
ops = append(ops, patchOperation{Op: "add", Path: "/spec/hostAliases/-", Value: &v})
ops = append(ops, patchOperation{Op: "add", Path: "/spec/hostAliases/-", Value: hostAliases})
}
}
return ops
Expand Down
12 changes: 11 additions & 1 deletion pkg/webhook/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,14 @@ func TestPatchSparkPod_HostAliases(t *testing.T) {
IP: "192.168.0.1",
Hostnames: []string{"test.com", "test2.com"},
},
{
IP: "192.168.0.2",
Hostnames: []string{"test3.com"},
},
{
IP: "192.168.0.3",
Hostnames: []string{"test4.com"},
},
},
},
},
Expand Down Expand Up @@ -1875,9 +1883,11 @@ func TestPatchSparkPod_HostAliases(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Equal(t, 2, len(modifiedDriverPod.Spec.HostAliases))
assert.Equal(t, 4, len(modifiedDriverPod.Spec.HostAliases))
assert.Equal(t, "127.0.0.1", modifiedDriverPod.Spec.HostAliases[0].IP)
assert.Equal(t, "192.168.0.1", modifiedDriverPod.Spec.HostAliases[1].IP)
assert.Equal(t, "192.168.0.2", modifiedDriverPod.Spec.HostAliases[2].IP)
assert.Equal(t, "192.168.0.3", modifiedDriverPod.Spec.HostAliases[3].IP)

executorPod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 0f1afbd

Please sign in to comment.