Skip to content

Commit

Permalink
Removing duplicate IPs for 5 node cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Arvinth C <[email protected]>
  • Loading branch information
ArvinthC3000 committed Oct 10, 2023
1 parent 08e4c04 commit e60760c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
6 changes: 5 additions & 1 deletion components/automate-cli/cmd/chef-automate/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/chef/automate/components/automate-cli/pkg/verifyserver/server"
"github.com/chef/automate/components/automate-cli/pkg/verifysystemdcreate"
"github.com/chef/automate/components/automate-deployment/pkg/cli"
"github.com/chef/automate/lib/arrayutils"
"github.com/chef/automate/lib/config"
"github.com/chef/automate/lib/httputils"
"github.com/chef/automate/lib/logger"
Expand Down Expand Up @@ -484,8 +485,11 @@ func (v *verifyCmdFlow) runVerifyServiceForRemote(batchCheckConfig models.Config
return nil, err
}

// Remove duplicates
hostIpWihtoutDuplicates := arrayutils.RemoveStringDuplicates(hostIPs)

// Starting automate-verify service on remote nodes
err = v.startServiceOnRemoteNodes(destFileName, sshConfig, hostIPs)
err = v.startServiceOnRemoteNodes(destFileName, sshConfig, hostIpWihtoutDuplicates)
if err != nil {
return nil, err
}
Expand Down
15 changes: 15 additions & 0 deletions lib/arrayutils/remove_duplicate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package arrayutils

import (
"golang.org/x/exp/slices"

Check failure on line 4 in lib/arrayutils/remove_duplicate.go

View workflow job for this annotation

GitHub Actions / SonarQube

missing go.sum entry for module providing package golang.org/x/exp/slices (imported by github.com/chef/automate/lib/arrayutils); to add:
)

func RemoveStringDuplicates(inputArray []string) []string {
arrayWithoutDuplicate := []string{}
for _, item := range inputArray {
if !slices.Contains(arrayWithoutDuplicate, item) {
arrayWithoutDuplicate = append(arrayWithoutDuplicate, item)
}
}
return arrayWithoutDuplicate
}
51 changes: 51 additions & 0 deletions lib/arrayutils/remove_duplicate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package arrayutils_test

import (
"testing"

"github.com/bmizerany/assert"
"github.com/chef/automate/lib/arrayutils"
)

func TestRemoveStringDuplicates(t *testing.T) {

testCases := []struct {
title string
inputArray []string
expectedArray []string
wantErr bool
expectedErr error
}{
{
title: "Have duplicate value",
inputArray: []string{"0.0.0.0", "0.0.0.0", "0.0.0.1"},
expectedArray: []string{"0.0.0.0", "0.0.0.1"},
wantErr: false,
expectedErr: nil,
},
{
title: "Have no duplicate value",
inputArray: []string{"0.0.0.0", "0.0.0.1"},
expectedArray: []string{"0.0.0.0", "0.0.0.1"},
wantErr: false,
expectedErr: nil,
},
{
title: "empty array",
inputArray: []string{"0.0.0.0", "0.0.0.1"},
expectedArray: []string{"0.0.0.0", "0.0.0.1"},
wantErr: false,
expectedErr: nil,
},
}
for _, testCase := range testCases {
t.Run(testCase.title, func(t *testing.T) {
output := arrayutils.RemoveStringDuplicates(testCase.inputArray)
if !testCase.wantErr {
// assert.Error(t, err)
assert.Equal(t, testCase.expectedArray, output)
}
})
}

}

0 comments on commit e60760c

Please sign in to comment.