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`.
This commit is contained in:
Mahmood Ali 2020-08-28 15:03:05 -04:00
parent b77fe023b5
commit 117aec0036
3 changed files with 10 additions and 7 deletions

View File

@ -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},
}))
})

View File

@ -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) {

View File

@ -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
}