Skip to content

Commit 4258d77

Browse files
committed
fix(windows): use tempfile library
1 parent 873ffa2 commit 4258d77

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import base64
77
import json
88
import os
9+
import tempfile
910
import time
1011
from typing import Dict, List, Optional, Tuple, Union
1112

@@ -428,10 +429,14 @@ def deploy_agent(self, chart_version: Optional[str] = None,
428429
# Add custom values if provided
429430
values = self._create_helm_values()
430431

431-
values_file = f"/tmp/aks-agent-values-{int(time.time())}.yaml"
432+
# Create temporary file in a cross-platform way
433+
values_file = None
432434
try:
433435
import yaml
434-
with open(values_file, 'w') as f:
436+
437+
# Create a temporary file that works on both Windows and Unix/Linux
438+
with tempfile.NamedTemporaryFile(mode='w', suffix='.yaml', delete=False) as f:
439+
values_file = f.name
435440
yaml.dump(values, f)
436441
helm_args.extend(["--values", values_file])
437442
except Exception as e: # pylint: disable=broad-exception-caught
@@ -444,12 +449,13 @@ def deploy_agent(self, chart_version: Optional[str] = None,
444449
success, output = self._run_helm_command(helm_args)
445450

446451
# Clean up temporary values file
447-
try:
448-
if os.path.exists(values_file):
449-
os.remove(values_file)
450-
logger.debug("Removed temporary values file: %s", values_file)
451-
except Exception as e: # pylint: disable=broad-exception-caught
452-
logger.debug("Failed to remove temporary values file: %s", e)
452+
if values_file:
453+
try:
454+
if os.path.exists(values_file):
455+
os.remove(values_file)
456+
logger.debug("Removed temporary values file: %s", values_file)
457+
except Exception as e: # pylint: disable=broad-exception-caught
458+
logger.debug("Failed to remove temporary values file: %s", e)
453459

454460
if success:
455461
logger.info("AKS agent deployed/upgraded successfully")

0 commit comments

Comments
 (0)