- Args:
- event (EventBase): Hook or Relation event that started the
- function.
- """
- if not self.unit.is_leader():
- self.unit.status = ActiveStatus("ready")
- return
-
- relation_state = None
- try:
- relation_state = self.get_relation_state()
- except RelationsMissing as exc:
- logger.exception("Relation missing error")
- self.unit.status = BlockedStatus(exc.message)
- return
-
- self.unit.status = MaintenanceStatus("Assembling pod spec")
-
- # Fetch image information
- try:
- self.unit.status = MaintenanceStatus("Fetching image information")
- image_info = self.image.fetch()
- except OCIImageResourceError:
- self.unit.status = BlockedStatus("Error fetching image information")
- return
-
- try:
- pod_spec = make_pod_spec(
- image_info,
- self.model.config,
- relation_state,
- self.model.app.name,
- self.port,
+ # Build container
+ container_builder = ContainerV3Builder(
+ self.app.name, image_info, config.image_pull_policy
+ )
+ container_builder.add_port(name=self.app.name, port=PORT)
+ container_builder.add_http_readiness_probe(
+ path="/api/health",
+ port=PORT,
+ initial_delay_seconds=10,
+ period_seconds=10,
+ timeout_seconds=5,
+ success_threshold=1,
+ failure_threshold=3,
+ )
+ container_builder.add_http_liveness_probe(
+ path="/api/health",
+ port=PORT,
+ initial_delay_seconds=60,
+ timeout_seconds=30,
+ failure_threshold=10,
+ )
+
+ unparsed = (
+ config.mongodb_uri
+ if config.mongodb_uri
+ else self.mongodb_client.connection_string
+ )
+ parsed = urlparse(unparsed)
+ mongodb_uri = f"mongodb://{parsed.netloc.split(',')[0]}{parsed.path}"
+ if parsed.query:
+ mongodb_uri += f"?{parsed.query}"
+
+ container_builder.add_envs(
+ {
+ "MONGODB_URI": mongodb_uri,
+ }
+ )
+ container = container_builder.build()
+
+ # Add container to PodSpec
+ pod_spec_builder.add_container(container)
+
+ # Add ingress resources to PodSpec if site url exists
+ if config.site_url:
+ parsed = urlparse(config.site_url)
+ annotations = {}
+ if config.ingress_class:
+ annotations["kubernetes.io/ingress.class"] = config.ingress_class
+ ingress_resource_builder = IngressResourceV3Builder(
+ f"{self.app.name}-ingress", annotations