Skip to content

Commit 07f1529

Browse files
committed
remove windows compatibility
Signed-off-by: Yash Pal <yashpal2104@gmail.com>
1 parent 3fef467 commit 07f1529

File tree

1 file changed

+39
-97
lines changed
  • workspaces/controller/test/utils

1 file changed

+39
-97
lines changed

workspaces/controller/test/utils/utils.go

Lines changed: 39 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,13 @@ func UninstallIstioctl() {
8282
}
8383
}
8484

85-
// Remove istioctl binary from system
86-
osName := runtime.GOOS
87-
var rmCmd *exec.Cmd
88-
89-
if osName == "windows" {
90-
// Windows: Remove from C:\istioctl
91-
rmCmd = exec.Command("del", "/f", "/q", "C:\\istioctl\\istioctl.exe")
92-
} else {
93-
// Unix-like: Remove from local bin directory
94-
homeDir, err := os.UserHomeDir()
95-
if err != nil {
96-
warnError(fmt.Errorf("failed to get user home directory: %w", err))
97-
return
98-
}
99-
rmCmd = exec.Command("rm", "-f", homeDir+"/.local/bin/istioctl")
85+
// Remove istioctl binary from local bin directory
86+
homeDir, err := os.UserHomeDir()
87+
if err != nil {
88+
warnError(fmt.Errorf("failed to get user home directory: %w", err))
89+
return
10090
}
91+
rmCmd := exec.Command("rm", "-f", homeDir+"/.local/bin/istioctl")
10192

10293
if _, err := Run(rmCmd); err != nil {
10394
warnError(fmt.Errorf("failed to remove istioctl binary: %w", err))
@@ -123,21 +114,16 @@ func InstallIstioctl() error {
123114
return fmt.Errorf("unsupported architecture: %s", archName)
124115
}
125116

126-
// Map Go OS names to Istio release names and determine file extension
127-
var fileExt string
117+
// Map Go OS names to Istio release names
128118
switch osName {
129119
case "linux":
130120
osName = "linux"
131-
fileExt = "tar.gz"
132121
case "darwin":
133122
osName = "osx"
134-
fileExt = "tar.gz"
135-
case "windows":
136-
osName = "win"
137-
fileExt = "zip"
138123
default:
139-
return fmt.Errorf("unsupported operating system: %s", osName)
124+
return fmt.Errorf("only Linux and macOS are supported, got: %s", osName)
140125
}
126+
fileExt := "tar.gz"
141127

142128
// Construct the download URL dynamically
143129
fileName := fmt.Sprintf("istioctl-%s-%s-%s.%s", istioctlVersion, osName, archName, fileExt)
@@ -149,43 +135,25 @@ func InstallIstioctl() error {
149135
binaryName = "istioctl.exe"
150136
}
151137

152-
// Download the file using platform-appropriate method with fallbacks
138+
// Download the file using curl with wget as fallback
153139
downloadSuccess := false
154140

155-
// Try primary download method
156-
var primaryCmd *exec.Cmd
157-
var fallbackCmd *exec.Cmd
158-
159-
if osName == "win" {
160-
// Windows: PowerShell first, curl as fallback
161-
// Use proper PowerShell syntax with double quotes and escape handling
162-
primaryCmd = exec.Command("powershell", "-ExecutionPolicy", "Bypass", "-Command",
163-
fmt.Sprintf(`Invoke-WebRequest -Uri "%s" -OutFile "%s"`, url, fileName))
164-
fallbackCmd = exec.Command("curl", "-L", url, "-o", fileName)
165-
} else {
166-
// Unix-like: curl first, wget as fallback
167-
primaryCmd = exec.Command("curl", "-L", url, "-o", fileName)
168-
fallbackCmd = exec.Command("wget", "-O", fileName, url)
169-
}
170-
171-
// Try primary method
172-
primaryCmd.Stdout, primaryCmd.Stderr = os.Stdout, os.Stderr
173-
if err := primaryCmd.Run(); err == nil {
141+
// Try curl first
142+
curlCmd := exec.Command("curl", "-L", url, "-o", fileName)
143+
curlCmd.Stdout, curlCmd.Stderr = os.Stdout, os.Stderr
144+
if err := curlCmd.Run(); err == nil {
174145
downloadSuccess = true
175146
} else {
176-
// Try fallback method
177-
fallbackCmd.Stdout, fallbackCmd.Stderr = os.Stdout, os.Stderr
178-
if err := fallbackCmd.Run(); err == nil {
147+
// Try wget as fallback
148+
wgetCmd := exec.Command("wget", "-O", fileName, url)
149+
wgetCmd.Stdout, wgetCmd.Stderr = os.Stdout, os.Stderr
150+
if err := wgetCmd.Run(); err == nil {
179151
downloadSuccess = true
180152
}
181153
}
182154

183155
if !downloadSuccess {
184-
if osName == "win" {
185-
return fmt.Errorf("failed to download istioctl from %s using both PowerShell and curl", url)
186-
} else {
187-
return fmt.Errorf("failed to download istioctl from %s using both curl and wget", url)
188-
}
156+
return fmt.Errorf("failed to download istioctl from %s using both curl and wget", url)
189157
}
190158

191159
// Extract based on file type
@@ -226,69 +194,43 @@ func InstallIstioctl() error {
226194
normalizedPath := strings.TrimPrefix(binaryPath, "./")
227195
if normalizedPath != binaryName {
228196
var cpCmd *exec.Cmd
229-
if osName == "win" {
230-
cpCmd = exec.Command("copy", binaryPath, binaryName)
231-
} else {
232-
cpCmd = exec.Command("cp", binaryPath, binaryName)
233-
}
197+
cpCmd = exec.Command("cp", binaryPath, binaryName)
198+
234199
if err := cpCmd.Run(); err != nil {
235200
return fmt.Errorf("failed to copy istioctl binary: %w", err)
236201
}
237202
}
238-
239-
// Make executable (not needed on Windows)
240-
if osName != "win" {
241-
chmodCmd := exec.Command("chmod", "+x", binaryName)
242-
if err := chmodCmd.Run(); err != nil {
243-
return fmt.Errorf("failed to make istioctl executable: %w", err)
244-
}
203+
chmodCmd := exec.Command("chmod", "+x", binaryName)
204+
if err := chmodCmd.Run(); err != nil {
205+
return fmt.Errorf("failed to make istioctl executable: %w", err)
245206
}
207+
// Move to local bin directory
208+
homeDir, err := os.UserHomeDir()
209+
if err != nil {
210+
return fmt.Errorf("failed to get user home directory: %w", err)
211+
}
212+
binDir := homeDir + "/.local/bin"
246213

247-
// Move to appropriate bin directory
248-
// Use local bin directory to avoid sudo requirements
249-
var binDir string
250-
var moveCmd *exec.Cmd
251-
252-
if osName == "win" {
253-
// Use a local bin directory on Windows
254-
binDir = "C:\\istioctl"
255-
mkdirCmd := exec.Command("mkdir", "-p", binDir)
256-
mkdirCmd.Run() // Ignore errors if directory exists
257-
moveCmd = exec.Command("move", binaryName, binDir+"\\istioctl.exe")
258-
} else {
259-
// Use local bin directory instead of /usr/local/bin to avoid sudo
260-
homeDir, err := os.UserHomeDir()
261-
if err != nil {
262-
return fmt.Errorf("failed to get user home directory: %w", err)
263-
}
264-
binDir = homeDir + "/.local/bin"
265-
266-
// Create the bin directory if it doesn't exist
267-
mkdirCmd := exec.Command("mkdir", "-p", binDir)
268-
if err := mkdirCmd.Run(); err != nil {
269-
return fmt.Errorf("failed to create local bin directory: %w", err)
270-
}
271-
272-
moveCmd = exec.Command("mv", binaryName, binDir+"/istioctl")
214+
// Create the bin directory if it doesn't exist
215+
mkdirCmd := exec.Command("mkdir", "-p", binDir)
216+
if err := mkdirCmd.Run(); err != nil {
217+
return fmt.Errorf("failed to create local bin directory: %w", err)
273218
}
274219

220+
moveCmd := exec.Command("mv", binaryName, binDir+"/istioctl")
221+
275222
moveCmd.Stdout, moveCmd.Stderr = os.Stdout, os.Stderr
276223
if err := moveCmd.Run(); err != nil {
277224
return fmt.Errorf("failed to move istioctl to bin directory: %w", err)
278225
}
279226

280227
// Add to PATH notice
281-
if osName != "win" {
282-
fmt.Printf("istioctl installed to %s\n", binDir)
283-
fmt.Printf("Make sure %s is in your PATH by adding this to your shell profile:\n", binDir)
284-
fmt.Printf("export PATH=\"%s:$PATH\"\n", binDir)
285-
}
228+
fmt.Printf("istioctl installed to %s\n", binDir)
229+
fmt.Printf("Make sure %s is in your PATH by adding this to your shell profile:\n", binDir)
230+
fmt.Printf("export PATH=\"%s:$PATH\"\n", binDir)
286231

287232
// Clean up downloaded files
288233
cleanupCmd := exec.Command("rm", "-f", fileName)
289-
if osName == "win" {
290-
cleanupCmd = exec.Command("del", "/f", fileName)
291-
}
292234
cleanupCmd.Run() // Ignore cleanup errors
293235

294236
return nil

0 commit comments

Comments
 (0)