From b8fa58782addfc835ba813ad4dc261fff400ee4a Mon Sep 17 00:00:00 2001 From: yiyione Date: Fri, 5 Feb 2021 11:12:37 +0800 Subject: [PATCH] [Marketplace] Simplify marketplace setting (#5283) * add prerequisite in marketplace-webportal and marketplace-restserver, auto use config from their prerequisite services * Fix template * Fix template * Fix template * auto use https in marketplace if pylon.ssl * auto use https in marketplace if pylon.ssl * Add deploy marketplace to quickstart * fix template * Add config to enable/disable the auto-added marketplace-plugin * Set marketplace: false in quick-start default services-configuration * Add enable_marketplace option to config.yaml --- contrib/kubespray/config/config.yaml | 1 + .../services-configuration.yaml.template | 7 +++--- .../services-configuration.yaml.template | 7 +++--- .../config/marketplace-restserver.yaml | 11 +++++----- .../marketplace-restserver.yaml.template | 22 ++++++++++++++++--- .../deploy/service.yaml | 1 + .../config/marketplace_webportal.py | 2 -- .../marketplace-webportal.yaml.template | 8 +++++++ src/marketplace-webportal/deploy/service.yaml | 1 + src/webportal/config/webportal.py | 2 +- src/webportal/config/webportal.yaml | 3 +++ src/webportal/deploy/webportal.yaml.template | 19 +++++++++++++++- 12 files changed, 65 insertions(+), 19 deletions(-) diff --git a/contrib/kubespray/config/config.yaml b/contrib/kubespray/config/config.yaml index c8758d8686..0154db40d4 100644 --- a/contrib/kubespray/config/config.yaml +++ b/contrib/kubespray/config/config.yaml @@ -8,6 +8,7 @@ docker_image_tag: v1.5.0 # OpenPAI Customized Settings # ####################################################################### # enable_hived_scheduler: true +# enable_marketplace: false ############################################# # Ansible-playbooks' inventory hosts' vars. # diff --git a/contrib/kubespray/quick-start/services-configuration.yaml.template b/contrib/kubespray/quick-start/services-configuration.yaml.template index c48be481d2..5f68add8bd 100644 --- a/contrib/kubespray/quick-start/services-configuration.yaml.template +++ b/contrib/kubespray/quick-start/services-configuration.yaml.template @@ -7,6 +7,7 @@ cluster: data-path: "/datastorage" qos-switch: "{{ env["cfg"]["qos-switch"] | default('false') }}" docker-data-root: "{{ env['cfg']['docker_data_root'] | default('/mnt/docker') }}" + marketplace: "{{ env["cfg"]["enable_marketplace"] | default('false') }}" # the docker registry to store docker images that contain system services like frameworklauncher, hadoop, etc. docker-registry: @@ -205,15 +206,15 @@ authentication: # alertname: PAIJobGpuPercentLowerThan0_3For1h # customized-receivers: # receivers are combination of several actions # - name: "pai-email-admin-user-and-stop-job" -# actions: +# actions: # # the email template for `email-admin` and `email-user `can be chosen from ['general-template', 'kill-low-efficiency-job-alert'] # # if no template specified, 'general-template' will be used. # email-admin: -# email-user: +# email-user: # template: 'kill-low-efficiency-job-alert' # stop-jobs: # no parameters required for stop-jobs action # tag-jobs: -# tags: +# tags: # - 'stopped-by-alert-manager' # uncomment following if you want to customize prometheus diff --git a/deployment/quick-start/services-configuration.yaml.template b/deployment/quick-start/services-configuration.yaml.template index a76b198e8a..2ef9f5b286 100644 --- a/deployment/quick-start/services-configuration.yaml.template +++ b/deployment/quick-start/services-configuration.yaml.template @@ -23,6 +23,7 @@ cluster: # cluster-type: k8s # # HDFS, zookeeper data path on your cluster machine. # data-path: "/datastorage" + # marketplace: "true" # the docker registry to store docker images that contain system services like frameworklauncher, hadoop, etc. docker-registry: @@ -90,15 +91,15 @@ rest-server: # alertname: PAIJobGpuPercentLowerThan0_3For1h # customized-receivers: # receivers are combination of several actions # - name: "pai-email-admin-user-and-stop-job" -# actions: +# actions: # # the email template for `email-admin` and `email-user `can be chosen from ['general-template', 'kill-low-efficiency-job-alert'] # # if no template specified, 'general-template' will be used. # email-admin: -# email-user: +# email-user: # template: 'kill-low-efficiency-job-alert' # stop-jobs: # no parameters required for stop-jobs action # tag-jobs: -# tags: +# tags: # - 'stopped-by-alert-manager' # uncomment following if you want to customize prometheus diff --git a/src/marketplace-restserver/config/marketplace-restserver.yaml b/src/marketplace-restserver/config/marketplace-restserver.yaml index 90ac7cecab..35525bd805 100644 --- a/src/marketplace-restserver/config/marketplace-restserver.yaml +++ b/src/marketplace-restserver/config/marketplace-restserver.yaml @@ -3,16 +3,15 @@ service_type: "k8s" -db_user: user -db_password: passwd -db: marketplace +# db_user: user +# db_password: passwd +# db: marketplace # db_host: postgres -db_port: 9291 +# db_port: 9291 server-port: 9292 azure_storage: type: blob storage_account: openpaimarketplace - connection_strings: - - '' + connection_strings: [] azure_storage_json: '' diff --git a/src/marketplace-restserver/deploy/marketplace-restserver.yaml.template b/src/marketplace-restserver/deploy/marketplace-restserver.yaml.template index c00d6ffa50..05ff0dcc68 100644 --- a/src/marketplace-restserver/deploy/marketplace-restserver.yaml.template +++ b/src/marketplace-restserver/deploy/marketplace-restserver.yaml.template @@ -21,16 +21,32 @@ spec: image: {{ cluster_cfg["cluster"]["docker-registry"]["prefix"] }}marketplace-restserver:{{ cluster_cfg["cluster"]["docker-registry"]["tag"] }} imagePullPolicy: Always env: + - name: DB_HOST + value: {{ cluster_cfg["marketplace-restserver"]["db_host"] }} - name: DB_USERNAME +{% if 'db_user' in cluster_cfg["marketplace-restserver"] %} value: {{ cluster_cfg["marketplace-restserver"]["db_user"] }} +{% else %} + value: {{ cluster_cfg["marketplace-db"]["user"] }} +{% endif %} - name: DB_PASSWORD +{% if 'db_password' in cluster_cfg["marketplace-restserver"] %} value: {{ cluster_cfg["marketplace-restserver"]["db_password"] }} +{% else %} + value: {{ cluster_cfg["marketplace-db"]["passwd"] }} +{% endif %} - name: DATABASE +{% if 'db' in cluster_cfg["marketplace-restserver"] %} value: {{ cluster_cfg["marketplace-restserver"]["db"] }} - - name: DB_HOST - value: {{ cluster_cfg["marketplace-restserver"]["db_host"] }} +{% else %} + value: {{ cluster_cfg["marketplace-db"]["db"] }} +{% endif %} - name: DB_PORT - value: "{{ cluster_cfg["marketplace-restserver"]["db_port"] }}" +{% if 'db_port' in cluster_cfg["marketplace-restserver"] %} + value: '{{ cluster_cfg["marketplace-restserver"]["db_port"] }}' +{% else %} + value: '{{ cluster_cfg["marketplace-db"]["port"] }}' +{% endif %} - name: NODE_ENV value: production - name: PORT diff --git a/src/marketplace-restserver/deploy/service.yaml b/src/marketplace-restserver/deploy/service.yaml index 8b22188561..8d368d5b9b 100644 --- a/src/marketplace-restserver/deploy/service.yaml +++ b/src/marketplace-restserver/deploy/service.yaml @@ -6,6 +6,7 @@ cluster-type: prerequisite: - cluster-configuration + - marketplace-db template-list: - marketplace-restserver.yaml diff --git a/src/marketplace-webportal/config/marketplace_webportal.py b/src/marketplace-webportal/config/marketplace_webportal.py index 7a807e4b3c..77ebb66770 100644 --- a/src/marketplace-webportal/config/marketplace_webportal.py +++ b/src/marketplace-webportal/config/marketplace_webportal.py @@ -21,8 +21,6 @@ def run(self): api_port = self.service_conf['api-port'] master_ip = [host['hostip'] for host in machine_list if host.get('pai-master') == 'true'][0] result['uri'] = 'http://{0}:{1}'.format(master_ip, server_port) - if 'marketplace_api_uri' not in result: - result['marketplace_api_uri'] = 'http://{0}:{1}/api'.format(master_ip, api_port) return result def validation_post(self, conf): diff --git a/src/marketplace-webportal/deploy/marketplace-webportal.yaml.template b/src/marketplace-webportal/deploy/marketplace-webportal.yaml.template index d641d6f2bf..a3868f88bd 100644 --- a/src/marketplace-webportal/deploy/marketplace-webportal.yaml.template +++ b/src/marketplace-webportal/deploy/marketplace-webportal.yaml.template @@ -22,7 +22,15 @@ spec: imagePullPolicy: Always env: - name: MARKETPLACE_API_URL +{%- if 'marketplace_api_uri' in cluster_cfg['marketplace-webportal'] %} value: {{ cluster_cfg["marketplace-webportal"]["marketplace_api_uri"] }} +{%- else %} +{% if "ssl" in cluster_cfg["pylon"] and cluster_cfg["pylon"]["ssl"] %} + value: "{{ cluster_cfg['pylon']['uri-https']}}/marketplace/api" +{% else %} + value: "{{ cluster_cfg['pylon']['uri']}}/marketplace/api" +{% endif %} +{%- endif %} - name: SERVER_PORT value: "{{ cluster_cfg["marketplace-webportal"]["server-port"] }}" - name: NPM_INSTALL_TOKEN diff --git a/src/marketplace-webportal/deploy/service.yaml b/src/marketplace-webportal/deploy/service.yaml index d4f9879c06..749cc95638 100644 --- a/src/marketplace-webportal/deploy/service.yaml +++ b/src/marketplace-webportal/deploy/service.yaml @@ -6,6 +6,7 @@ cluster-type: prerequisite: - cluster-configuration + - marketplace-restserver template-list: - marketplace-webportal.yaml diff --git a/src/webportal/config/webportal.py b/src/webportal/config/webportal.py index c3ac4ddca9..80d8f98409 100644 --- a/src/webportal/config/webportal.py +++ b/src/webportal/config/webportal.py @@ -61,7 +61,7 @@ def apply_config(plugin): return { 'server-port': server_port, 'uri': uri, - 'plugins': json.dumps([apply_config(plugin) for plugin in plugins]), + 'plugins': [apply_config(plugin) for plugin in plugins], 'webportal-address': master_ip, 'enable-job-transfer': self.service_configuration['enable-job-transfer'], } diff --git a/src/webportal/config/webportal.yaml b/src/webportal/config/webportal.yaml index c40ab50024..0cdcff9f5d 100644 --- a/src/webportal/config/webportal.yaml +++ b/src/webportal/config/webportal.yaml @@ -20,3 +20,6 @@ service_type: "common" server-port: 9286 enable-job-transfer: false + +# Will add the marketplace entries to webportal plugin if set true. +marketplace: true diff --git a/src/webportal/deploy/webportal.yaml.template b/src/webportal/deploy/webportal.yaml.template index 7c5495ac72..8561e55b62 100644 --- a/src/webportal/deploy/webportal.yaml.template +++ b/src/webportal/deploy/webportal.yaml.template @@ -91,7 +91,24 @@ spec: - name: WEBPORTAL_PLUGINS # A raw JSON formatted value is required here. value: | - {{ cluster_cfg['webportal']['plugins'] }} + [ +{% if cluster_cfg['cluster']['common']['marketplace'] == "true" and cluster_cfg['webportal']['marketplace'] == "true" %} + { + "id": "marketplace", + "title": "Marketplace", +{% if "ssl" in cluster_cfg["pylon"] and cluster_cfg["pylon"]["ssl"] %} + "uri": "{{ cluster_cfg['pylon']['uri-https']}}/marketplace/plugin.js" +{% else %} + "uri": "{{ cluster_cfg['pylon']['uri']}}/marketplace/plugin.js" +{% endif %} + }, +{% endif %} +{% if cluster_cfg['webportal']['plugins']|length > 0 %} +{% for item in cluster_cfg['webportal']['plugins'] %} + {{item}}, +{% endfor %} +{% endif %} + ] ports: - name: webportal containerPort: 8080