Skip to content

Commit

Permalink
csi: remove misleading newStructs method from CSIVolume
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Oct 30, 2020
1 parent 849754c commit 852971a
Showing 1 changed file with 51 additions and 57 deletions.
108 changes: 51 additions & 57 deletions nomad/structs/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,39 +294,24 @@ type CSIVolListStub struct {

// NewCSIVolume creates the volume struct. No side-effects
func NewCSIVolume(volumeID string, index uint64) *CSIVolume {
out := &CSIVolume{
ID: volumeID,
CreateIndex: index,
ModifyIndex: index,
}
return &CSIVolume{
ID: volumeID,
Topologies: []*CSITopology{},
MountOptions: &CSIMountOptions{},
Secrets: CSISecrets{},
Parameters: map[string]string{},
Context: map[string]string{},

out.newStructs()
return out
}
ReadAllocs: map[string]*Allocation{},
WriteAllocs: map[string]*Allocation{},

func (v *CSIVolume) newStructs() {
if v.Topologies == nil {
v.Topologies = []*CSITopology{}
}
if v.Context == nil {
v.Context = map[string]string{}
}
if v.Parameters == nil {
v.Parameters = map[string]string{}
}
if v.MountOptions == nil {
v.MountOptions = &CSIMountOptions{}
}
if v.Secrets == nil {
v.Secrets = CSISecrets{}
}

v.ReadAllocs = map[string]*Allocation{}
v.WriteAllocs = map[string]*Allocation{}
ReadClaims: map[string]*CSIVolumeClaim{},
WriteClaims: map[string]*CSIVolumeClaim{},
PastClaims: map[string]*CSIVolumeClaim{},

v.ReadClaims = map[string]*CSIVolumeClaim{}
v.WriteClaims = map[string]*CSIVolumeClaim{}
v.PastClaims = map[string]*CSIVolumeClaim{}
CreateIndex: index,
ModifyIndex: index,
}
}

func (v *CSIVolume) RemoteID() string {
Expand Down Expand Up @@ -407,48 +392,57 @@ func (v *CSIVolume) InUse() bool {

// Copy returns a copy of the volume, which shares only the Topologies slice
func (v *CSIVolume) Copy() *CSIVolume {
copy := *v
out := &copy
out.newStructs()
for k, v := range v.Parameters {
out.Parameters[k] = v
out := new(CSIVolume)
*out = *v

out.Topologies = []*CSITopology{}
for _, t := range v.Topologies {
out.Topologies = append(out.Topologies, t.Copy())
}
for k, v := range v.Context {
out.Context[k] = v

out.MountOptions = new(CSIMountOptions)
if v.MountOptions != nil {
*out.MountOptions = *v.MountOptions
}

out.Secrets = CSISecrets{}
for k, v := range v.Secrets {
out.Secrets[k] = v
}
mo := *v.MountOptions
out.MountOptions = &mo

for k, v := range v.ReadAllocs {
if v != nil {
a := *v
out.ReadAllocs[k] = &a
} else {
out.ReadAllocs[k] = nil
}
out.Parameters = map[string]string{}
for k, v := range v.Parameters {
out.Parameters[k] = v
}

for k, v := range v.WriteAllocs {
if v != nil {
a := *v
out.WriteAllocs[k] = &a
} else {
out.WriteAllocs[k] = nil
}
out.Context = map[string]string{}
for k, v := range v.Context {
out.Context[k] = v
}

out.ReadAllocs = map[string]*Allocation{}
for k, alloc := range v.ReadAllocs {
out.ReadAllocs[k] = alloc.Copy()
}

out.WriteAllocs = map[string]*Allocation{}
for k, alloc := range v.WriteAllocs {
out.WriteAllocs[k] = alloc.Copy()
}

out.ReadClaims = map[string]*CSIVolumeClaim{}
for k, v := range v.ReadClaims {
claim := *v
out.ReadClaims[k] = &claim
}

out.WriteClaims = map[string]*CSIVolumeClaim{}
for k, v := range v.WriteClaims {
claim := *v
out.WriteClaims[k] = &claim
}

out.PastClaims = map[string]*CSIVolumeClaim{}
for k, v := range v.PastClaims {
claim := *v
out.PastClaims[k] = &claim
Expand Down Expand Up @@ -784,19 +778,19 @@ func (p *CSIPlugin) Copy() *CSIPlugin {
out.newStructs()

for k, v := range p.Controllers {
out.Controllers[k] = v
out.Controllers[k] = v.Copy()
}

for k, v := range p.Nodes {
out.Nodes[k] = v
out.Nodes[k] = v.Copy()
}

for k, v := range p.ControllerJobs {
out.ControllerJobs[k] = v
out.ControllerJobs[k] = v.Copy()
}

for k, v := range p.NodeJobs {
out.NodeJobs[k] = v
out.NodeJobs[k] = v.Copy()
}

return out
Expand Down

0 comments on commit 852971a

Please sign in to comment.