Skip to content

Commit

Permalink
fix random paths (rancher#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuan Le committed Jun 18, 2023
1 parent 58eb292 commit fb7ccef
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"math/rand"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -166,6 +167,8 @@ func (p *LocalPathProvisioner) watchAndRefreshConfig() {
}()
}

var randPath = rand.New(rand.NewSource(time.Now().Unix()))

func (p *LocalPathProvisioner) getPathOnNode(node string, requestedPath string) (string, error) {
p.configMutex.RLock()
defer p.configMutex.RUnlock()
Expand Down Expand Up @@ -205,8 +208,12 @@ func (p *LocalPathProvisioner) getPathOnNode(node string, requestedPath string)
}
// if no particular path was requested, choose a random one
path := ""
i := randPath.Intn(len(paths))
for path = range paths {
break
if i == 0 {
break
}
i--
}
return path, nil
}
Expand Down

0 comments on commit fb7ccef

Please sign in to comment.