- 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,
+ # Create Builder for the PodSpec
+ pod_spec_builder = PodSpecV3Builder()
+
+ # Build Container
+ container_builder = ContainerV3Builder(
+ self.app.name, image_info, config.image_pull_policy
+ )
+ certs_files = self._build_cert_files(config)
+
+ if certs_files:
+ container_builder.add_volume_config("certs", "/certs", certs_files)
+
+ container_builder.add_port(name=self.app.name, port=PORT)
+ container_builder.add_http_readiness_probe(
+ "/ro/" if config.enable_ng_ro else "/openmano/tenants",
+ PORT,
+ initial_delay_seconds=10,
+ period_seconds=10,
+ timeout_seconds=5,
+ failure_threshold=3,
+ )
+ container_builder.add_http_liveness_probe(
+ "/ro/" if config.enable_ng_ro else "/openmano/tenants",
+ PORT,
+ initial_delay_seconds=600,
+ period_seconds=10,
+ timeout_seconds=5,
+ failure_threshold=3,
+ )
+ container_builder.add_envs(
+ {
+ "OSMRO_LOG_LEVEL": config.log_level,
+ }
+ )
+
+ if config.enable_ng_ro:
+ container_builder.add_envs(
+ {
+ "OSMRO_MESSAGE_DRIVER": "kafka",
+ "OSMRO_MESSAGE_HOST": self.kafka_client.host,
+ "OSMRO_MESSAGE_PORT": self.kafka_client.port,
+ # MongoDB configuration
+ "OSMRO_DATABASE_DRIVER": "mongo",
+ "OSMRO_DATABASE_URI": config.mongodb_uri
+ or self.mongodb_client.connection_string,
+ "OSMRO_DATABASE_COMMONKEY": config.database_commonkey,
+ }
+ )
+
+ else:
+ container_builder.add_envs(
+ {
+ "RO_DB_HOST": config.mysql_host or self.mysql_client.host,
+ "RO_DB_OVIM_HOST": config.mysql_host or self.mysql_client.host,
+ "RO_DB_PORT": config.mysql_port or self.mysql_client.port,
+ "RO_DB_OVIM_PORT": config.mysql_port or self.mysql_client.port,
+ "RO_DB_USER": config.mysql_user or self.mysql_client.user,
+ "RO_DB_OVIM_USER": config.mysql_user or self.mysql_client.user,
+ "RO_DB_PASSWORD": config.mysql_password
+ or self.mysql_client.password,
+ "RO_DB_OVIM_PASSWORD": config.mysql_password
+ or self.mysql_client.password,
+ "RO_DB_ROOT_PASSWORD": config.mysql_root_password
+ or self.mysql_client.root_password,
+ "RO_DB_OVIM_ROOT_PASSWORD": config.mysql_root_password
+ or self.mysql_client.root_password,
+ "RO_DB_NAME": config.ro_database,
+ "RO_DB_OVIM_NAME": config.vim_database,
+ "OPENMANO_TENANT": config.openmano_tenant,
+ }