Skip to content

Commit

Permalink
fix: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed Jan 23, 2025
1 parent 1184ec6 commit 5ec6822
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 37 deletions.
65 changes: 28 additions & 37 deletions pkg/check/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,13 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
}

rnd := random.PseudoGenerator(o.Seed)
names := cluster.FullNodeNames()
perm := rnd.Perm(len(names))
clients, err := cluster.ShuffledFullNodeClients(ctx, rnd)

Check failure on line 72 in pkg/check/manifest/manifest.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

ineffectual assignment to err (ineffassign)

if len(names) < 2 {
if len(clients) < 2 {
return fmt.Errorf("not enough nodes to run feed check")
}

clients, err := cluster.NodesClients(ctx)
if err != nil {
return err
}
upClient := clients[names[perm[0]]]
downClient := clients[names[perm[1]]]
upClient := clients[0]
downClient := clients[1]

err = c.checkWithoutSubDirs(ctx, rnd, o, upClient, downClient)
if err != nil {
Expand Down Expand Up @@ -229,38 +223,37 @@ func (c *Check) download(client *bee.Client, address swarm.Address, file *bee.Fi
}
c.logger.Infof("downloading file: %s/%s", address, fName)

try := 0
DOWNLOAD:
time.Sleep(5 * time.Second)
try++
if try > 5 {
return fmt.Errorf("failed getting manifest files after too many retries")
}
_, hash, err := client.DownloadManifestFile(context.Background(), address, fName)
if err != nil {
var hash []byte
for i := 0; i < 5; i++ {
_, h, err := client.DownloadManifestFile(context.Background(), address, fName)
hash = h
if err == nil {
break
}
c.logger.Infof("node %s. Error retrieving file: %s", client.Name(), err.Error())
goto DOWNLOAD
time.Sleep(5 * time.Second)
}
if hash == nil {
return fmt.Errorf("failed getting manifest files after too many retries")
}

expectedHash := indexFile.Hash()
if file != nil {
if !bytes.Equal(file.Hash(), hash) {
c.logger.Infof("node %s. File hash does not match", client.Name())
return errManifest
}
} else {
if !bytes.Equal(indexFile.Hash(), hash) {
c.logger.Infof("node %s. Index hash does not match", client.Name())
return errManifest
}
expectedHash = file.Hash()
}
c.logger.Infof("node %s. File retrieved successfully", client.Name())

if !bytes.Equal(expectedHash, hash) {
c.logger.Infof("node %s: file hash does not match", client.Name())
return errManifest
}

c.logger.Infof("node %s: file retrieved successfully", client.Name())
return nil
}

func generateFilesWithPaths(r *rand.Rand, paths []string, maxSize int) ([]bee.File, error) {
files := make([]bee.File, len(paths))
for i := 0; i < len(paths); i++ {
path := paths[i]
for i, path := range paths {
size := int64(r.Intn(maxSize)) + 1
file := bee.NewRandomFile(r, path, size)
err := file.CalculateHash()
Expand Down Expand Up @@ -306,6 +299,8 @@ func tarFiles(files []bee.File) (*bytes.Buffer, error) {
var buf bytes.Buffer
tw := tar.NewWriter(&buf)

defer tw.Close()

for _, file := range files {
// create tar header and write it
hdr := &tar.Header{
Expand All @@ -327,10 +322,6 @@ func tarFiles(files []bee.File) (*bytes.Buffer, error) {
return nil, err
}
}

if err := tw.Close(); err != nil {
return nil, err
}


return &buf, nil
}
1 change: 1 addition & 0 deletions pkg/orchestration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Cluster interface {
FlattenSettlements(ctx context.Context) (settlements NodeGroupSettlements, err error)
FlattenTopologies(ctx context.Context) (topologies map[string]bee.Topology, err error)
FullNodeNames() (names []string)
ShuffledFullNodeClients(ctx context.Context, r *rand.Rand) ([]*bee.Client, error)
GlobalReplicationFactor(ctx context.Context, a swarm.Address) (grf int, err error)
LightNodeNames() (names []string)
Name() string
Expand Down
16 changes: 16 additions & 0 deletions pkg/orchestration/k8s/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,22 @@ func (c *Cluster) FullNodeNames() (names []string) {
return
}

// ShuffledFullNodeClients returns a list of full node clients shuffled
func (c *Cluster) ShuffledFullNodeClients(ctx context.Context, r *rand.Rand) ([]*bee.Client, error) {
cls, err := c.NodesClients(ctx)
if err != nil {
return nil, err
}
var res []*bee.Client
for _, cl := range cls {
res = append(res, cl)
}
r.Shuffle(len(res), func(i, j int) {
res[i], res[j] = res[j], res[i]
})
return res, nil
}

// NodesClients returns map of node's clients in the cluster excluding stopped nodes
func (c *Cluster) NodesClients(ctx context.Context) (map[string]*bee.Client, error) {
clients := make(map[string]*bee.Client)
Expand Down

0 comments on commit 5ec6822

Please sign in to comment.