Skip to content

Commit 2b210d6

Browse files
fix: do not use bash in ip config update
1 parent c4d9408 commit 2b210d6

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

test/integration/cilium-nodesubnet/ipconfigupdate.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import (
1212
"github.com/pkg/errors"
1313
)
1414

15-
func runCommand(command string) (string, error) {
15+
func runAzCommand(params ...string) (string, error) {
1616
var out bytes.Buffer
1717
var stderr bytes.Buffer
1818
var err error
19+
fmt.Println("Running Azure CLI command ", strings.Join(params, " "))
1920
for i := 0; i < 3; i++ {
20-
cmd := exec.Command("bash", "-c", command)
21+
cmd := exec.Command("az", params...)
2122
cmd.Stdout = &out
2223
cmd.Stderr = &stderr
2324
err = cmd.Run()
@@ -27,7 +28,7 @@ func runCommand(command string) (string, error) {
2728
}
2829

2930
if err != nil {
30-
return "", errors.Wrap(err, fmt.Sprintf("command %s failed ", command))
31+
return "", errors.Wrap(err, fmt.Sprintf("command failed "+stderr.String()))
3132
}
3233

3334
return out.String(), nil
@@ -60,16 +61,14 @@ func main() {
6061
os.Exit(1)
6162
}
6263

63-
command := fmt.Sprintf("az vmss list -g %s --query '[0].name' -o tsv", resourceGroup)
64-
result, err := runCommand(command)
64+
result, err := runAzCommand("vmss", "list", "-g", resourceGroup, "--query", "[0].name", "-o", "tsv")
6565
if err != nil {
6666
fmt.Printf("Command failed with error: %s\n", err)
6767
os.Exit(1)
6868
}
6969
vmssName := strings.TrimSpace(result)
7070

71-
command = fmt.Sprintf("az vmss show -g %s -n %s", resourceGroup, vmssName)
72-
result, err = runCommand(command)
71+
result, err = runAzCommand("vmss", "show", "-g", resourceGroup, "-n", vmssName)
7372
if err != nil {
7473
fmt.Printf("Command failed with error: %s\n", err)
7574
os.Exit(1)
@@ -131,20 +130,13 @@ func main() {
131130
os.Exit(1)
132131
}
133132

134-
escapedNetworkProfileJSON := strings.ReplaceAll(string(networkProfileJSON), `\`, `\\`)
135-
escapedNetworkProfileJSON = strings.ReplaceAll(escapedNetworkProfileJSON, `'`, `\'`)
136-
137-
command = fmt.Sprintf("az vmss update -g %s -n %s --set virtualMachineProfile.networkProfile='%s'", resourceGroup, vmssName, escapedNetworkProfileJSON)
138-
fmt.Println("Command to update VMSS: ", command)
139-
_, err = runCommand(command)
133+
_, err = runAzCommand("vmss", "update", "-g", resourceGroup, "-n", vmssName, "--set", fmt.Sprintf("virtualMachineProfile.networkProfile=%s", networkProfileJSON))
140134
if err != nil {
141135
fmt.Printf("Command failed with error: %s\n", err)
142136
os.Exit(1)
143137
}
144138

145-
command = fmt.Sprintf("az vmss update-instances -g %s -n %s --instance-ids '*'", resourceGroup, vmssName)
146-
fmt.Println("Command to update VMSS instances: ", command)
147-
_, err = runCommand(command)
139+
_, err = runAzCommand("vmss", "update-instances", "-g", resourceGroup, "-n", vmssName, "--instance-ids", "*")
148140
if err != nil {
149141
fmt.Printf("Command failed with error: %s\n", err)
150142
os.Exit(1)

0 commit comments

Comments
 (0)