- # Relations
- self.framework.observe(
- self.on.kafka_relation_changed, self.on_kafka_relation_changed
- )
- self.framework.observe(
- self.on.mongo_relation_changed, self.on_mongo_relation_changed
+ self.mongodb_client = MongoClient(self, "mongodb")
+ self.framework.observe(self.on["mongodb"].relation_changed, self.configure_pod)
+ self.framework.observe(self.on["mongodb"].relation_broken, self.configure_pod)
+
+ def _check_missing_dependencies(self, config: ConfigModel):
+ missing_relations = []
+
+ if (
+ self.kafka_client.is_missing_data_in_unit()
+ and self.kafka_client.is_missing_data_in_app()
+ ):
+ missing_relations.append("kafka")
+ if not config.mongodb_uri and self.mongodb_client.is_missing_data_in_unit():
+ missing_relations.append("mongodb")
+
+ if missing_relations:
+ raise RelationsMissing(missing_relations)
+
+ def build_pod_spec(self, image_info):
+ # Validate config
+ config = ConfigModel(**dict(self.config))
+
+ if config.mongodb_uri and not self.mongodb_client.is_missing_data_in_unit():
+ raise Exception("Mongodb data cannot be provided via config and relation")
+
+ # Check relations
+ self._check_missing_dependencies(config)
+
+ # Create Builder for the PodSpec
+ pod_spec_builder = PodSpecV3Builder(
+ enable_security_context=config.security_context