Skip to content

Commit 0c47a4e

Browse files
committed
fix(windows): pick correct helm.exe in zip for windows
1 parent 4258d77 commit 0c47a4e

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

src/aks-agent/azext_aks_agent/agent/k8s/helm_manager.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,15 @@ def _download_helm_binary(self) -> str:
131131
if member.endswith(binary_name):
132132
# Extract to local bin directory
133133
zip_file.extract(member, self.local_bin_dir)
134-
extracted_binary_path = self.local_bin_dir / Path(member).name
134+
extracted_path = self.local_bin_dir / member
135+
extracted_binary_path = self.local_bin_dir / binary_name
136+
# Move to final location if needed
137+
if extracted_path != extracted_binary_path:
138+
shutil.move(str(extracted_path), str(extracted_binary_path))
139+
# Clean up extracted directory if it exists
140+
parent_dir = extracted_path.parent
141+
if parent_dir != self.local_bin_dir and parent_dir.exists():
142+
shutil.rmtree(parent_dir)
135143
break
136144
else:
137145
# Handle TAR.GZ file

src/aks-agent/azext_aks_agent/tests/latest/test_helm_manager.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import os
1111
import platform
1212
import subprocess
13+
import tempfile
1314
import unittest
1415
from pathlib import Path
1516
from unittest.mock import MagicMock, Mock, mock_open, patch
@@ -221,5 +222,69 @@ def test_repo_update_success(self, mock_ensure_helm, mock_mkdir, mock_run):
221222
self.assertIn("update", call_args)
222223

223224

225+
class TestHelmManagerRealDownload(unittest.TestCase):
226+
"""Integration tests for HelmManager that perform real downloads."""
227+
228+
def setUp(self):
229+
"""Set up test fixtures."""
230+
self.test_helm_version = "3.14.0"
231+
self.temp_dir = None
232+
233+
def tearDown(self):
234+
"""Clean up test fixtures."""
235+
if self.temp_dir and os.path.exists(self.temp_dir):
236+
import shutil
237+
shutil.rmtree(self.temp_dir, ignore_errors=True)
238+
239+
@unittest.skipIf(os.environ.get('SKIP_INTEGRATION_TESTS'), "Skipping integration test")
240+
def test_real_download_all_platforms(self):
241+
"""Test real helm binary download for all supported OS and architecture combinations."""
242+
import shutil
243+
244+
platforms = [
245+
("linux", "amd64"),
246+
("linux", "arm64"),
247+
("linux", "arm"),
248+
("linux", "386"),
249+
("darwin", "amd64"),
250+
("darwin", "arm64"),
251+
("windows", "amd64"),
252+
# ("windows", "arm64"), # The blob does not exist for this platform
253+
]
254+
255+
for os_name, arch in platforms:
256+
with self.subTest(os=os_name, arch=arch):
257+
# Create fresh temp directory for each platform
258+
if self.temp_dir and os.path.exists(self.temp_dir):
259+
shutil.rmtree(self.temp_dir, ignore_errors=True)
260+
261+
self.temp_dir = tempfile.mkdtemp()
262+
263+
try:
264+
with patch('azext_aks_agent.agent.k8s.helm_manager.HelmManager._get_platform_info') as mock_platform:
265+
mock_platform.return_value = (os_name, arch)
266+
267+
manager = HelmManager.__new__(HelmManager)
268+
manager.local_bin_dir = Path(self.temp_dir)
269+
manager.helm_version = self.test_helm_version
270+
271+
# Perform actual download
272+
result = manager._download_helm_binary()
273+
274+
# Verify no exception was raised and binary exists
275+
self.assertIsNotNone(result, f"Download failed for {os_name}-{arch}")
276+
self.assertTrue(os.path.exists(result), f"Binary not found for {os_name}-{arch}")
277+
self.assertIn("helm", result)
278+
279+
# Verify binary is executable on Unix systems
280+
if os_name != "windows":
281+
self.assertTrue(os.access(result, os.X_OK), f"Binary not executable for {os_name}-{arch}")
282+
finally:
283+
# Clean up temp directory after each platform test
284+
if self.temp_dir and os.path.exists(self.temp_dir):
285+
shutil.rmtree(self.temp_dir, ignore_errors=True)
286+
self.temp_dir = None
287+
288+
224289
if __name__ == '__main__':
225290
unittest.main()

0 commit comments

Comments
 (0)