- def _apply_spec(self):
- # Only apply the spec if this unit is a leader.
- unit = self.model.unit
- if not unit.is_leader():
- unit.status = ActiveStatus("ready")
- return
- if not self.state.kafka_host or not self.state.kafka_port:
- unit.status = WaitingStatus("Waiting for Kafka")
- return
- if not self.state.mongodb_uri:
- unit.status = WaitingStatus("Waiting for MongoDB")
- return
-
- unit.status = MaintenanceStatus("Applying new pod spec")
-
- new_spec = self.make_pod_spec()
- if new_spec == self.state.spec:
- unit.status = ActiveStatus("ready")
- return
- self.framework.model.pod.set_spec(new_spec)
- self.state.spec = new_spec
- unit.status = ActiveStatus("ready")
-
- def make_pod_spec(self):
- config = self.framework.model.config
-
- ports = [
- {"name": "port", "containerPort": config["port"], "protocol": "TCP", },
- ]
-
- config_spec = {
- "OSMPLA_MESSAGE_DRIVER": "kafka",
- "OSMPLA_MESSAGE_HOST": self.state.kafka_host,
- "OSMPLA_MESSAGE_PORT": self.state.kafka_port,
- "OSMPLA_DATABASE_DRIVER": "mongo",
- "OSMPLA_DATABASE_URI": self.state.mongodb_uri,
- "OSMPLA_GLOBAL_LOG_LEVEL": config["log_level"],
- "OSMPLA_DATABASE_COMMONKEY": config["database_common_key"],
- }