Skip to content

Commit

Permalink
python subprocess.run doesn't need ticks to escape a brace like bash …
Browse files Browse the repository at this point in the history
…does (#10)
  • Loading branch information
addyess authored Nov 9, 2023
1 parent 53b6c8f commit 5d96a5a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ops/charms/node_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def __init__(self, charm: Charm, kubeconfig_path: Union[PathLike, str]):
@staticmethod
def _retried_call(
cmd: List[str], retry_msg: str, timeout: int = None
) -> Tuple[str, str]:
) -> Tuple[bytes, bytes]:
timeout = RUN_RETRIES if timeout is None else timeout
deadline = time.time() + timeout
while time.time() < deadline:
rc = run(cmd, capture_output=True)
if rc.returncode == 0:
return rc.stdout, rc.stderr
log.info(retry_msg)
log.error(f"{retry_msg}: {rc.stderr}")
time.sleep(1)
else:
raise LabelMaker.NodeLabelError(retry_msg)
Expand All @@ -61,7 +61,7 @@ def active_labels(self) -> Optional[Mapping[str, str]]:
Returns all existing labels if the api server can fetch from the node,
otherwise returns None indicating the node cannot be relabeled.
"""
cmd = "kubectl --kubeconfig={0} get node {1} -o=jsonpath='{{.metadata.labels}}'"
cmd = "kubectl --kubeconfig={0} get node {1} -o=jsonpath={{.metadata.labels}}"
cmd = cmd.format(self.kubeconfig_path, self.charm.get_node_name())
retry_msg = "Failed to get labels. Will retry."
try:
Expand All @@ -71,6 +71,7 @@ def active_labels(self) -> Optional[Mapping[str, str]]:
try:
return json.loads(label_json)
except json.JSONDecodeError:
log.error(f"Failed to decode labels: {label_json.decode()}")
return None

def set_label(self, label: str, value: str) -> None:
Expand Down

0 comments on commit 5d96a5a

Please sign in to comment.