Skip to content

Commit

Permalink
fix: Add livenessProbe to workload pod (#124)
Browse files Browse the repository at this point in the history
Adds the condition from integration tests as a `livenessProbe` to the workload 
container in order to ensure that the workload container restarts if it's not functional.

Closes canonical/bundle-kubeflow#966
  • Loading branch information
orfeas-k authored Aug 5, 2024
1 parent d8916ea commit a18b723
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ def set_pod_spec(self, event):

interfaces = self._get_interfaces()

http_port = int(self.model.config["http-port"])

image_details = self._check_image_details()

upstreams = self._check_grpc(interfaces)

self._send_info(interfaces)

self._send_data_to_ingress_provider(interfaces)
self._send_data_to_ingress_provider(interfaces, http_port)

except CheckFailed as check_failed:
self.model.unit.status = check_failed.status
Expand All @@ -190,7 +192,7 @@ def set_pod_spec(self, event):
listeners=[
get_listener(
cluster=upstream["service"],
port=int(self.model.config["http-port"]),
port=http_port,
)
for upstream in upstreams
],
Expand Down Expand Up @@ -221,7 +223,7 @@ def set_pod_spec(self, event):
},
{
"name": "http",
"containerPort": int(self.model.config["http-port"]),
"containerPort": http_port,
},
],
"volumeConfig": [
Expand All @@ -236,6 +238,21 @@ def set_pod_spec(self, event):
],
}
],
"kubernetes": {
"livenessProbe": {
"initialDelaySeconds": 15,
"httpGet": {
"path": "/",
"port": http_port,
"httpHeaders": [
{
"name": "Content-Type",
"value": "application/grpc-web-text",
}
],
},
}
},
}
],
},
Expand Down Expand Up @@ -282,7 +299,7 @@ def _check_grpc(self, interfaces):
raise CheckFailed("Waiting for upstream gRPC connection information.", WaitingStatus)
return upstreams

def _send_data_to_ingress_provider(self, interfaces):
def _send_data_to_ingress_provider(self, interfaces, port: int):
"""Send data to the ingress relation data bag so the VirtualServices provider configures
a VirtualService routing traffic from `/ml_metadata` path to envoy service.
Expand All @@ -294,7 +311,7 @@ def _send_data_to_ingress_provider(self, interfaces):
"prefix": "/ml_metadata",
"rewrite": "/ml_metadata",
"service": self.model.app.name,
"port": int(self.model.config["http-port"]),
"port": port,
}
)
else:
Expand Down

0 comments on commit a18b723

Please sign in to comment.