Skip to content

Commit

Permalink
Update pod.py (#33779)
Browse files Browse the repository at this point in the history
Put a quote to the entire curl command
  • Loading branch information
Owen-CH-Leung authored Aug 26, 2023
1 parent b1f2a16 commit 42bc8fc
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions airflow/providers/cncf/kubernetes/operators/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ class KubernetesPodOperator(BaseOperator):
# This field can be overloaded at the instance level via base_container_name
BASE_CONTAINER_NAME = "base"
ISTIO_CONTAINER_NAME = "istio-proxy"
KILL_ISTIO_PROXY_SUCCESS_MSG = "HTTP/1.1 200"
POD_CHECKED_KEY = "already_checked"
POST_TERMINATION_TIMEOUT = 120

Expand Down Expand Up @@ -777,25 +778,31 @@ def is_istio_enabled(self, pod: V1Pod) -> bool:
return False

def kill_istio_sidecar(self, pod: V1Pod) -> None:
command = "/bin/sh -c curl -fsI -X POST http://localhost:15020/quitquitquit && exit 0"
command = "/bin/sh -c 'curl -fsI -X POST http://localhost:15020/quitquitquit'"
command_to_container = shlex.split(command)
try:
resp = stream(
self.client.connect_get_namespaced_pod_exec,
name=pod.metadata.name,
namespace=pod.metadata.namespace,
container=self.ISTIO_CONTAINER_NAME,
command=command_to_container,
stderr=True,
stdin=True,
stdout=True,
tty=False,
_preload_content=False,
)
resp.close()
except Exception as e:
self.log.error("Error while deleting istio-proxy sidecar: %s", e)
raise e
resp = stream(
self.client.connect_get_namespaced_pod_exec,
name=pod.metadata.name,
namespace=pod.metadata.namespace,
container=self.ISTIO_CONTAINER_NAME,
command=command_to_container,
stderr=True,
stdin=True,
stdout=True,
tty=False,
_preload_content=False,
)
output = []
while resp.is_open():
if resp.peek_stdout():
output.append(resp.read_stdout())

resp.close()
output_str = "".join(output)
self.log.info("Output of curl command to kill istio: %s", output_str)
resp.close()
if self.KILL_ISTIO_PROXY_SUCCESS_MSG not in output_str:
raise Exception("Error while deleting istio-proxy sidecar: %s", output_str)

def process_pod_deletion(self, pod: k8s.V1Pod, *, reraise=True):
istio_enabled = self.is_istio_enabled(pod)
Expand Down

0 comments on commit 42bc8fc

Please sign in to comment.