From eea4578dd127b3e7bed51b8b39dd1950e8ad7a32 Mon Sep 17 00:00:00 2001 From: Cole Walker Date: Fri, 29 Jan 2021 15:16:05 -0500 Subject: [PATCH] Added armada manifest and required build files This commit builds the armada manifest and packages the base helm charts and sysinv integration code into the final rpm. The output rpm, stx-ptp-notification-helm*.rpm can be deployed on a running system. Removes unused files in ptp-notification-helm. All required charts are now located under stx-ptp-notification-helm. Story: 2008529 Task: 41724 Signed-off-by: Cole Walker Change-Id: I49e970b7d21e4078aea3d185fbe98910f3d59ce6 --- CONTRIBUTING.rst | 10 + HACKING.rst | 13 ++ centos_build_layer.cfg | 1 + centos_iso_image.inc | 1 + centos_pkg_dirs | 2 + centos_pkg_dirs_containers | 2 + config | 0 ptp-notification-helm/centos/build_srpm.data | 0 ptp-notification-helm/centos/build_srpm.spec | 0 .../ptp-notification-helm/README | 0 .../ptp-notification-helm/files/Makefile | 0 .../ptp-notification-helm/files/index.yaml | 0 .../ptp-notification-helm/files/metadata.yaml | 0 .../files/repositories.yaml | 0 .../helm-charts/values.yaml | 0 requirements.txt | 1 + .../centos/build_srpm.data | 11 ++ .../centos/docker/placeholder.txt | 0 .../centos/stx-ptp-notification-helm.spec | 87 +++++++++ ...-ptp-notification-helm.stable_docker_image | 0 .../stx-ptp-notification-helm/README | 5 + .../files/index.yaml | 8 + .../files/metadata.yaml | 6 + .../files/repositories.yaml | 11 ++ .../helm-charts/Makefile | 43 +++++ .../helm-charts/ptp-notification/Chart.yaml | 10 + .../scripts/init/locationservice_start.sh | 174 +++++++++++++++++ .../scripts/init/ptptracking_start.sh | 98 ++++++++++ .../ptp-notification/templates/.helmignore | 22 +++ .../ptp-notification/templates/_helpers.tpl | 40 ++++ .../ptp-notification/templates/configmap.yaml | 26 +++ .../ptp-notification/templates/daemonset.yaml | 181 ++++++++++++++++++ .../templates/deployment.yaml | 40 ++++ .../ptp-notification/templates/service.yaml | 19 ++ .../helm-charts/ptp-notification/values.yaml | 77 ++++++++ .../manifests/ptp_notification_manifest.yaml | 80 ++++++++ test-requirements.txt | 3 + 37 files changed, 971 insertions(+) delete mode 100644 config delete mode 100644 ptp-notification-helm/centos/build_srpm.data delete mode 100644 ptp-notification-helm/centos/build_srpm.spec delete mode 100644 ptp-notification-helm/ptp-notification-helm/README delete mode 100644 ptp-notification-helm/ptp-notification-helm/files/Makefile delete mode 100644 ptp-notification-helm/ptp-notification-helm/files/index.yaml delete mode 100644 ptp-notification-helm/ptp-notification-helm/files/metadata.yaml delete mode 100644 ptp-notification-helm/ptp-notification-helm/files/repositories.yaml delete mode 100644 ptp-notification-helm/ptp-notification-helm/helm-charts/values.yaml delete mode 100644 stx-ptp-notification-helm/centos/docker/placeholder.txt delete mode 100644 stx-ptp-notification-helm/centos/stx-ptp-notification-helm.stable_docker_image create mode 100644 stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/Chart.yaml create mode 100644 stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/resources/scripts/init/locationservice_start.sh create mode 100644 stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/resources/scripts/init/ptptracking_start.sh create mode 100644 stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/.helmignore create mode 100644 stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/_helpers.tpl create mode 100644 stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/configmap.yaml create mode 100644 stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/daemonset.yaml create mode 100644 stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/deployment.yaml create mode 100644 stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/service.yaml create mode 100644 stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/values.yaml diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index e69de29..a69add6 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -0,0 +1,10 @@ +If you would like to contribute to the development of OpenStack, +you must follow the steps in this page: + https://docs.openstack.org/infra/manual/developers.html +Once those steps have been completed, changes to OpenStack +should be submitted for review via the Gerrit tool, following +the workflow documented at: + https://docs.openstack.org/infra/manual/developers.html#development-workflow +Pull requests submitted through GitHub will be ignored. +Bugs should be filed in Launchpad: + https://bugs.launchpad.net/starlingx diff --git a/HACKING.rst b/HACKING.rst index e69de29..f9729f8 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -0,0 +1,13 @@ +StarlingX PTP-Notification-Armada-App Style Commandments +================================================================ +- Step 1: Read the OpenStack style commandments + https://docs.openstack.org/hacking/latest/ +- Step 2: Read on +PTP-Notification-Armada-App Specific Commandments +--------------------------------------------------------- +None so far +Running tests +------------- +The approach to running tests is to simply run the command ``tox``. This will +create virtual environments, populate them with dependencies and run all of +the tests that OpenStack CI systems run. \ No newline at end of file diff --git a/centos_build_layer.cfg b/centos_build_layer.cfg index e69de29..fde92ef 100644 --- a/centos_build_layer.cfg +++ b/centos_build_layer.cfg @@ -0,0 +1 @@ +flock \ No newline at end of file diff --git a/centos_iso_image.inc b/centos_iso_image.inc index e69de29..e48b894 100644 --- a/centos_iso_image.inc +++ b/centos_iso_image.inc @@ -0,0 +1 @@ +stx-ptp-notification-helm \ No newline at end of file diff --git a/centos_pkg_dirs b/centos_pkg_dirs index e69de29..fec07f3 100644 --- a/centos_pkg_dirs +++ b/centos_pkg_dirs @@ -0,0 +1,2 @@ +stx-ptp-notification-helm +python-k8sapp-ptp-notification \ No newline at end of file diff --git a/centos_pkg_dirs_containers b/centos_pkg_dirs_containers index e69de29..fec07f3 100644 --- a/centos_pkg_dirs_containers +++ b/centos_pkg_dirs_containers @@ -0,0 +1,2 @@ +stx-ptp-notification-helm +python-k8sapp-ptp-notification \ No newline at end of file diff --git a/config b/config deleted file mode 100644 index e69de29..0000000 diff --git a/ptp-notification-helm/centos/build_srpm.data b/ptp-notification-helm/centos/build_srpm.data deleted file mode 100644 index e69de29..0000000 diff --git a/ptp-notification-helm/centos/build_srpm.spec b/ptp-notification-helm/centos/build_srpm.spec deleted file mode 100644 index e69de29..0000000 diff --git a/ptp-notification-helm/ptp-notification-helm/README b/ptp-notification-helm/ptp-notification-helm/README deleted file mode 100644 index e69de29..0000000 diff --git a/ptp-notification-helm/ptp-notification-helm/files/Makefile b/ptp-notification-helm/ptp-notification-helm/files/Makefile deleted file mode 100644 index e69de29..0000000 diff --git a/ptp-notification-helm/ptp-notification-helm/files/index.yaml b/ptp-notification-helm/ptp-notification-helm/files/index.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/ptp-notification-helm/ptp-notification-helm/files/metadata.yaml b/ptp-notification-helm/ptp-notification-helm/files/metadata.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/ptp-notification-helm/ptp-notification-helm/files/repositories.yaml b/ptp-notification-helm/ptp-notification-helm/files/repositories.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/ptp-notification-helm/ptp-notification-helm/helm-charts/values.yaml b/ptp-notification-helm/ptp-notification-helm/helm-charts/values.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/requirements.txt b/requirements.txt index e69de29..c01ade2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1 @@ +# Nothing diff --git a/stx-ptp-notification-helm/centos/build_srpm.data b/stx-ptp-notification-helm/centos/build_srpm.data index e69de29..e3aa90f 100644 --- a/stx-ptp-notification-helm/centos/build_srpm.data +++ b/stx-ptp-notification-helm/centos/build_srpm.data @@ -0,0 +1,11 @@ +SRC_DIR="stx-ptp-notification-helm" + +OPT_DEP_LIST="$STX_BASE/ptp-notification-armada-app/python-k8sapp-ptp-notification" + +COPY_LIST_TO_TAR="\ + $STX_BASE/helm-charts/psp-rolebinding/psp-rolebinding/helm-charts \ +" +# Keep the SRCREV in sync with python-k8sapp-ptp-notification so the app version is +# the same as the plugin version +TIS_BASE_SRCREV=c525a7fe479103bc316792c11b5289ebcca8a2a7 +TIS_PATCH_VER=GITREVCOUNT \ No newline at end of file diff --git a/stx-ptp-notification-helm/centos/docker/placeholder.txt b/stx-ptp-notification-helm/centos/docker/placeholder.txt deleted file mode 100644 index e69de29..0000000 diff --git a/stx-ptp-notification-helm/centos/stx-ptp-notification-helm.spec b/stx-ptp-notification-helm/centos/stx-ptp-notification-helm.spec index e69de29..9c794c7 100644 --- a/stx-ptp-notification-helm/centos/stx-ptp-notification-helm.spec +++ b/stx-ptp-notification-helm/centos/stx-ptp-notification-helm.spec @@ -0,0 +1,87 @@ +# Application tunables (maps to metadata) +%global app_name ptp-notification +%global helm_repo stx-platform + +%global armada_folder /usr/lib/armada + +# Install location +%global app_folder /usr/local/share/applications/helm + +# Build variables +%global helm_folder /usr/lib/helm + +Summary: StarlingX PTP Notification Armada Helm Charts +Name: stx-ptp-notification-helm +Version: 1.0 +Release: %{tis_patch_ver}%{?_tis_dist} +License: Apache-2.0 +Group: base +Packager: Wind River +URL: unknown + +Source0: %{name}-%{version}.tar.gz + +BuildArch: noarch + +BuildRequires: helm +BuildRequires: chartmuseum +BuildRequires: python-k8sapp-ptp-notification +BuildRequires: python-k8sapp-ptp-notification-wheels + +%description +StarlingX PTP Notification Helm Charts + +%prep +%setup -n %{name}-%{version} + +%build +chartmuseum --debug --port=8879 --context-path='/charts' --storage="local" --storage-local-rootdir="." & +sleep 2 + +helm repo add local http://localhost:8879/charts + +cd helm-charts +make ptp-notification +make psp-rolebinding +cd - + +# Terminate helm server (the last backgrounded task) +kill %1 + +# Create a chart tarball compliant with sysinv kube-app.py +%define app_staging %{_builddir}/staging +%define app_tarball %{app_name}-%{version}-%{tis_patch_ver}.tgz + +# Setup staging +mkdir -p %{app_staging} +cp files/metadata.yaml %{app_staging} +cp manifests/*.yaml %{app_staging} +mkdir -p %{app_staging}/charts +cp helm-charts/*.tgz %{app_staging}/charts +#cp %{helm_folder}/*.tgz %{app_staging}/charts +cd %{app_staging} + +# Populate metadata +sed -i 's/@APP_NAME@/%{app_name}/g' %{app_staging}/metadata.yaml +sed -i 's/@APP_VERSION@/%{version}-%{tis_patch_ver}/g' %{app_staging}/metadata.yaml +sed -i 's/@HELM_REPO@/%{helm_repo}/g' %{app_staging}/metadata.yaml + + +# Copy the plugins: installed in the buildroot +mkdir -p %{app_staging}/plugins +cp /plugins/%{app_name}/*.whl %{app_staging}/plugins + +# package it up +find . -type f ! -name '*.md5' -print0 | xargs -0 md5sum > checksum.md5 +tar -zcf %{_builddir}/%{app_tarball} -C %{app_staging}/ . + +# Cleanup staging +rm -fr %{app_staging} + +%install +install -d -m 755 %{buildroot}/%{app_folder} +install -p -D -m 755 %{_builddir}/%{app_tarball} %{buildroot}/%{app_folder} + +%files +%defattr(-,root,root,-) +%{app_folder}/* diff --git a/stx-ptp-notification-helm/centos/stx-ptp-notification-helm.stable_docker_image b/stx-ptp-notification-helm/centos/stx-ptp-notification-helm.stable_docker_image deleted file mode 100644 index e69de29..0000000 diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/README b/stx-ptp-notification-helm/stx-ptp-notification-helm/README index e69de29..b8152f5 100644 --- a/stx-ptp-notification-helm/stx-ptp-notification-helm/README +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/README @@ -0,0 +1,5 @@ +This directory contains all StarlingX charts that need to be built for this +application. Some charts are common across applications. These common charts +reside in the stx/helm-charts repository. To include these in this +application update the build_srpm.data file and use the COPY_LIST_TO_TAR +mechanism to populate these common charts. \ No newline at end of file diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/files/index.yaml b/stx-ptp-notification-helm/stx-ptp-notification-helm/files/index.yaml index e69de29..bcb641e 100644 --- a/stx-ptp-notification-helm/stx-ptp-notification-helm/files/index.yaml +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/files/index.yaml @@ -0,0 +1,8 @@ +# +# Copyright (c) 2021 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +apiVersion: v1 +entries: {} +generated: 2021-01-18T12:46:46.098162524-06:00 diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/files/metadata.yaml b/stx-ptp-notification-helm/stx-ptp-notification-helm/files/metadata.yaml index e69de29..8a9e1c8 100644 --- a/stx-ptp-notification-helm/stx-ptp-notification-helm/files/metadata.yaml +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/files/metadata.yaml @@ -0,0 +1,6 @@ +maintain_user_overrides: true + +app_name: @APP_NAME@ +app_version: @APP_VERSION@ +helm_repo: @HELM_REPO@ + diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/files/repositories.yaml b/stx-ptp-notification-helm/stx-ptp-notification-helm/files/repositories.yaml index e69de29..ddd9cdf 100644 --- a/stx-ptp-notification-helm/stx-ptp-notification-helm/files/repositories.yaml +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/files/repositories.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +generated: 2021-01-18T12:46:46.098162524-06:00 +repositories: +- caFile: "" + cache: /builddir/.helm/repository/cache/local-index.yaml + certFile: "" + keyFile: "" + name: local + password: "" + url: http://127.0.0.1:8879/charts + username: "" diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/Makefile b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/Makefile index e69de29..dc98968 100644 --- a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/Makefile +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/Makefile @@ -0,0 +1,43 @@ +# +# Copyright 2017 The Openstack-Helm Authors. +# +# Copyright (c) 2021 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +# It's necessary to set this because some environments don't link sh -> bash. +SHELL := /bin/bash +TASK := build + +EXCLUDES := helm-toolkit doc tests tools logs tmp +CHARTS := helm-toolkit $(filter-out $(EXCLUDES), $(patsubst %/.,%,$(wildcard */.))) + +.PHONY: $(EXCLUDES) $(CHARTS) + +all: $(CHARTS) + +$(CHARTS): + @if [ -d $@ ]; then \ + echo; \ + echo "===== Processing [$@] chart ====="; \ + make $(TASK)-$@; \ + fi + +init-%: + if [ -f $*/Makefile ]; then make -C $*; fi + if [ -f $*/requirements.yaml ]; then helm dep up $*; fi + +lint-%: init-% + if [ -d $* ]; then helm lint $*; fi + +build-%: + if [ -d $* ]; then helm package $*; fi + +clean: + @echo "Clean all build artifacts" + rm -f */templates/_partials.tpl */templates/_globals.tpl + rm -f *tgz */charts/*tgz */requirements.lock + rm -rf */charts */tmpcharts + +%: + @: diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/Chart.yaml b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/Chart.yaml new file mode 100644 index 0000000..53d9e43 --- /dev/null +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/Chart.yaml @@ -0,0 +1,10 @@ +# +# Copyright (c) 2021 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart to deploy PTP Notification Service +name: ptp-notification +version: 0.1.0 diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/resources/scripts/init/locationservice_start.sh b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/resources/scripts/init/locationservice_start.sh new file mode 100644 index 0000000..9053715 --- /dev/null +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/resources/scripts/init/locationservice_start.sh @@ -0,0 +1,174 @@ +# +# Copyright (c) 2021 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +#!/bin/bash + +# apt-get update -y +# #sleep infinity + +# apt-get install -y gcc +# apt-get install -y python-dev +# apt-get install -y python3-pip + +# export https_proxy=http://128.224.230.5:9090 + +# pip3 install oslo-config +# pip3 install oslo-messaging + +cat </root/location-query-server.py +#!/usr/bin/python3 +# -*- coding: UTF-8 -*- + +import os +import json +import time # 引入time模块 +import oslo_messaging +from oslo_config import cfg + + +THIS_NODE_NAME = os.environ.get("THIS_NODE_NAME",'controller-1') +THIS_POD_IP = os.environ.get("THIS_POD_IP",'127.0.0.1') +THIS_NAMESPACE = os.environ.get("THIS_NAMESPACE",'notification') + +rabbituser = os.environ.get("REGISTRATION_USER",'admin') +rabbitpasswd = os.environ.get("REGISTRATION_PASS",'admin') +rabbitip = "registration.{0}.svc.cluster.local".format(THIS_NAMESPACE) +rabbitport = os.environ.get("REGISTRATION_PORT",'5672') +# 'rabbit://admin:admin@172.16.192.78:5672/' +rabbitendpoint = "rabbit://{0}:{1}@{2}:{3}".format( + rabbituser, rabbitpasswd, rabbitip, rabbitport) + +class LocationInfoEndpoint(object): + target = oslo_messaging.Target(namespace='notification', version='1.0') + + def __init__(self, server): + self.server = server + + def QueryLocation(self, ctx, rpc_kwargs): + print ("QueryLocation called %s" %rpc_kwargs) + LocationInfo = { + 'NodeName': THIS_NODE_NAME, + 'PodIP': THIS_POD_IP, + 'ResourceTypes': ['PTP'], + 'Timestamp': time.time() + } + + return LocationInfo + +oslo_messaging.set_transport_defaults('notification_exchange') +transport = oslo_messaging.get_rpc_transport(cfg.CONF, url=rabbitendpoint) +target = oslo_messaging.Target(topic='LocationQuery', server="LocationService-{0}".format(THIS_NODE_NAME)) +endpoints = [LocationInfoEndpoint(None)] +server = oslo_messaging.get_rpc_server(transport, target, endpoints, + executor=None) +# oslo_messaging.server.ExecutorLoadFailure: +# Failed to load executor "blocking": Executor should be None or 'eventlet' and 'threading' +server.start() +print("LocationService-{0} starts".format(THIS_NODE_NAME)) +server.wait() + +EOF + + + +cat </root/location-announce.py +#!/usr/bin/python3 +# -*- coding: UTF-8 -*- + +import os +import json +import time # 引入time模块 +import oslo_messaging +from oslo_config import cfg +from webob.exc import HTTPException, HTTPNotFound, HTTPBadRequest, HTTPClientError, HTTPServerError + + +THIS_NODE_NAME = os.environ.get("THIS_NODE_NAME",'controller-1') +THIS_POD_IP = os.environ.get("THIS_POD_IP",'127.0.0.1') +THIS_NAMESPACE = os.environ.get("THIS_NAMESPACE",'notification') + +rabbituser = os.environ.get("REGISTRATION_USER",'admin') +rabbitpasswd = os.environ.get("REGISTRATION_PASS",'admin') +rabbitip = "registration.{0}.svc.cluster.local".format(THIS_NAMESPACE) +rabbitport = os.environ.get("REGISTRATION_PORT",'5672') +rabbitendpoint = "rabbit://{0}:{1}@{2}:{3}".format( + rabbituser, rabbitpasswd, rabbitip, rabbitport) + +oslo_messaging.set_transport_defaults('notification_exchange') +transport = oslo_messaging.get_rpc_transport(cfg.CONF, url=rabbitendpoint) + +location_topic='LocationListener-{0}'.format(THIS_NODE_NAME), +target = oslo_messaging.Target( + topic=location_topic, + fanout=True, + version='1.0', namespace='notification') + +client = oslo_messaging.RPCClient(transport, target) +LocationInfo = { + 'NodeName': THIS_NODE_NAME, + 'PodIP': THIS_POD_IP, + 'ResourceTypes': ['PTP'], + 'Timestamp': time.time() + } + +while True: + try: + client.cast({}, 'NotifyLocation', location_info=LocationInfo) + print("Announce location info:{0}@Topic:{1}".format(LocationInfo, location_topic)) + except HTTPNotFound as ex: + print("Failed to publish location due to not found: {0}".format(str(ex))) + continue + except Exception as ex: + print("Failed to publish location due to: {0}".format(str(ex))) + continue + else: + break + +EOF + +echo "done" + +# python3 /root/location-query-server.py & + +# python3 /root/location-announce.py + +cat </root/notification_control.py +import os +import time +import json +from pecan import conf +from locationservicesdk.services.daemon import DaemonControl + +REGISTRATION_USER = os.environ.get("REGISTRATION_USER", "admin") +REGISTRATION_PASS = os.environ.get("REGISTRATION_PASS", "admin") +REGISTRATION_PORT = os.environ.get("REGISTRATION_PORT", "5672") +REGISTRATION_HOST = os.environ.get("REGISTRATION_HOST",'registration.notification.svc.cluster.local') +THIS_NODE_NAME = os.environ.get("THIS_NODE_NAME",'controller-0') +THIS_POD_IP = os.environ.get("THIS_POD_IP",'127.0.0.1') + +REGISTRATION_TRANSPORT_ENDPOINT = 'rabbit://{0}:{1}@{2}:{3}'.format( + REGISTRATION_USER, REGISTRATION_PASS, REGISTRATION_HOST, REGISTRATION_PORT) + +sqlalchemy_conf_json=json.dumps({}) +LocationInfo = { + 'NodeName': THIS_NODE_NAME, + 'PodIP': THIS_POD_IP, + 'ResourceTypes': ['PTP'], + 'Timestamp': time.time() + } +location_info_json = json.dumps(LocationInfo) +notification_control = DaemonControl( + sqlalchemy_conf_json, REGISTRATION_TRANSPORT_ENDPOINT, location_info_json) + + +EOF + +cp /root/notification_control.py /opt/locationservice/apiserver/repository + +cd /opt/locationservice && pecan serve config.py & + + +sleep infinity diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/resources/scripts/init/ptptracking_start.sh b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/resources/scripts/init/ptptracking_start.sh new file mode 100644 index 0000000..d71b616 --- /dev/null +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/resources/scripts/init/ptptracking_start.sh @@ -0,0 +1,98 @@ +# +# Copyright (c) 2021 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +#!/bin/bash + +# apt-get update -y +# #sleep infinity + +# apt-get install -y gcc +# apt-get install -y python-dev +# apt-get install -y python3-pip + +# export https_proxy=http://128.224.230.5:9090 + +# pip3 install oslo-config +# pip3 install oslo-messaging + +cat </root/ptptracking-daemon.py +#!/usr/bin/python3 +# -*- coding: UTF-8 -*- +import logging +LOG = logging.getLogger(__name__) + +from trackingfunctionsdk.common.helpers import log_helper +log_helper.config_logger(LOG) + +import os +import json +import time # 引入time模块 +import oslo_messaging +from oslo_config import cfg + +from trackingfunctionsdk.services.daemon import DaemonControl + +THIS_NAMESPACE = os.environ.get("THIS_NAMESPACE",'notification') +THIS_NODE_NAME = os.environ.get("THIS_NODE_NAME",'controller-1') +THIS_POD_IP = os.environ.get("THIS_POD_IP",'127.0.0.1') +REGISTRATION_USER = os.environ.get("REGISTRATION_USER", "admin") +REGISTRATION_PASS = os.environ.get("REGISTRATION_PASS", "admin") +REGISTRATION_PORT = os.environ.get("REGISTRATION_PORT", "5672") +REGISTRATION_HOST = os.environ.get("REGISTRATION_HOST",'registration.notification.svc.cluster.local') + +REGISTRATION_TRANSPORT_ENDPOINT = 'rabbit://{0}:{1}@{2}:{3}'.format( + REGISTRATION_USER, REGISTRATION_PASS, REGISTRATION_HOST, REGISTRATION_PORT) + +NOTIFICATION_BROKER_USER = os.environ.get("NOTIFICATIONSERVICE_USER", "admin") +NOTIFICATION_BROKER_PASS = os.environ.get("NOTIFICATIONSERVICE_PASS", "admin") +NOTIFICATION_BROKER_PORT = os.environ.get("NOTIFICATIONSERVICE_PORT", "5672") + +NOTIFICATION_TRANSPORT_ENDPOINT = 'rabbit://{0}:{1}@{2}:{3}'.format( + NOTIFICATION_BROKER_USER, NOTIFICATION_BROKER_PASS, THIS_POD_IP, NOTIFICATION_BROKER_PORT) + +PTP_DEVICE_SIMULATED = os.environ.get("PTP_DEVICE_SIMULATED", False) + +PTP_HOLDOVER_SECONDS = os.environ.get("PTP_HOLDOVER_SECONDS", 30) +PTP_POLL_FREQ_SECONDS = os.environ.get("PTP_POLL_FREQ_SECONDS", 2) + +context = { + 'THIS_NAMESPACE': THIS_NAMESPACE, + 'THIS_NODE_NAME': THIS_NODE_NAME, + 'THIS_POD_IP': THIS_POD_IP, + 'REGISTRATION_TRANSPORT_ENDPOINT': REGISTRATION_TRANSPORT_ENDPOINT, + 'NOTIFICATION_TRANSPORT_ENDPOINT': NOTIFICATION_TRANSPORT_ENDPOINT, + # 'NOTIFICATION_BROKER_USER': NOTIFICATION_BROKER_USER, + # 'NOTIFICATION_BROKER_PASS': NOTIFICATION_BROKER_PASS, + # 'NOTIFICATION_BROKER_PORT': NOTIFICATION_BROKER_PORT + 'ptptracker_context': { + 'device_simulated': PTP_DEVICE_SIMULATED, + 'holdover_seconds': PTP_HOLDOVER_SECONDS, + 'poll_freq_seconds': PTP_POLL_FREQ_SECONDS + } +} + +sqlalchemy_conf = { + 'url' : 'sqlite:///apiserver.db', + 'echo' : False, + 'echo_pool' : False, + 'pool_recycle' : 3600, + 'encoding' : 'utf-8' +} +sqlalchemy_conf_json = json.dumps(sqlalchemy_conf) +default_daemoncontrol = DaemonControl(sqlalchemy_conf_json, json.dumps(context)) + +default_daemoncontrol.refresh() +while True: + pass + +EOF + + + +echo "done" + +PYTHONPATH=/opt/ptptrackingfunction python3 /root/ptptracking-daemon.py & + +sleep infinity diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/.helmignore b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/.helmignore @@ -0,0 +1,22 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/_helpers.tpl b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/_helpers.tpl new file mode 100644 index 0000000..d9798d3 --- /dev/null +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/_helpers.tpl @@ -0,0 +1,40 @@ +{{/* +# +# Copyright (c) 2021 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +*/}} + +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "notification.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "notification.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "notification.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/configmap.yaml b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/configmap.yaml new file mode 100644 index 0000000..5bef2fc --- /dev/null +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/configmap.yaml @@ -0,0 +1,26 @@ +# Copyright © 2017 Amdocs, Bell Canada +# Modifications Copyright © 2018 AT&T +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Chart.Name }}-scripts-configmap + namespace: {{ .Values.global.namespace }} + labels: + release: {{ .Release.Name }} + app: {{ include "notification.name" . }} + chart: {{ .Chart.Name }} +data: +{{ tpl (.Files.Glob "resources/scripts/init/*").AsConfig . | indent 2 }} diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/daemonset.yaml b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/daemonset.yaml new file mode 100644 index 0000000..de17990 --- /dev/null +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/daemonset.yaml @@ -0,0 +1,181 @@ +# +# Copyright (c) 2021 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: {{ include "notification.fullname" . }} + namespace: {{ .Values.global.namespace }} + labels: + release: {{ .Release.Name }} + app: {{ include "notification.name" . }} + chart: {{ .Chart.Name }} +spec: + selector: + matchLabels: + app: {{ include "notification.name" . }} + release: {{ .Release.Name }} + template: + metadata: + namespace: {{ .Values.global.namespace }} + labels: + app: {{ include "notification.name" . }} + release: {{ .Release.Name }} + spec: + imagePullSecrets: + - name: {{ .Values.ptptracking.imagePullSecrets}} + {{ if .Values.ptptracking.device.simulated }} + {{ else }} +{{- if .Values.notification.affinity }} + affinity: +{{ toYaml .Values.notification.affinity | indent 8 }} +{{- end }} + {{ end }} + containers: + - name: {{ .Chart.Name }}-rabbitmq + image: rabbitmq:3-management + env: + - name: THIS_NODE_NAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName + - name: THIS_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + - name: THIS_NAMESPACE + value: {{ .Values.global.namespace }} + - name: RABBITMQ_DEFAULT_USER + value: "admin" + - name: RABBITMQ_DEFAULT_PASS + value: "admin" + - name: RABBITMQ_DEFAULT_PORT + value: "5672" + - name: {{ .Chart.Name }}-location + image: "{{ .Values.location.image.repository }}:{{ .Values.location.image.tag }}" + imagePullPolicy: {{ .Values.location.image.pullPolicy }} + tty: true + stdin: true + env: + - name: THIS_NODE_NAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName + - name: THIS_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + - name: THIS_NAMESPACE + value: {{ .Values.global.namespace }} + - name: REGISTRATION_HOST + value: "{{ .Values.registration.endpoint.host }}" + - name: REGISTRATION_USER + value: "{{ .Values.registration.endpoint.user }}" + - name: REGISTRATION_PASS + value: "{{ .Values.registration.endpoint.pass }}" + - name: REGISTRATION_PORT + value: "{{ .Values.registration.endpoint.port }}" + - name: NOTIFICATIONSERVICE_USER + value: "{{ .Values.notification.endpoint.user }}" + - name: NOTIFICATIONSERVICE_PASS + value: "{{ .Values.notification.endpoint.pass }}" + - name: NOTIFICATIONSERVICE_PORT + value: "{{ .Values.notification.endpoint.port }}" + + command: ["/bin/bash", "/mnt/locationservice_start.sh"] + volumeMounts: + - name: scripts + mountPath: /mnt + resources: + limits: + cpu: {{ .Values.resources.cpu }} + memory: {{ .Values.resources.memory }} + - name: {{ .Chart.Name }}-ptptracking + image: "{{ .Values.ptptracking.image.repository }}:{{ .Values.ptptracking.image.tag }}" + imagePullPolicy: {{ .Values.ptptracking.image.pullPolicy }} + tty: true + stdin: true + env: + - name: THIS_NODE_NAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName + - name: THIS_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + - name: THIS_NAMESPACE + value: {{ .Values.global.namespace }} + - name: PTP_DEVICE_SIMULATED + value: "{{ .Values.ptptracking.device.simulated }}" + - name: PTP_HOLDOVER_SECONDS + value: "{{ .Values.ptptracking.device.holdover_seconds }}" + - name: PTP_POLL_FREQ_SECONDS + value: "{{ .Values.ptptracking.device.poll_freq_seconds }}" + - name: NOTIFICATIONSERVICE_USER + value: "admin" + - name: NOTIFICATIONSERVICE_PASS + value: "admin" + - name: NOTIFICATIONSERVICE_PORT + value: "5672" + - name: REGISTRATION_USER + value: "admin" + - name: REGISTRATION_PASS + value: "admin" + - name: REGISTRATION_PORT + value: "5672" + - name: REGISTRATION_HOST + value: "registration.{{.Values.global.namespace}}.svc.cluster.local" + command: ["/bin/bash", "/mnt/ptptracking_start.sh"] + securityContext: + privileged: true + capabilities: + add: + - CAP_SYS_ADMIN + volumeMounts: + - name: scripts + mountPath: /mnt + {{ if .Values.ptptracking.device.simulated }} + {{ else }} + - name: ptpdir + mountPath: /var/run/ + readOnly: false + - name: varrun + mountPath: /var/run/ptp4l + readOnly: false + - name: pmc + mountPath: /usr/sbin/pmc + readOnly: false + {{ end }} + - name: conf + mountPath: /ptp/ + readOnly: true + resources: + limits: + cpu: {{ .Values.resources.cpu }} + memory: {{ .Values.resources.memory }} + volumes: + - name: scripts + configMap: + name: {{ .Chart.Name }}-scripts-configmap + - name: ptpdir + hostPath: + path: /var/run/ + type: Directory + {{ if .Values.ptptracking.device.simulated }} + {{ else }} + - name: varrun + hostPath: + path: /var/run/ptp4l + type: Socket + {{ end }} + - name: pmc + hostPath: + path: /usr/sbin/pmc + - name: conf + hostPath: + path: /etc/ + type: Directory diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/deployment.yaml b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/deployment.yaml new file mode 100644 index 0000000..0601304 --- /dev/null +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/deployment.yaml @@ -0,0 +1,40 @@ +# +# Copyright (c) 2021 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: registration + namespace: {{ .Values.global.namespace }} + labels: + app: rabbitmq +spec: + replicas: 1 + selector: + matchLabels: + app: rabbitmq + template: + metadata: + labels: + app: rabbitmq + spec: + imagePullSecrets: + - name: {{ .Values.registration.imagePullSecrets }} +{{- if .Values.registration.affinity }} + affinity: +{{ toYaml .Values.registration.affinity | indent 8 }} +{{- end }} + containers: + - name: rabbitmq + image: "{{ .Values.registration.image.repository }}:{{ .Values.registration.image.tag }}" + env: + - name: RABBITMQ_DEFAULT_USER + value: "admin" + - name: RABBITMQ_DEFAULT_PASS + value: "admin" + - name: RABBITMQ_DEFAULT_PORT + value: "5672" +--- diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/service.yaml b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/service.yaml new file mode 100644 index 0000000..5592a28 --- /dev/null +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/service.yaml @@ -0,0 +1,19 @@ +# +# Copyright (c) 2021 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +apiVersion: v1 +kind: Service +metadata: + name: registration + namespace: {{ .Values.global.namespace }} +spec: + #clusterIP: None + ports: + - name: rabbitmq + port: 5672 + protocol: TCP + selector: + app: rabbitmq \ No newline at end of file diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/values.yaml b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/values.yaml new file mode 100644 index 0000000..0b971ae --- /dev/null +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/values.yaml @@ -0,0 +1,77 @@ +# +# Copyright (c) 2021 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +# Default values for notification services. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +# global vars for parent and subcharts. +# registration.endpoint.host: registration.{namespace}.svc.{cluster-domain} + +replicaCount: 1 + +nameOverride: "" +fullnameOverride: "" + +resources: + cpu: 1 + memory: 2Gi + +global: + namespace: notification + +registration: + imagePullSecrets: default-registry-key + image: + repository: rabbitmq + tag: 3-management + pullPolicy: IfNotPresent + endpoint: + host: "registration.notification.svc.cluster.local" + port: 5672 + user: admin + pass: admin + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: ptp-registration + operator: In + values: + - "true" + +notification: + endpoint: + port: 5672 + user: admin + pass: admin + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: ptp-notification + operator: In + values: + - "true" + +location: + image: + repository: locationservice + tag: 1.0.1 + pullPolicy: IfNotPresent + +ptptracking: + imagePullSecrets: admin-registry-secret + image: + repository: ptptrackingfunction + tag: 1.0.1 + pullPolicy: IfNotPresent + device: + simulated: false + holdover_seconds: 30 + poll_freq_seconds: 2 diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/manifests/ptp_notification_manifest.yaml b/stx-ptp-notification-helm/stx-ptp-notification-helm/manifests/ptp_notification_manifest.yaml index e69de29..e309ef4 100644 --- a/stx-ptp-notification-helm/stx-ptp-notification-helm/manifests/ptp_notification_manifest.yaml +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/manifests/ptp_notification_manifest.yaml @@ -0,0 +1,80 @@ +--- +schema: armada/Chart/v1 +metadata: + schema: metadata/Document/v1 + name: ptp-notification-psp-rolebinding +data: + chart_name: ptp-notification-psp-rolebinding + release: ptp-notification-psp-rolebinding + namespace: notification + values: + rolebindingNamespace: notification + serviceAccount: notification + source: + location: http://172.17.0.1:8080/helm_charts/stx-platform/psp-rolebinding-0.1.0.tgz + subpath: psp-rolebinding + type: tar + reference: master + upgrade: + no_hooks: false + pre: + delete: + - labels: + release_group: ptp-notification-psp-rolebinding + type: job + wait: + labels: + release_group: ptp-notification-psp-rolebinding + resources: [] + timeout: 1800 + dependencies: [] +--- +schema: armada/Chart/v1 +metadata: + schema: metadata/Document/v1 + name: ptp-notification +data: + chart_name: ptp-notification + release: ptp-notification + namespace: notification + wait: + timeout: 1800 + labels: + app: ptp-notification + install: + no_hooks: false + upgrade: + no_hooks: false + pre: + delete: + - type: job + labels: + app: ptp-notification + values: + replicaCount: 1 + source: + type: tar + location: http://172.17.0.1/helm_charts/stx-platform/ptp-notification-0.1.0.tgz + subpath: ptp-notification + reference: master + dependencies: [] +--- +schema: armada/ChartGroup/v1 +metadata: + schema: metadata/Document/v1 + name: ptp-notification +data: + description: "Deploy PTP Notification" + sequenced: false + chart_group: + - ptp-notification + - ptp-notification-psp-rolebinding +--- +schema: armada/Manifest/v1 +metadata: + schema: metadata/Document/v1 + name: ptp-notification-manifest +data: + release_prefix: ptp + chart_groups: + - ptp-notification \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt index e69de29..8ae3e22 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -0,0 +1,3 @@ +# hacking pulls in flake8 +hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 +bashate >= 0.2