bundle: kubernetes
applications:
zookeeper-k8s:
- charm: 'cs:~charmed-osm/zookeeper-k8s'
- channel: 'stable'
+ charm: "cs:~charmed-osm/zookeeper-k8s"
+ channel: "stable"
scale: 1
series: kubernetes
storage:
zookeeper-units: 1
annotations:
gui-x: 0
- gui-y: 1100
- # mariadb-k8s:
- # charm: 'cs:~charmed-osm/mariadb-k8s'
- # channel: 'stable'
- # scale: 1
- # series: kubernetes
- # storage:
- # database: 50M
- # options:
- # password: manopw
- # root_password: osm4u
- # user: mano
- # database: database
- # mysql_port: "3306"
- # query-cache-type: "OFF"
- # query-cache-size: 0
- # ha-mode: false
- # annotations:
- # gui-x: -500
- # gui-y: -400
+ gui-y: 550
+ mariadb-k8s:
+ charm: "cs:~charmed-osm/mariadb-k8s"
+ channel: "stable"
+ scale: 1
+ series: kubernetes
+ storage:
+ database: 50M
+ options:
+ password: manopw
+ root_password: osm4u
+ user: mano
+ database: database
+ mysql_port: "3306"
+ query-cache-type: "OFF"
+ query-cache-size: 0
+ ha-mode: false
+ annotations:
+ gui-x: -250
+ gui-y: -200
kafka-k8s:
- charm: 'cs:~charmed-osm/kafka-k8s'
- channel: 'stable'
+ charm: "cs:~charmed-osm/kafka-k8s"
+ channel: "stable"
scale: 1
series: kubernetes
storage:
zookeeper-service-name: zookeeper-k8s-endpoints
annotations:
gui-x: 0
- gui-y: 600
+ gui-y: 300
mongodb-k8s:
- charm: 'cs:~charmed-osm/mongodb-k8s'
- channel: 'stable'
+ charm: "cs:~charmed-osm/mongodb-k8s"
+ channel: "stable"
scale: 1
series: kubernetes
storage:
enable-sidecar: false
annotations:
gui-x: 0
- gui-y: 100
+ gui-y: 50
nbi-k8s:
- charm: '%(prefix)s/nbi-k8s%(suffix)s'
- channel: '%(channel)s'
+ charm: "%(prefix)s/nbi-k8s%(suffix)s"
+ channel: "%(channel)s"
scale: 1
series: kubernetes
storage:
DATABASE_COMMONKEY: osm
annotations:
gui-x: 0
- gui-y: -400
+ gui-y: -200
ro-k8s:
- charm: '%(prefix)s/ro-k8s%(suffix)s'
- channel: '%(channel)s'
+ charm: "%(prefix)s/ro-k8s%(suffix)s"
+ channel: "%(channel)s"
scale: 1
series: kubernetes
storage:
log: 50M
options:
- vim_database: 'mano_vim_db'
- ro_database: 'mano_db'
- OPENMANO_TENANT: 'osm'
+ vim_database: "mano_vim_db"
+ ro_database: "mano_db"
+ OPENMANO_TENANT: "osm"
annotations:
- gui-x: -500
- gui-y: 600
+ gui-x: -250
+ gui-y: 300
ui-k8s:
- charm: '%(prefix)s/ui-k8s%(suffix)s'
- channel: '%(channel)s'
+ charm: "%(prefix)s/ui-k8s%(suffix)s"
+ channel: "%(channel)s"
scale: 1
series: kubernetes
options:
mysql_database: lwui
annotations:
- gui-x: 500
- gui-y: -400
+ gui-x: 250
+ gui-y: -200
ng-ui:
- charm: '%(prefix)s/ng-ui%(suffix)s'
- channel: '%(channel)s'
+ charm: "%(prefix)s/ng-ui%(suffix)s"
+ channel: "%(channel)s"
scale: 1
series: kubernetes
options:
server_name: localhost
client_max_body_size: 15M
lcm-k8s:
- charm: '%(prefix)s/lcm-k8s%(suffix)s'
- channel: '%(channel)s'
+ charm: "%(prefix)s/lcm-k8s%(suffix)s"
+ channel: "%(channel)s"
scale: 1
series: kubernetes
storage:
use_external_vca: false
DATABASE_COMMONKEY: osm
annotations:
- gui-x: -500
- gui-y: 100
+ gui-x: -250
+ gui-y: 50
mon-k8s:
- charm: '%(prefix)s/mon-k8s%(suffix)s'
- channel: '%(channel)s'
+ charm: "%(prefix)s/mon-k8s%(suffix)s"
+ channel: "%(channel)s"
scale: 1
series: kubernetes
storage:
vca_cacert: cacert
use_external_vca: false
annotations:
- gui-x: 500
- gui-y: 100
+ gui-x: 250
+ gui-y: 50
pol-k8s:
- charm: '%(prefix)s/pol-k8s%(suffix)s'
- channel: '%(channel)s'
+ charm: "%(prefix)s/pol-k8s%(suffix)s"
+ channel: "%(channel)s"
scale: 1
series: kubernetes
storage:
options:
log_level: INFO
annotations:
- gui-x: -500
- gui-y: 1100
+ gui-x: -250
+ gui-y: 550
+ pla:
+ charm: "%(prefix)s/pla%(suffix)s"
+ channel: "%(channel)s"
+ scale: 1
+ series: kubernetes
+ annotations:
+ gui-x: 500
+ gui-y: -200
prometheus-k8s:
- charm: 'cs:~charmed-osm/prometheus-k8s'
- channel: 'stable'
+ charm: "cs:~charmed-osm/prometheus-k8s"
+ channel: "stable"
scale: 1
series: kubernetes
storage:
web-subpath: /
default-target: "mon-k8s:8000"
annotations:
- gui-x: 500
- gui-y: 600
+ gui-x: 250
+ gui-y: 300
grafana-k8s:
- charm: 'cs:~charmed-osm/grafana-k8s'
- channel: 'stable'
+ charm: "cs:~charmed-osm/grafana-k8s"
+ channel: "stable"
scale: 1
series: kubernetes
annotations:
- gui-x: 500
- gui-y: 1100
+ gui-x: 250
+ gui-y: 550
relations:
- - - 'kafka-k8s:zookeeper'
- - 'zookeeper-k8s:zookeeper'
- - - 'ro-k8s:mysql'
- - 'mariadb-k8s:mysql'
- - - 'nbi-k8s:mongo'
- - 'mongodb-k8s:mongo'
- - - 'nbi-k8s:kafka'
- - 'kafka-k8s:kafka'
- - - 'lcm-k8s:kafka'
- - 'kafka-k8s:kafka'
- - - 'lcm-k8s:mongo'
- - 'mongodb-k8s:mongo'
- - - 'mon-k8s:kafka'
- - 'kafka-k8s:kafka'
- - - 'mon-k8s:mongo'
- - 'mongodb-k8s:mongo'
- - - 'pol-k8s:kafka'
- - 'kafka-k8s:kafka'
- - - 'pol-k8s:mongo'
- - 'mongodb-k8s:mongo'
- - - 'lcm-k8s:ro'
- - 'ro-k8s:ro'
- - - 'prometheus-k8s:prometheus'
- - 'mon-k8s:prometheus'
- - - 'grafana-k8s:prometheus'
- - 'prometheus-k8s:prometheus'
- - - 'ui-k8s:mysql'
- - 'mariadb-k8s:mysql'
- - - 'ui-k8s:nbi'
- - 'nbi-k8s:nbi'
- - - 'prometheus-k8s:prometheus'
- - 'nbi-k8s:prometheus'
+ - - "kafka-k8s:zookeeper"
+ - "zookeeper-k8s:zookeeper"
+ - - "ro-k8s:mysql"
+ - "mariadb-k8s:mysql"
+ - - "nbi-k8s:mongo"
+ - "mongodb-k8s:mongo"
+ - - "nbi-k8s:kafka"
+ - "kafka-k8s:kafka"
+ - - "lcm-k8s:kafka"
+ - "kafka-k8s:kafka"
+ - - "lcm-k8s:mongo"
+ - "mongodb-k8s:mongo"
+ - - "mon-k8s:kafka"
+ - "kafka-k8s:kafka"
+ - - "mon-k8s:mongo"
+ - "mongodb-k8s:mongo"
+ - - "pol-k8s:kafka"
+ - "kafka-k8s:kafka"
+ - - "pol-k8s:mongo"
+ - "mongodb-k8s:mongo"
+ - - "lcm-k8s:ro"
+ - "ro-k8s:ro"
+ - - "prometheus-k8s:prometheus"
+ - "mon-k8s:prometheus"
+ - - "grafana-k8s:prometheus"
+ - "prometheus-k8s:prometheus"
+ - - "ui-k8s:mysql"
+ - "mariadb-k8s:mysql"
+ - - "ui-k8s:nbi"
+ - "nbi-k8s:nbi"
+ - - "prometheus-k8s:prometheus"
+ - "nbi-k8s:prometheus"
+ - - "pla:kafka"
+ - "kafka-k8s:kafka"
+ - - "pla:mongo"
+ - "mongodb-k8s:mongo"
+ - - "pla:mysql"
+ - "mariadb-k8s:mysql"
from ops.model import (
ActiveStatus,
MaintenanceStatus,
+ WaitingStatus,
)
from glob import glob
def __init__(self, framework, key):
super().__init__(framework, key)
self.state.set_default(spec=None)
+ self.state.set_default(kafka_host=None)
+ self.state.set_default(kafka_port=None)
+ self.state.set_default(mongodb_uri=None)
+ self.state.set_default(mysql_host=None)
+ self.state.set_default(mysql_port=None)
# Observe Charm related events
self.framework.observe(self.on.config_changed, self.on_config_changed)
self.framework.observe(self.on.start, self.on_start)
self.framework.observe(self.on.upgrade_charm, self.on_upgrade_charm)
+ # 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.framework.observe(
+ self.on.mysql_relation_changed, self.on_mysql_relation_changed
+ )
+
def _apply_spec(self):
# Only apply the spec if this unit is a leader.
- if not self.framework.model.unit.is_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
+ if not self.state.mysql_host or not self.state.mysql_port:
+ unit.status = WaitingStatus("Waiting for MySQL")
+ 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
+ mysql_uri = "mysql://root:{}@{}:{}/{}".format(
+ self.state.mysql_root_password,
+ self.state.mysql_host,
+ self.state.mysql_port,
+ self.state.mysql_database,
+ )
ports = [
{"name": "port", "containerPort": config["port"], "protocol": "TCP",},
]
- kubernetes = {
- "readinessProbe": {
- "tcpSocket": {"port": config["port"]},
- "timeoutSeconds": 5,
- "periodSeconds": 5,
- "initialDelaySeconds": 10,
- },
- "livenessProbe": {
- "tcpSocket": {"port": config["port"]},
- "timeoutSeconds": 5,
- "initialDelaySeconds": 45,
- },
- }
config_spec = {
"OSMPLA_MESSAGE_DRIVER": "kafka",
- "OSMPLA_MESSAGE_HOST": config["kafka_host"],
- "OSMPLA_MESSAGE_PORT": config["kafka_port"],
+ "OSMPLA_MESSAGE_HOST": self.state.kafka_host,
+ "OSMPLA_MESSAGE_PORT": self.state.kafka_port,
"OSMPLA_DATABASE_DRIVER": "mongo",
- "OSMPLA_DATABASE_URI": config["mongo_uri"],
+ "OSMPLA_DATABASE_URI": self.state.mongodb_uri,
"OSMPLA_GLOBAL_LOG_LEVEL": config["log_level"],
+ "OSMPLA_SQL_DATABASE_URI": mysql_uri,
+ "OSMPLA_DATABASE_COMMONKEY": config["database_common_key"],
}
spec = {
"containers": [
{
"name": self.framework.model.app.name,
- "image": "{}".format(config["image"]),
+ "image": config["image"],
"ports": ports,
- "kubernetes": kubernetes,
"config": config_spec,
}
],
def on_config_changed(self, event):
"""Handle changes in configuration"""
- unit = self.model.unit
- unit.status = MaintenanceStatus("Applying new pod spec")
self._apply_spec()
- unit.status = ActiveStatus("Ready")
def on_start(self, event):
"""Called when the charm is being installed"""
- unit = self.model.unit
- unit.status = MaintenanceStatus("Applying pod spec")
self._apply_spec()
- unit.status = ActiveStatus("Ready")
def on_upgrade_charm(self, event):
"""Upgrade the charm."""
unit.status = MaintenanceStatus("Upgrading charm")
self.on_start(event)
+ def on_kafka_relation_changed(self, event):
+ unit = self.model.unit
+ if not unit.is_leader():
+ return
+ self.state.kafka_host = event.relation.data[event.unit].get("host")
+ self.state.kafka_port = event.relation.data[event.unit].get("port")
+ self._apply_spec()
+
+ def on_mongo_relation_changed(self, event):
+ unit = self.model.unit
+ if not unit.is_leader():
+ return
+ self.state.mongodb_uri = event.relation.data[event.unit].get(
+ "connection_string"
+ )
+ self._apply_spec()
+
+ def on_mysql_relation_changed(self, event):
+ unit = self.model.unit
+ if not unit.is_leader():
+ return
+ unit_data = event.relation.data[event.unit]
+ self.state.mysql_host = unit_data.get("host")
+ self.state.mysql_port = unit_data.get("port")
+ self.state.mysql_root_password = unit_data.get("root_password")
+ self.state.mysql_database = self.model.config["database"]
+ self._apply_spec()
+
if __name__ == "__main__":
main(PLACharm)