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

JIMM k8s charm fixes #989

Merged
merged 2 commits into from
Jul 7, 2023
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
23 changes: 12 additions & 11 deletions charms/jimm-k8s/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"CANDID_URL",
]

JIMM_SERVICE_NAME = "jimm"
DATABASE_NAME = "jimm"
LOG_FILE = "/var/log/jimm"
# This likely will just be JIMM's port.
Expand Down Expand Up @@ -258,7 +259,7 @@ def _update_workload(self, event):
"summary": "jimm layer",
"description": "pebble config layer for jimm",
"services": {
"jimm": {
JIMM_SERVICE_NAME: {
"override": "merge",
"summary": "JAAS Intelligent Model Manager",
"command": "/root/jimmsrv",
Expand All @@ -276,10 +277,10 @@ def _update_workload(self, event):
}
container.add_layer("jimm", pebble_layer, combine=True)
if self._ready():
if container.get_service("jimm").is_running():
if container.get_service(JIMM_SERVICE_NAME).is_running():
container.replan()
else:
container.start("jimm")
container.start(JIMM_SERVICE_NAME)
self.unit.status = ActiveStatus("running")
else:
logger.info("workload container not ready - defering")
Expand All @@ -304,7 +305,7 @@ def _on_stop(self, _):
"""Stop JIMM."""
container = self.unit.get_container(WORKLOAD_CONTAINER)
if container.can_connect():
container.stop()
container.stop(JIMM_SERVICE_NAME)
self._ready()

def _on_update_status(self, _):
Expand Down Expand Up @@ -357,12 +358,12 @@ def _ready(self):

if container.can_connect():
plan = container.get_plan()
if plan.services.get("jimm") is None:
if plan.services.get(JIMM_SERVICE_NAME) is None:
logger.error("waiting for service")
self.unit.status = WaitingStatus("waiting for service")
return False

env_vars = plan.services.get("jimm").environment
env_vars = plan.services.get(JIMM_SERVICE_NAME).environment

for setting in REQUIRED_SETTINGS:
if not env_vars.get(setting, ""):
Expand All @@ -371,7 +372,7 @@ def _ready(self):
)
return False

if container.get_service("jimm").is_running():
if container.get_service(JIMM_SERVICE_NAME).is_running():
self.unit.status = ActiveStatus("running")
else:
self.unit.status = WaitingStatus("stopped")
Expand Down Expand Up @@ -555,7 +556,7 @@ def _get_dns_name(self, event):
if not self._state.is_ready():
event.defer()
logger.warning("State is not ready")
return
return None

default_dns_name = "{}.{}-endpoints.{}.svc.cluster.local".format(
self.unit.name.replace("/", "-"),
Expand Down Expand Up @@ -601,15 +602,15 @@ def _on_certificate_expiring(self, event: CertificateExpiringEvent) -> None:

new_csr = generate_csr(
private_key=private_key.encode(),
subject=self.dns_name,
subject=dns_name,
)
self.certificates.request_certificate_renewal(
old_certificate_signing_request=old_csr,
new_certificate_signing_request=new_csr,
)
self._state.csr = new_csr.decode()

self._update_workload()
self._update_workload(event)

@requires_state_setter
def _on_certificate_revoked(self, event: CertificateRevokedEvent) -> None:
Expand All @@ -634,7 +635,7 @@ def _on_certificate_revoked(self, event: CertificateRevokedEvent) -> None:
del self._state.chain

self.unit.status = WaitingStatus("Waiting for new certificate")
self._update_workload()
self._update_workload(event)

@requires_state_setter
def _on_ingress_ready(self, event: IngressPerAppReadyEvent):
Expand Down