Fix PLA relations, add missing ENVs, and include it in the bundle 72/9372/8
authorDavid Garcia <david.garcia@canonical.com>
Thu, 9 Jul 2020 11:14:13 +0000 (13:14 +0200)
committerbeierlm <mark.beierl@canonical.com>
Thu, 9 Jul 2020 15:05:57 +0000 (17:05 +0200)
Change-Id: I4d309d045404a900e04909c46196d32e43bb1862
Signed-off-by: David Garcia <david.garcia@canonical.com>
installers/charm/bundles/osm-ha/bundle.yaml
installers/charm/bundles/osm/bundle.yaml
installers/charm/pla/config.yaml
installers/charm/pla/hooks/install [new symlink]
installers/charm/pla/hooks/upgrade-charm [new symlink]
installers/charm/pla/metadata.yaml
installers/charm/pla/src/charm.py
installers/charmed_install.sh

index 212a520..f395830 100644 (file)
@@ -28,7 +28,7 @@ applications:
       zookeeper-units: 3
     annotations:
       gui-x: 0
-      gui-y: 1100
+      gui-y: 550
   mariadb-k8s:
     charm: "cs:~charmed-osm/mariadb-k8s"
     channel: "stable"
@@ -46,8 +46,8 @@ applications:
       query-cache-size: 0
       ha-mode: true
     annotations:
-      gui-x: -500
-      gui-y: -400
+      gui-x: -250
+      gui-y: -200
   kafka-k8s:
     charm: "cs:~charmed-osm/kafka-k8s"
     channel: "stable"
@@ -63,7 +63,7 @@ applications:
       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"
@@ -80,7 +80,7 @@ applications:
       enable-sidecar: true
     annotations:
       gui-x: 0
-      gui-y: 100
+      gui-y: 50
   nbi-k8s:
     charm: "cs:~charmed-osm/nbi-k8s"
     channel: "%(channel)s"
@@ -93,7 +93,7 @@ applications:
       DATABASE_COMMONKEY: osm
     annotations:
       gui-x: 0
-      gui-y: -400
+      gui-y: -200
   ro-k8s:
     charm: "cs:~charmed-osm/ro-k8s"
     channel: "%(channel)s"
@@ -106,8 +106,8 @@ applications:
       ro_database: "mano_db"
       OPENMANO_TENANT: "osm"
     annotations:
-      gui-x: -500
-      gui-y: 600
+      gui-x: -250
+      gui-y: 300
   ui-k8s:
     charm: "cs:~charmed-osm/ui-k8s"
     channel: "%(channel)s"
@@ -116,8 +116,8 @@ applications:
     options:
       mysql_database: lwui
     annotations:
-      gui-x: 500
-      gui-y: -400
+      gui-x: 250
+      gui-y: -200
   lcm-k8s:
     charm: "cs:~charmed-osm/lcm-k8s"
     channel: "%(channel)s"
@@ -136,8 +136,8 @@ applications:
       use_external_vca: true
       DATABASE_COMMONKEY: osm
     annotations:
-      gui-x: -500
-      gui-y: 100
+      gui-x: -250
+      gui-y: 50
   mon-k8s:
     charm: "cs:~charmed-osm/mon-k8s"
     channel: "%(channel)s"
@@ -158,8 +158,8 @@ applications:
       vca_cacert: cacert
       use_external_vca: true
     annotations:
-      gui-x: 500
-      gui-y: 100
+      gui-x: 250
+      gui-y: 50
   pol-k8s:
     charm: "cs:~charmed-osm/pol-k8s"
     channel: "%(channel)s"
@@ -170,8 +170,16 @@ applications:
     options:
       log_level: INFO
     annotations:
-      gui-x: -500
-      gui-y: 1100
+      gui-x: -250
+      gui-y: 550
+  pla-k8s:
+    charm: "%(prefix)s/pla%(suffix)s"
+    channel: "%(channel)s"
+    scale: 3
+    series: kubernetes
+    annotations:
+      gui-x: 500
+      gui-y: -200
   prometheus-k8s:
     charm: "cs:~charmed-osm/prometheus-k8s"
     channel: "stable"
@@ -184,16 +192,16 @@ applications:
       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"
     scale: 3
     series: kubernetes
     annotations:
-      gui-x: 500
-      gui-y: 1100
+      gui-x: 250
+      gui-y: 550
 
 relations:
   - - "kafka-k8s:zookeeper"
@@ -228,3 +236,9 @@ relations:
     - "nbi-k8s:nbi"
   - - "prometheus-k8s:prometheus"
     - "nbi-k8s:prometheus"
+  - - "pla:kafka"
+    - "kafka-k8s:kafka"
+  - - "pla:mongo"
+    - "mongodb-k8s:mongo"
+  - - "pla:mysql"
+    - "mariadb-k8s:mysql"
index 54d9f59..71465f6 100644 (file)
@@ -15,8 +15,8 @@ description: Single instance OSM bundle
 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:
@@ -28,29 +28,29 @@ applications:
       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:
@@ -63,10 +63,10 @@ applications:
       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:
@@ -80,10 +80,10 @@ applications:
       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:
@@ -93,34 +93,34 @@ applications:
       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:
@@ -128,8 +128,8 @@ applications:
       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:
@@ -145,11 +145,11 @@ applications:
       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:
@@ -167,11 +167,11 @@ applications:
       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:
@@ -179,11 +179,19 @@ applications:
     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:
@@ -193,47 +201,53 @@ applications:
       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"
index 92bb422..3f092c5 100644 (file)
@@ -24,19 +24,15 @@ options:
     description: Port number
     type: int
     default: 8080 # Fake port
-  kafka_host:
-    description: Kafka Hostname
-    type: string
-    default: kafka-k8s
-  kafka_port:
-    description: Kafka Port
-    type: int
-    default: 9092
-  mongo_uri:
-    description: Mongo URI
-    type: string
-    default: mongodb://mongodb-k8s:27017
   log_level:
     description: Log level
     type: string
     default: INFO
+  database:
+    description: Database name
+    type: string
+    default: pla
+  database_common_key:
+    description: Common Key for Mongo database
+    type: string
+    default: osm
diff --git a/installers/charm/pla/hooks/install b/installers/charm/pla/hooks/install
new file mode 120000 (symlink)
index 0000000..25b1f68
--- /dev/null
@@ -0,0 +1 @@
+../src/charm.py
\ No newline at end of file
diff --git a/installers/charm/pla/hooks/upgrade-charm b/installers/charm/pla/hooks/upgrade-charm
new file mode 120000 (symlink)
index 0000000..25b1f68
--- /dev/null
@@ -0,0 +1 @@
+../src/charm.py
\ No newline at end of file
index 37b6214..afd4574 100644 (file)
@@ -26,6 +26,6 @@ requires:
   kafka:
     interface: kafka
   mongo:
-    interface: mongo
+    interface: mongodb
   mysql:
     interface: mysql
\ No newline at end of file
index b94d62b..f90b407 100755 (executable)
@@ -24,6 +24,7 @@ from ops.main import main
 from ops.model import (
     ActiveStatus,
     MaintenanceStatus,
+    WaitingStatus,
 )
 
 from glob import glob
@@ -39,49 +40,76 @@ class PLACharm(CharmBase):
     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 = {
@@ -89,9 +117,8 @@ class PLACharm(CharmBase):
             "containers": [
                 {
                     "name": self.framework.model.app.name,
-                    "image": "{}".format(config["image"]),
+                    "image": config["image"],
                     "ports": ports,
-                    "kubernetes": kubernetes,
                     "config": config_spec,
                 }
             ],
@@ -101,17 +128,11 @@ class PLACharm(CharmBase):
 
     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."""
@@ -119,6 +140,34 @@ class PLACharm(CharmBase):
         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)
index 94bd705..cb840fa 100755 (executable)
@@ -132,7 +132,6 @@ function deploy_charmed_osm(){
         sg microk8s -c "juju add-model osm $K8S_CLOUD_NAME"
     fi
     echo "Deploying OSM with charms"
-    # echo $BUNDLE
     images_overlay=""
     [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
     if [ -v BUNDLE ]; then
@@ -201,6 +200,11 @@ applications:
       vca_password: $vca_password
       vca_host: $vca_host
       vca_cacert: $vca_cacert
+  pla:
+    options:
+      vca_user: $vca_user
+      vca_password: $vca_password
+      vca_host: $vca_host
 EOF
     mv /tmp/vca-overlay.yaml ~/.osm/
     OSM_VCA_HOST=$vca_host
@@ -227,6 +231,9 @@ applications:
   ui-k8s:
     options:
       image: opensourcemano/light-ui:$TAG
+  pla:
+    options:
+      image: opensourcemano/pla:$TAG
 
 EOF
     mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE