Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add livenessProbe to workload pod #124

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading