From a80d9bcb0a21f479d8e50f63414a4b3d0d2649d0 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Fri, 28 Aug 2020 15:03:05 -0400 Subject: [PATCH] Fix accidental broken clones Fix CSIMountOptions.Copy() and VolumeRequest.Copy() where they accidentally returned a reference to self rather than a deep copy. `&(*ref)` in Golang apparently equivalent to plain `&ref`. --- nomad/job_endpoint_hook_expose_check_test.go | 4 ++-- nomad/structs/csi.go | 7 ++++++- nomad/structs/volumes.go | 6 ++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/nomad/job_endpoint_hook_expose_check_test.go b/nomad/job_endpoint_hook_expose_check_test.go index 80c1b271c..4abf089c2 100644 --- a/nomad/job_endpoint_hook_expose_check_test.go +++ b/nomad/job_endpoint_hook_expose_check_test.go @@ -139,11 +139,11 @@ func TestJobExposeCheckHook_tgValidateUseOfCheckExpose(t *testing.T) { }) t.Run("group-service uses custom proxy but no expose", func(t *testing.T) { - withCustomProxyTaskNoExpose := &(*withCustomProxyTask) + withCustomProxyTaskNoExpose := *withCustomProxyTask withCustomProxyTask.Checks[0].Expose = false require.Nil(t, tgValidateUseOfCheckExpose(&structs.TaskGroup{ Name: "g1", - Services: []*structs.Service{withCustomProxyTaskNoExpose}, + Services: []*structs.Service{&withCustomProxyTaskNoExpose}, })) }) diff --git a/nomad/structs/csi.go b/nomad/structs/csi.go index 425d3e3cf..2c2b68885 100644 --- a/nomad/structs/csi.go +++ b/nomad/structs/csi.go @@ -4,6 +4,8 @@ import ( "fmt" "strings" "time" + + "github.com/hashicorp/nomad/helper" ) // CSISocketName is the filename that Nomad expects plugins to create inside the @@ -152,7 +154,10 @@ func (o *CSIMountOptions) Copy() *CSIMountOptions { if o == nil { return nil } - return &(*o) + + no := *o + no.MountFlags = helper.CopySliceString(o.MountFlags) + return &no } func (o *CSIMountOptions) Merge(p *CSIMountOptions) { diff --git a/nomad/structs/volumes.go b/nomad/structs/volumes.go index e29d1c42b..832c7af66 100644 --- a/nomad/structs/volumes.go +++ b/nomad/structs/volumes.go @@ -100,12 +100,10 @@ func (v *VolumeRequest) Copy() *VolumeRequest { nv := new(VolumeRequest) *nv = *v - if v.MountOptions == nil { - return nv + if v.MountOptions != nil { + nv.MountOptions = v.MountOptions.Copy() } - nv.MountOptions = &(*v.MountOptions) - return nv }