From 02a5eb917180b11efb62fd410a95bb1ad12acd81 Mon Sep 17 00:00:00 2001 From: David Garcia Date: Sat, 28 Nov 2020 14:41:22 +0100 Subject: [PATCH] Update RO charm for the newRO and update bundle - Add kafka and mongo relations - Remove ui-k8s from bundle - Add new RO relations Change-Id: I9d68cab33dd262408b8023d58e54b0be8dc024c6 Signed-off-by: David Garcia Signed-off-by: beierlm --- installers/charm/bundles/osm-ha/bundle.yaml | 29 +--- installers/charm/bundles/osm/bundle.yaml | 26 +--- installers/charm/ro-k8s/layer.yaml | 2 + installers/charm/ro-k8s/metadata.yaml | 4 + installers/charm/ro-k8s/reactive/ro.py | 131 +++++++++++++++--- .../charm/ro-k8s/reactive/spec_template.yaml | 21 --- installers/charm/ro-k8s/tox.ini | 2 + installers/charmed_install.sh | 11 +- 8 files changed, 128 insertions(+), 98 deletions(-) diff --git a/installers/charm/bundles/osm-ha/bundle.yaml b/installers/charm/bundles/osm-ha/bundle.yaml index f60082e0..ff666c02 100644 --- a/installers/charm/bundles/osm-ha/bundle.yaml +++ b/installers/charm/bundles/osm-ha/bundle.yaml @@ -83,7 +83,6 @@ applications: gui-y: 50 nbi-k8s: charm: "%(prefix)s/nbi-k8s%(suffix)s" - channel: "%(channel)s" scale: 3 series: kubernetes storage: @@ -97,7 +96,6 @@ applications: gui-y: -200 ro-k8s: charm: "%(prefix)s/ro-k8s%(suffix)s" - channel: "%(channel)s" scale: 3 series: kubernetes storage: @@ -109,19 +107,8 @@ applications: annotations: gui-x: -250 gui-y: 300 - ui-k8s: - charm: "%(prefix)s/ui-k8s%(suffix)s" - channel: "%(channel)s" - scale: 3 - series: kubernetes - options: - mysql_database: lwui - annotations: - gui-x: 250 - gui-y: -200 ng-ui: charm: "%(prefix)s/ng-ui%(suffix)s" - channel: "%(channel)s" scale: 3 series: kubernetes options: @@ -134,7 +121,6 @@ applications: gui-y: 100 lcm-k8s: charm: "%(prefix)s/lcm-k8s%(suffix)s" - channel: "%(channel)s" scale: 3 series: kubernetes storage: @@ -153,8 +139,7 @@ applications: gui-y: 50 mon-k8s: charm: "%(prefix)s/mon-k8s%(suffix)s" - channel: "%(channel)s" - scale: 3 + scale: 1 series: kubernetes storage: database: 100M @@ -175,7 +160,6 @@ applications: gui-y: 50 pol-k8s: charm: "%(prefix)s/pol-k8s%(suffix)s" - channel: "%(channel)s" scale: 3 series: kubernetes storage: @@ -187,7 +171,6 @@ applications: gui-y: 550 pla: charm: "%(prefix)s/pla%(suffix)s" - channel: "%(channel)s" scale: 3 series: kubernetes annotations: @@ -196,7 +179,7 @@ applications: prometheus-k8s: charm: "cs:~charmed-osm/prometheus-k8s" channel: "stable" - scale: 3 + scale: 1 series: kubernetes storage: database: 100M @@ -251,10 +234,6 @@ relations: - "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" @@ -267,3 +246,7 @@ relations: - 'mariadb-k8s:mysql' - - 'keystone:keystone' - 'nbi-k8s:keystone' + - - "ro-k8s:mongo" + - "mongodb-k8s:mongo" + - - "ro-k8s:kafka" + - "kafka-k8s:kafka" diff --git a/installers/charm/bundles/osm/bundle.yaml b/installers/charm/bundles/osm/bundle.yaml index a3ac4085..f1a846cb 100644 --- a/installers/charm/bundles/osm/bundle.yaml +++ b/installers/charm/bundles/osm/bundle.yaml @@ -83,7 +83,6 @@ applications: gui-y: 50 nbi-k8s: charm: "%(prefix)s/nbi-k8s%(suffix)s" - channel: "%(channel)s" scale: 1 series: kubernetes storage: @@ -97,7 +96,6 @@ applications: gui-y: -200 ro-k8s: charm: "%(prefix)s/ro-k8s%(suffix)s" - channel: "%(channel)s" scale: 1 series: kubernetes storage: @@ -109,19 +107,8 @@ applications: annotations: gui-x: -250 gui-y: 300 - ui-k8s: - charm: "%(prefix)s/ui-k8s%(suffix)s" - channel: "%(channel)s" - scale: 1 - series: kubernetes - options: - mysql_database: lwui - annotations: - gui-x: 250 - gui-y: -200 ng-ui: charm: "%(prefix)s/ng-ui%(suffix)s" - channel: "%(channel)s" scale: 1 series: kubernetes options: @@ -134,7 +121,6 @@ applications: gui-y: 100 lcm-k8s: charm: "%(prefix)s/lcm-k8s%(suffix)s" - channel: "%(channel)s" scale: 1 series: kubernetes storage: @@ -153,7 +139,6 @@ applications: gui-y: 50 mon-k8s: charm: "%(prefix)s/mon-k8s%(suffix)s" - channel: "%(channel)s" scale: 1 series: kubernetes storage: @@ -175,7 +160,6 @@ applications: gui-y: 50 pol-k8s: charm: "%(prefix)s/pol-k8s%(suffix)s" - channel: "%(channel)s" scale: 1 series: kubernetes storage: @@ -187,7 +171,6 @@ applications: gui-y: 550 pla: charm: "%(prefix)s/pla%(suffix)s" - channel: "%(channel)s" scale: 1 series: kubernetes annotations: @@ -217,7 +200,6 @@ applications: gui-y: 550 keystone: charm: '%(prefix)s/keystone%(suffix)s' - channel: '%(channel)s' scale: 1 series: kubernetes annotations: @@ -251,10 +233,6 @@ relations: - "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" @@ -267,3 +245,7 @@ relations: - 'mariadb-k8s:mysql' - - 'keystone:keystone' - 'nbi-k8s:keystone' + - - "ro-k8s:mongo" + - "mongodb-k8s:mongo" + - - "ro-k8s:kafka" + - "kafka-k8s:kafka" diff --git a/installers/charm/ro-k8s/layer.yaml b/installers/charm/ro-k8s/layer.yaml index 73a7090b..04d1612e 100644 --- a/installers/charm/ro-k8s/layer.yaml +++ b/installers/charm/ro-k8s/layer.yaml @@ -16,6 +16,8 @@ includes: - "layer:status" - "layer:leadership" - "layer:osm-common" + - "interface:kafka" + - "interface:mongodb" - "interface:juju-relation-mysql" - "interface:osm-ro" diff --git a/installers/charm/ro-k8s/metadata.yaml b/installers/charm/ro-k8s/metadata.yaml index 3531e4b2..102851ab 100755 --- a/installers/charm/ro-k8s/metadata.yaml +++ b/installers/charm/ro-k8s/metadata.yaml @@ -27,6 +27,10 @@ provides: requires: mysql: interface: mysql + kafka: + interface: kafka + mongo: + interface: mongodb storage: log: type: filesystem diff --git a/installers/charm/ro-k8s/reactive/ro.py b/installers/charm/ro-k8s/reactive/ro.py index 8f91b4bd..094812fb 100644 --- a/installers/charm/ro-k8s/reactive/ro.py +++ b/installers/charm/ro-k8s/reactive/ro.py @@ -11,51 +11,96 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import yaml + +from charmhelpers.core.hookenv import log, metadata, config +from charms import layer from charms.layer.caas_base import pod_spec_set +from charms.osm.k8s import get_service_ip from charms.reactive import endpoint_from_flag from charms.reactive import when, when_not, hook from charms.reactive.flags import set_flag, clear_flag -from charmhelpers.core.hookenv import log, metadata, config -from charms import layer -from charms.osm.k8s import get_service_ip @hook("upgrade-charm") @when("leadership.is_leader") def upgrade(): clear_flag("ro-k8s.configured") + clear_flag("ro-k8s.ready") @when("config.changed") @when("leadership.is_leader") def restart(): clear_flag("ro-k8s.configured") + clear_flag("ro-k8s.ready") +@when_not("mongo.ready") @when_not("mysql.available") @when_not("ro-k8s.configured") @when("leadership.is_leader") def waiting_for_mysql(): - layer.status.waiting("Waiting for mysql to be ready") + layer.status.waiting("Waiting for db to be ready") + clear_flag("ro-k8s.ready") + +@when_not("kafka.ready") +@when_not("ro-k8s.configured") +@when("leadership.is_leader") +def waiting_for_kafka(): + layer.status.waiting("Waiting for kafka to be ready") + clear_flag("ro-k8s.ready") + +@when_not("ro-k8s.ready") @when("mysql.available") +def ro_k8s_mysql_ready(): + set_flag("ro-k8s.ready") + + +@when_not("ro-k8s.ready") +@when("kafka.ready") +@when("mongo.ready") +def ro_k8s_kafka_mongo_ready(): + set_flag("ro-k8s.ready") + + +@when("ro-k8s.ready") @when_not("ro-k8s.configured") @when("leadership.is_leader") def configure(): layer.status.maintenance("Configuring ro container") try: mysql = endpoint_from_flag("mysql.available") - - if mysql.host() is not None: - spec = make_pod_spec( - mysql.host(), - mysql.port(), - mysql.user(), - mysql.password(), - mysql.root_password(), - ) - + kafka = endpoint_from_flag("kafka.ready") + mongo = endpoint_from_flag("mongo.ready") + spec = None + if mysql: + if mysql.host() is not None: + spec = make_pod_spec( + mysql.host(), + mysql.port(), + mysql.user(), + mysql.password(), + mysql.root_password(), + ) + elif kafka and mongo: + kafka_units = kafka.kafkas() + kafka_unit = kafka_units[0] + mongo_uri = mongo.connection_string() + + if ( + mongo_uri + and kafka_unit["host"] + # and kafka_unit["port"] + ): + spec = make_pod_spec_new_ro( + kafka_unit["host"], + # kafka_unit["port"], + mongo_uri, + ) + if spec: log("set pod spec:\n{}".format(spec)) pod_spec_set(spec) layer.status.active("creating container") @@ -64,7 +109,7 @@ def configure(): layer.status.blocked("k8s spec failed to deploy: {}".format(e)) -@when("mysql.available") +@when("ro-k8s.configured") @when_not("leadership.is_leader") def non_leaders_active(): layer.status.active("ready") @@ -84,7 +129,8 @@ def send_config(): service_ip = get_service_ip("ro") if service_ip: ro.send_connection( - service_ip, get_ro_port(), + service_ip, + get_ro_port(), ) clear_flag("ro.joined") except Exception as e: @@ -114,15 +160,56 @@ def make_pod_spec( data = { "name": md.get("name"), - "mysql_host": mysql_host, - "mysql_port": mysql_port, - "mysql_user": mysql_user, - "mysql_password": mysql_password, - "mysql_root_password": mysql_root_password, } data.update(cfg) + spec = yaml.safe_load(pod_spec_template % data) + spec["containers"][0]["config"].update( + { + "RO_DB_HOST": mysql_host, + "RO_DB_PORT": mysql_port, + "RO_DB_NAME": cfg.get("ro_database"), + "RO_DB_USER": mysql_user, + "RO_DB_ROOT_PASSWORD": mysql_root_password, + "RO_DB_PASSWORD": mysql_password, + "RO_DB_OVIM_PASSWORD": mysql_password, + "RO_DB_OVIM_HOST": mysql_host, + "RO_DB_OVIM_PORT": mysql_port, + "RO_DB_OVIM_USER": mysql_user, + "RO_DB_OVIM_ROOT_PASSWORD": mysql_root_password, + "RO_DB_OVIM_NAME": cfg.get("vim_database"), + } + ) + return spec + + +def make_pod_spec_new_ro(kafka_host, mongodb_uri): + """Make pod specification for Kubernetes + + Args: + kafka_host (str): Kafka host + mongodb_uri (str): Mongodb URI + Returns: + pod_spec: Pod specification for Kubernetes + """ + + with open("reactive/spec_template.yaml") as spec_file: + pod_spec_template = spec_file.read() + + md = metadata() + cfg = config() - return pod_spec_template % data + data = { + "name": md.get("name"), + } + data.update(cfg) + spec = yaml.safe_load(pod_spec_template % data) + spec["containers"][0]["config"].update( + { + "OSMRO_DATABASE_URI": mongodb_uri, + "OSMRO_MESSAGE_HOST": kafka_host, + } + ) + return spec def get_ro_port(): diff --git a/installers/charm/ro-k8s/reactive/spec_template.yaml b/installers/charm/ro-k8s/reactive/spec_template.yaml index f2b35350..499acd79 100644 --- a/installers/charm/ro-k8s/reactive/spec_template.yaml +++ b/installers/charm/ro-k8s/reactive/spec_template.yaml @@ -21,14 +21,6 @@ containers: username: %(image_username)s password: %(image_password)s kubernetes: - readinessProbe: - httpGet: - path: /openmano/tenants - port: %(advertised-port)s - periodSeconds: 10 - timeoutSeconds: 5 - successThreshold: 1 - failureThreshold: 3 livenessProbe: tcpSocket: port: %(advertised-port)s @@ -42,17 +34,4 @@ containers: protocol: TCP config: ALLOW_ANONYMOUS_LOGIN: 'yes' - RO_DB_HOST: %(mysql_host)s - RO_DB_PORT: %(mysql_port)s - RO_DB_NAME: %(ro_database)s - RO_DB_USER: %(mysql_user)s - RO_DB_ROOT_PASSWORD: %(mysql_root_password)s - RO_DB_PASSWORD: %(mysql_password)s - - RO_DB_OVIM_PASSWORD: %(mysql_password)s - RO_DB_OVIM_HOST: %(mysql_host)s - RO_DB_OVIM_PORT: %(mysql_port)s - RO_DB_OVIM_USER: %(mysql_user)s - RO_DB_OVIM_ROOT_PASSWORD: %(mysql_root_password)s - RO_DB_OVIM_NAME: %(vim_database)s OPENMANO_TENANT: %(OPENMANO_TENANT)s diff --git a/installers/charm/ro-k8s/tox.ini b/installers/charm/ro-k8s/tox.ini index fef77c01..badd81e4 100644 --- a/installers/charm/ro-k8s/tox.ini +++ b/installers/charm/ro-k8s/tox.ini @@ -36,8 +36,10 @@ whitelist_externals = git mv commands = rm -rf release + rm -rf ../interfaces/mongodb rm -rf ../interfaces/juju-relation-mysql rm -rf /tmp/canonical-osm + git clone https://git.launchpad.net/interface-mongodb ../interfaces/mongodb git clone https://git.launchpad.net/canonical-osm/ /tmp/canonical-osm mv /tmp/canonical-osm/charms/interfaces/juju-relation-mysql ../interfaces/juju-relation-mysql charm build . --build-dir /tmp diff --git a/installers/charmed_install.sh b/installers/charmed_install.sh index 9d41e3ee..69f74fc1 100755 --- a/installers/charmed_install.sh +++ b/installers/charmed_install.sh @@ -275,22 +275,16 @@ function deploy_charmed_osm(){ juju expose prometheus-k8s wait_for_port prometheus-k8s 3 - # Expose UI - juju config ui-k8s juju-external-hostname=osm.${API_SERVER}.xip.io - juju expose ui-k8s - wait_for_port ui-k8s 4 - # Apply annotations sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/backend-protocol=HTTPS -n osm -l juju-app=nbi-k8s" sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=nbi-k8s" sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ng-ui" - sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ui-k8s" } function check_osm_deployed() { TIME_TO_WAIT=600 start_time="$(date -u +%s)" - total_service_count=15 + total_service_count=14 previous_count=0 while true do @@ -381,9 +375,6 @@ applications: pol-k8s: options: image: ${REGISTRY_URL}opensourcemano/pol:$TAG ${REGISTRY_CREDENTIALS} - ui-k8s: - options: - image: ${REGISTRY_URL}opensourcemano/light-ui:$TAG ${REGISTRY_CREDENTIALS} pla: options: image: ${REGISTRY_URL}opensourcemano/pla:$TAG ${REGISTRY_CREDENTIALS} -- 2.25.1