From aae2da91becf5f1f56329d49656c1ad634917cba Mon Sep 17 00:00:00 2001 From: Krzysztof Opasiak Date: Fri, 8 May 2020 18:56:39 +0200 Subject: [Tree-wide] Make chart build process predictible ONAP is built using plain makefile rules. List of targets is generated using wildcard function. Based on make changelog: http://git.savannah.gnu.org/cgit/make.git/tree/NEWS since version 3.82 wildcard is not going to sort its results which means that charts are being processed in an arbitrary order which may lead to build failure due to missing dependencies. Since version 4.3 make started sorting the wildcard results once again which may lead to build issues. To avoid that and make our builds predictible independently from Makefile version let's make sure that we always sort wildcard results. Addinally let's use 'file://' instead of '@local' for charts in common to resolve dependencies between them. Issue-ID: OOM-2399 Signed-off-by: Krzysztof Opasiak Change-Id: Iacb02dcdbd577ce0e9ca1078dd0586d296ec9375 --- kubernetes/Makefile | 4 +- kubernetes/common/Makefile | 4 +- kubernetes/common/cassandra/requirements.yaml | 2 +- kubernetes/common/dgbuilder/requirements.yaml | 2 +- .../components/curator/requirements.yaml | 2 +- .../components/data/requirements.yaml | 2 +- .../components/master/requirements.yaml | 2 +- kubernetes/common/elasticsearch/requirements.yaml | 3 +- kubernetes/common/etcd/requirements.yaml | 2 +- kubernetes/common/mongo/requirements.yaml | 2 +- .../music/charts/music-cassandra/requirements.yaml | 2 +- kubernetes/common/music/requirements.yaml | 2 +- .../common/network-name-gen/requirements.yaml | 6 +- kubernetes/common/postgres/requirements.yaml | 2 +- kubernetes/sdnc/Makefile | 6 +- kubernetes/sdnc/components/Makefile | 51 +++++++++ kubernetes/sdnc/components/sdnc-prom/Chart.yaml | 18 +++ .../sdnc/components/sdnc-prom/requirements.yaml | 18 +++ .../sdnc-prom/resources/bin/ensureSdncActive.sh | 105 +++++++++++++++++ .../sdnc-prom/resources/bin/ensureSdncStandby.sh | 58 ++++++++++ .../components/sdnc-prom/resources/bin/prom.sh | 31 +++++ .../sdnc-prom/resources/bin/sdnc.cluster | 61 ++++++++++ .../sdnc-prom/resources/bin/sdnc.dnsswitch | 22 ++++ .../sdnc-prom/resources/bin/sdnc.failover | 86 ++++++++++++++ .../sdnc-prom/resources/bin/sdnc.monitor | 125 +++++++++++++++++++++ .../sdnc-prom/resources/bin/switchVoting.sh | 110 ++++++++++++++++++ .../sdnc-prom/resources/config/config.json | 19 ++++ .../sdnc-prom/resources/config/healthchecks.json | 1 + .../components/sdnc-prom/templates/configmap.yaml | 41 +++++++ .../components/sdnc-prom/templates/deployment.yaml | 101 +++++++++++++++++ .../sdnc/components/sdnc-prom/templates/pv.yaml | 39 +++++++ .../sdnc/components/sdnc-prom/templates/pvc.yaml | 39 +++++++ kubernetes/sdnc/components/sdnc-prom/values.yaml | 102 +++++++++++++++++ kubernetes/sdnc/sdnc-prom/Chart.yaml | 18 --- kubernetes/sdnc/sdnc-prom/requirements.yaml | 18 --- .../sdnc-prom/resources/bin/ensureSdncActive.sh | 105 ----------------- .../sdnc-prom/resources/bin/ensureSdncStandby.sh | 58 ---------- kubernetes/sdnc/sdnc-prom/resources/bin/prom.sh | 31 ----- .../sdnc/sdnc-prom/resources/bin/sdnc.cluster | 61 ---------- .../sdnc/sdnc-prom/resources/bin/sdnc.dnsswitch | 22 ---- .../sdnc/sdnc-prom/resources/bin/sdnc.failover | 86 -------------- .../sdnc/sdnc-prom/resources/bin/sdnc.monitor | 125 --------------------- .../sdnc/sdnc-prom/resources/bin/switchVoting.sh | 110 ------------------ .../sdnc/sdnc-prom/resources/config/config.json | 19 ---- .../sdnc-prom/resources/config/healthchecks.json | 1 - kubernetes/sdnc/sdnc-prom/templates/configmap.yaml | 41 ------- .../sdnc/sdnc-prom/templates/deployment.yaml | 101 ----------------- kubernetes/sdnc/sdnc-prom/templates/pv.yaml | 39 ------- kubernetes/sdnc/sdnc-prom/templates/pvc.yaml | 39 ------- kubernetes/sdnc/sdnc-prom/values.yaml | 102 ----------------- 50 files changed, 1048 insertions(+), 998 deletions(-) create mode 100644 kubernetes/sdnc/components/Makefile create mode 100644 kubernetes/sdnc/components/sdnc-prom/Chart.yaml create mode 100644 kubernetes/sdnc/components/sdnc-prom/requirements.yaml create mode 100755 kubernetes/sdnc/components/sdnc-prom/resources/bin/ensureSdncActive.sh create mode 100755 kubernetes/sdnc/components/sdnc-prom/resources/bin/ensureSdncStandby.sh create mode 100755 kubernetes/sdnc/components/sdnc-prom/resources/bin/prom.sh create mode 100755 kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.cluster create mode 100755 kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.dnsswitch create mode 100755 kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.failover create mode 100755 kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.monitor create mode 100755 kubernetes/sdnc/components/sdnc-prom/resources/bin/switchVoting.sh create mode 100644 kubernetes/sdnc/components/sdnc-prom/resources/config/config.json create mode 100644 kubernetes/sdnc/components/sdnc-prom/resources/config/healthchecks.json create mode 100644 kubernetes/sdnc/components/sdnc-prom/templates/configmap.yaml create mode 100644 kubernetes/sdnc/components/sdnc-prom/templates/deployment.yaml create mode 100644 kubernetes/sdnc/components/sdnc-prom/templates/pv.yaml create mode 100644 kubernetes/sdnc/components/sdnc-prom/templates/pvc.yaml create mode 100644 kubernetes/sdnc/components/sdnc-prom/values.yaml delete mode 100644 kubernetes/sdnc/sdnc-prom/Chart.yaml delete mode 100644 kubernetes/sdnc/sdnc-prom/requirements.yaml delete mode 100755 kubernetes/sdnc/sdnc-prom/resources/bin/ensureSdncActive.sh delete mode 100755 kubernetes/sdnc/sdnc-prom/resources/bin/ensureSdncStandby.sh delete mode 100755 kubernetes/sdnc/sdnc-prom/resources/bin/prom.sh delete mode 100755 kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.cluster delete mode 100755 kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.dnsswitch delete mode 100755 kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.failover delete mode 100755 kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.monitor delete mode 100755 kubernetes/sdnc/sdnc-prom/resources/bin/switchVoting.sh delete mode 100644 kubernetes/sdnc/sdnc-prom/resources/config/config.json delete mode 100644 kubernetes/sdnc/sdnc-prom/resources/config/healthchecks.json delete mode 100644 kubernetes/sdnc/sdnc-prom/templates/configmap.yaml delete mode 100644 kubernetes/sdnc/sdnc-prom/templates/deployment.yaml delete mode 100644 kubernetes/sdnc/sdnc-prom/templates/pv.yaml delete mode 100644 kubernetes/sdnc/sdnc-prom/templates/pvc.yaml delete mode 100644 kubernetes/sdnc/sdnc-prom/values.yaml (limited to 'kubernetes') diff --git a/kubernetes/Makefile b/kubernetes/Makefile index 7150f10c1f..faa96df811 100644 --- a/kubernetes/Makefile +++ b/kubernetes/Makefile @@ -28,9 +28,9 @@ endif SUBMODS := robot aai EXCLUDES := config oneclick readiness test dist helm $(PARENT_CHART) dcae $(SUBMODS) -HELM_CHARTS := $(filter-out $(EXCLUDES), $(patsubst %/.,%,$(wildcard */.))) $(PARENT_CHART) +HELM_CHARTS := $(filter-out $(EXCLUDES), $(sort $(patsubst %/.,%,$(wildcard */.)))) $(SUBMODS) $(PARENT_CHART) -.PHONY: $(EXCLUDES) $(HELM_CHARTS) $(SUBMODS) +.PHONY: $(EXCLUDES) $(HELM_CHARTS) all: $(COMMON_CHARTS_DIR) $(SUBMODS) $(HELM_CHARTS) plugins diff --git a/kubernetes/common/Makefile b/kubernetes/common/Makefile index 5bd503e0ff..941c2f84df 100644 --- a/kubernetes/common/Makefile +++ b/kubernetes/common/Makefile @@ -20,7 +20,7 @@ SECRET_DIR := $(OUTPUT_DIR)/secrets COMMON_CHARTS_DIR := common EXCLUDES := -HELM_CHARTS := $(filter-out $(EXCLUDES), $(patsubst %/.,%,$(wildcard */.))) +HELM_CHARTS := $(filter-out $(EXCLUDES), $(sort $(patsubst %/.,%,$(wildcard */.)))) .PHONY: $(EXCLUDES) $(HELM_CHARTS) @@ -49,4 +49,4 @@ clean: @rm -f *tgz */charts/*tgz @rm -rf $(PACKAGE_DIR) %: - @: \ No newline at end of file + @: diff --git a/kubernetes/common/cassandra/requirements.yaml b/kubernetes/common/cassandra/requirements.yaml index bab2c4befc..90e6621aa3 100644 --- a/kubernetes/common/cassandra/requirements.yaml +++ b/kubernetes/common/cassandra/requirements.yaml @@ -16,4 +16,4 @@ dependencies: - name: common version: ~6.x-0 - repository: '@local' + repository: 'file://../common' diff --git a/kubernetes/common/dgbuilder/requirements.yaml b/kubernetes/common/dgbuilder/requirements.yaml index 7d56bf28ef..4735901dfa 100644 --- a/kubernetes/common/dgbuilder/requirements.yaml +++ b/kubernetes/common/dgbuilder/requirements.yaml @@ -15,4 +15,4 @@ dependencies: - name: common version: ~6.x-0 - repository: '@local' \ No newline at end of file + repository: 'file://../common' diff --git a/kubernetes/common/elasticsearch/components/curator/requirements.yaml b/kubernetes/common/elasticsearch/components/curator/requirements.yaml index ff65593469..e9a5a5f61a 100644 --- a/kubernetes/common/elasticsearch/components/curator/requirements.yaml +++ b/kubernetes/common/elasticsearch/components/curator/requirements.yaml @@ -15,4 +15,4 @@ dependencies: - name: common version: ~6.x-0 - repository: '@local' \ No newline at end of file + repository: 'file://../../../common' diff --git a/kubernetes/common/elasticsearch/components/data/requirements.yaml b/kubernetes/common/elasticsearch/components/data/requirements.yaml index 6a61926e9e..a1f72ffc60 100644 --- a/kubernetes/common/elasticsearch/components/data/requirements.yaml +++ b/kubernetes/common/elasticsearch/components/data/requirements.yaml @@ -15,4 +15,4 @@ dependencies: - name: common version: ~6.x-0 - repository: '@local' \ No newline at end of file + repository: 'file://../../../common' diff --git a/kubernetes/common/elasticsearch/components/master/requirements.yaml b/kubernetes/common/elasticsearch/components/master/requirements.yaml index 6a61926e9e..a1f72ffc60 100644 --- a/kubernetes/common/elasticsearch/components/master/requirements.yaml +++ b/kubernetes/common/elasticsearch/components/master/requirements.yaml @@ -15,4 +15,4 @@ dependencies: - name: common version: ~6.x-0 - repository: '@local' \ No newline at end of file + repository: 'file://../../../common' diff --git a/kubernetes/common/elasticsearch/requirements.yaml b/kubernetes/common/elasticsearch/requirements.yaml index 84fa71c6e6..8a02fef7b7 100644 --- a/kubernetes/common/elasticsearch/requirements.yaml +++ b/kubernetes/common/elasticsearch/requirements.yaml @@ -15,7 +15,7 @@ dependencies: - name: common version: ~6.x-0 - repository: '@local' + repository: 'file://../common' - name: master version: ~6.x-0 repository: 'file://components/master' @@ -27,4 +27,3 @@ dependencies: version: ~6.x-0 repository: 'file://components/curator' condition: elasticsearch.curator.enabled,curator.enabled - diff --git a/kubernetes/common/etcd/requirements.yaml b/kubernetes/common/etcd/requirements.yaml index facbc4434e..e90e615d73 100644 --- a/kubernetes/common/etcd/requirements.yaml +++ b/kubernetes/common/etcd/requirements.yaml @@ -15,4 +15,4 @@ dependencies: - name: common version: ~6.x-0 - repository: '@local' + repository: 'file://../common' diff --git a/kubernetes/common/mongo/requirements.yaml b/kubernetes/common/mongo/requirements.yaml index f99477141f..6ba617e990 100644 --- a/kubernetes/common/mongo/requirements.yaml +++ b/kubernetes/common/mongo/requirements.yaml @@ -15,4 +15,4 @@ dependencies: - name: common version: ~6.x-0 - repository: '@local' + repository: 'file://../common' diff --git a/kubernetes/common/music/charts/music-cassandra/requirements.yaml b/kubernetes/common/music/charts/music-cassandra/requirements.yaml index 38536fcd78..0a80d654d0 100644 --- a/kubernetes/common/music/charts/music-cassandra/requirements.yaml +++ b/kubernetes/common/music/charts/music-cassandra/requirements.yaml @@ -15,4 +15,4 @@ dependencies: - name: common version: ~6.x-0 - repository: '@local' \ No newline at end of file + repository: 'file://../../../common' diff --git a/kubernetes/common/music/requirements.yaml b/kubernetes/common/music/requirements.yaml index a7089ea6b3..1c428d214e 100644 --- a/kubernetes/common/music/requirements.yaml +++ b/kubernetes/common/music/requirements.yaml @@ -15,4 +15,4 @@ dependencies: - name: common version: ~6.x-0 - repository: '@local' + repository: 'file://../common' diff --git a/kubernetes/common/network-name-gen/requirements.yaml b/kubernetes/common/network-name-gen/requirements.yaml index 8152196ab5..8c2277c210 100644 --- a/kubernetes/common/network-name-gen/requirements.yaml +++ b/kubernetes/common/network-name-gen/requirements.yaml @@ -15,12 +15,12 @@ dependencies: - name: common version: ~6.x-0 - repository: '@local' + repository: 'file://../common' - name: mariadb-galera version: ~6.x-0 - repository: '@local' + repository: 'file://../mariadb-galera' condition: global.mariadbGalera.localCluster - name: mariadb-init version: ~6.x-0 - repository: '@local' + repository: 'file://../mariadb-init' condition: not global.mariadbGalera.localCluster diff --git a/kubernetes/common/postgres/requirements.yaml b/kubernetes/common/postgres/requirements.yaml index 76afd96b98..6f898b6171 100644 --- a/kubernetes/common/postgres/requirements.yaml +++ b/kubernetes/common/postgres/requirements.yaml @@ -15,4 +15,4 @@ dependencies: - name: common version: ~6.x-0 - repository: '@local' + repository: 'file://../common' diff --git a/kubernetes/sdnc/Makefile b/kubernetes/sdnc/Makefile index d634a8c506..e4b5dda95d 100644 --- a/kubernetes/sdnc/Makefile +++ b/kubernetes/sdnc/Makefile @@ -18,8 +18,8 @@ OUTPUT_DIR := $(ROOT_DIR)/../dist PACKAGE_DIR := $(OUTPUT_DIR)/packages SECRET_DIR := $(OUTPUT_DIR)/secrets -EXCLUDES := -HELM_CHARTS := $(filter-out $(EXCLUDES), $(patsubst %/.,%,$(wildcard */.))) +EXCLUDES := dist resources templates charts +HELM_CHARTS := $(filter-out $(EXCLUDES), $(sort $(patsubst %/.,%,$(wildcard */.)))) .PHONY: $(EXCLUDES) $(HELM_CHARTS) @@ -48,4 +48,4 @@ clean: @rm -f *tgz */charts/*tgz @rm -rf $(PACKAGE_DIR) %: - @: \ No newline at end of file + @: diff --git a/kubernetes/sdnc/components/Makefile b/kubernetes/sdnc/components/Makefile new file mode 100644 index 0000000000..4e737638a6 --- /dev/null +++ b/kubernetes/sdnc/components/Makefile @@ -0,0 +1,51 @@ +# Copyright © 2017 Amdocs, Bell Canada +# +# 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. + +# FIXME OOM-765 +ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) +OUTPUT_DIR := $(ROOT_DIR)/../../dist +PACKAGE_DIR := $(OUTPUT_DIR)/packages +SECRET_DIR := $(OUTPUT_DIR)/secrets + +EXCLUDES := +HELM_CHARTS := $(filter-out $(EXCLUDES), $(sort $(patsubst %/.,%,$(wildcard */.)))) + +.PHONY: $(EXCLUDES) $(HELM_CHARTS) + +all: $(HELM_CHARTS) + +$(HELM_CHARTS): + @echo "\n[$@]" + @make package-$@ + +make-%: + @if [ -f $*/Makefile ]; then make -C $*; fi + +dep-%: make-% + @if [ -f $*/requirements.yaml ]; then helm dep up $*; fi + +lint-%: dep-% + @if [ -f $*/Chart.yaml ]; then helm lint $*; fi + +package-%: lint-% + @mkdir -p $(PACKAGE_DIR) + @if [ -f $*/Chart.yaml ]; then helm package -d $(PACKAGE_DIR) $*; fi + @helm repo index $(PACKAGE_DIR) + +clean: + @rm -f */requirements.lock + @rm -f *tgz */charts/*tgz + @rm -rf $(PACKAGE_DIR) +%: + @: diff --git a/kubernetes/sdnc/components/sdnc-prom/Chart.yaml b/kubernetes/sdnc/components/sdnc-prom/Chart.yaml new file mode 100644 index 0000000000..54fb337f04 --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/Chart.yaml @@ -0,0 +1,18 @@ +# Copyright © 2018 Amdocs +# +# 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 +description: ONAP SDNC Policy Driven Ownership Management +name: sdnc-prom +version: 6.0.0 diff --git a/kubernetes/sdnc/components/sdnc-prom/requirements.yaml b/kubernetes/sdnc/components/sdnc-prom/requirements.yaml new file mode 100644 index 0000000000..e4c7240290 --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/requirements.yaml @@ -0,0 +1,18 @@ +# Copyright © 2018 Amdocs +# +# 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. + +dependencies: + - name: common + version: ~6.x-0 + repository: '@local' diff --git a/kubernetes/sdnc/components/sdnc-prom/resources/bin/ensureSdncActive.sh b/kubernetes/sdnc/components/sdnc-prom/resources/bin/ensureSdncActive.sh new file mode 100755 index 0000000000..fb24653129 --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/resources/bin/ensureSdncActive.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +# Copyright © 2018 Amdocs +# +# 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. + +debugLog(){ + if [ "$enableDebugLogging" == true ]; then + if [ $# -eq 0 ]; then + echo "" >> $LOGFILE + else + echo $( date ) $@ >> $LOGFILE + fi + fi +} + +failover(){ + lockFile=/tmp/sdnc.failover.lock + # make sure that no failover is currently running + if [ -e ${lockFile} ] && kill -0 $(cat ${lockFile}) 2> /dev/null; then + debugLog "Currently running sdnc and dns failover" + return + fi + trap "rm -f ${lockFile}" INT TERM RETURN + echo $BASHPID > ${lockFile} + + # perform takeover + debugLog "Started executing sdnc.failover for $SITE_NAME" + takeoverResult=$( /app/bin/sdnc.failover ) + debugLog "Completed executing sdnc.failover. takeoverResult is: $takeoverResult" + if [ "success" = "$takeoverResult" ]; then + # update CoreDNS upon successful execution of sdnc.failover script + debugLog "Executing sdnc.dnsswitch" + /app/bin/sdnc.dnsswitch + rc=$? + debugLog "Completed executing sdnc.dnsswitch for $SITE_NAME. rc=$rc" + else + debugLog "Cluster takeover current status: $takeoverResult on $SITE_NAME." + rc=1 + fi + + if [ $rc -ne 0 ];then + takeoverResult="failure" + fi + + data="{\ +\"type\": \"failover\",\ +\"status\": \"$takeoverResult\",\ +\"site\": \"$SITE_NAME\",\ +\"deployment\": \"{{.Values.config.deployment}}\",\ +\"timestamp\": \"$(date '+%F %T')\"\ +}" + + # notifications are best-effort - ignore any failures + curl -H "Content-Type: application/json" -X POST --data "$data" http://$message_router/events/$topic >/dev/null 2>&1 + +} + +LOGFILE="/app/geo.log" +enableDebugLogging=true +message_router=message-router:3904 +topic={{.Values.config.messageRouterTopic}} +SITE_NAME="sdnc01" +if [ "$SDNC_IS_PRIMARY_CLUSTER" = "false" ];then + SITE_NAME="sdnc02" +fi + +debugLog +debugLog "Executing ensureSdncActive" + +# query SDN-C cluster status +debugLog "Started executing sdnc.cluster" +clusterStatus=$( /app/bin/sdnc.cluster ) +debugLog "Completed executing sdnc.cluster. Cluster status is: $clusterStatus" + +if [ "active" = "$clusterStatus" ]; then + # peform health-check + debugLog "Started excuting sdnc.monitor" + health=$( /app/bin/sdnc.monitor ) + debugLog "Completed executing sdnc.monitor. Cluster is: $health" + + if [ "healthy" = "$health" ]; then + # Cluster is ACTIVE and HEALTHY + exit 0 + fi + exit 1 + +elif [ "standby" = "$clusterStatus" ]; then + # Run failover in background process and allow PROM to continue + ( failover & ) + exit 0 +fi + +# Unknown cluster status +exit 1 diff --git a/kubernetes/sdnc/components/sdnc-prom/resources/bin/ensureSdncStandby.sh b/kubernetes/sdnc/components/sdnc-prom/resources/bin/ensureSdncStandby.sh new file mode 100755 index 0000000000..8dd84bd3ea --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/resources/bin/ensureSdncStandby.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# Copyright © 2018 Amdocs +# +# 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. + +debugLog(){ + if [ "$enableDebugLogging" == true ]; then + if [ $# -eq 0 ]; then + echo "" >> $LOGFILE + else + echo $( date ) $@ >> $LOGFILE + fi + fi +} + +LOGFILE="/app/geo.log" +enableDebugLogging=true + +debugLog +debugLog "Executing ensureSdncStandby" + +# query SDN-C cluster status +debugLog "Started executing sdnc.cluster" +clusterStatus=$( /app/bin/sdnc.cluster ) +debugLog "Completed executing sdnc.cluster. Cluster status is: $clusterStatus" + +if [ "active" = "$clusterStatus" ]; then + # assume transient error as other side transitions to ACTIVE + debugLog "Cluster status: $clusterStatus. exit 0" + exit 0 + +elif [ "standby" = "$clusterStatus" ]; then + # check that standby cluster is healthy + debugLog "Started executing sdnc.monitor. Cluster status is: $clusterStatus" + health=$( /app/bin/sdnc.monitor ) + debugLog "Completed executing sdnc.monitor. Cluster is: $health" + if [ "failure" = "$health" ];then + # Backup site is unhealthy - can't accept traffic! + exit 1 + fi + # Cluster is standing by + exit 0 +fi + +debugLog "Unknown cluster status: $clusterStatus" +# Unknown cluster status +exit 1 diff --git a/kubernetes/sdnc/components/sdnc-prom/resources/bin/prom.sh b/kubernetes/sdnc/components/sdnc-prom/resources/bin/prom.sh new file mode 100755 index 0000000000..c93ba24bd7 --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/resources/bin/prom.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Copyright © 2018 Amdocs +# +# 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. + +if [ "${SDNC_IS_PRIMARY_CLUSTER:-true}" = "true" ];then + id=sdnc01 +else + id=sdnc02 +fi + +# should PROM start as passive? +state=$( bin/sdnc.cluster ) +if [ "$state" == "standby" ]; then + echo "Starting PROM in passive mode" + passive="-p" +fi + +# start PROM as foreground process +java -jar prom.jar --id $id $passive --config config diff --git a/kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.cluster b/kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.cluster new file mode 100755 index 0000000000..bdfa1a440b --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.cluster @@ -0,0 +1,61 @@ +#!/bin/bash + +# Copyright © 2018 Amdocs +# +# 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. + +# query ODL cluster state +USERNAME="{{.Values.odl.jolokia.username}}" +PASSWORD="{{.Values.odl.jolokia.password}}" + +count=${SDNC_ODL_COUNT:-1} +memberStart=0 +if [ "${SDNC_IS_PRIMARY_CLUSTER:-true}" != "true" ];then + memberStart=$(( $memberStart + $count )) +fi + +for instance in $(seq $count);do + shard=member-$(( $memberStart + $instance ))-shard-default-config + mbean=Category=Shards,name=$shard,type=DistributedConfigDatastore + url=http://{{ include "common.release" . }}-sdnc-$(( $instance-1 )).sdnc-cluster.{{.Release.Namespace}}:8181/jolokia/read/org.opendaylight.controller:$mbean + + response=$( curl -s -u $USERNAME:$PASSWORD $url ) + rc=$? + if [ $rc -ne 0 ];then + # failed to contact SDN-C instance - try another + continue + fi + status=$( echo -E "$response" | jq -r ".status" ) + if [ "$status" != "200" ];then + # query failed, try another instance + continue + fi + + voting=$( echo -E "$response" | jq -r ".value.Voting" ) + case $voting in + true) + echo "active" + exit 0 + ;; + false) + echo "standby" + exit 0 + ;; + *) + echo "Error: Voting status could not be determined." + exit 1 + ;; + esac +done +echo "Error: Voting status could not be determined." +exit 1 diff --git a/kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.dnsswitch b/kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.dnsswitch new file mode 100755 index 0000000000..209352c4e3 --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.dnsswitch @@ -0,0 +1,22 @@ +#! /bin/bash + +# Copyright © 2018 Amdocs +# +# 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. + +#################################################################################################### +# sdncDnsSwitchWrapper.bash: Wrapper script to invoke SDNC DNS Switch for domain: sdnc.example.com # +#################################################################################################### +ssh -i {{.Values.coreDNS.sshKeyFile}} -o StrictHostKeyChecking=no {{.Values.coreDNS.sshUser}}@{{.Values.coreDNS.host}} "{{.Values.coreDNS.switchScript}} $SDNC_LOCAL_K8S_CLUSTER_MASTER {{.Values.config.deployment}}" + +exit $? diff --git a/kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.failover b/kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.failover new file mode 100755 index 0000000000..e78b7eeee3 --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.failover @@ -0,0 +1,86 @@ +#!/bin/bash + +# Copyright © 2018 Amdocs +# +# 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. + +LOGFILE="/app/geo.log" +enableDebugLogging=true +message_router=message-router:3904 +topic={{.Values.config.messageRouterTopic}} +KEYWORD_success="success" +KEYWORD_failure="failure" +SITE_NAME="sdnc01" +if [ "$SDNC_IS_PRIMARY_CLUSTER" = "false" ];then + SITE_NAME="sdnc02" +fi + +APP_BIN=/app/bin + +debugLog(){ + if [ "$enableDebugLogging" == true ]; then + if [ $# -eq 0 ]; then + echo "" >> $LOGFILE + else + echo $( date ) $@ >> $LOGFILE + fi + fi +} + +EXC_SIMPLE_FAILOVER=`${APP_BIN}/switchVoting.sh` + +if [ "$EXC_SIMPLE_FAILOVER" == "success" ]; then + debugLog "Simple failover success. SDNC failover completed." +else + # Simple failover failed. Trying catastrophic failover ... + debugLog "Simple failover failed. Trying catastrophic failover for $SITE_NAME ..." + + # Notify Dmaap before executing catastrophic failover, because all connections will be reset. + data="{\ + \"type\": \"Catastrophic failover\",\ + \"reason\": \"Simple failover failed\",\ + \"message_router\": \"$message_router\",\ + \"topic\": \"$topic\",\ + \"site\": \"$SITE_NAME\",\ + \"deployment\": \"{{.Values.config.deployment}}\",\ + \"timestamp\": \"$(date '+%F %T')\"\ + }" + + debugLog "$data" + + # notifications to Dmaap + curl -H "Content-Type: application/json" -X POST --data "$data" http://$message_router/events/$topic >/dev/null 2>&1 + + # We're going to kill prom, so we need to do dnsswitch now + + debugLog "Executing sdnc.dnsswitch" + + /app/bin/sdnc.dnsswitch > /dev/null 2>&1 + rc=$? + if [ $rc -ne 0 ];then + debugLog "sdnc.dnsswitch FAILED" + echo $KEYWORD_failure + exit 0 + fi + + # Now do catastrophic failure + + debugLog "Catastrophic failover in progress" + + ssh -o StrictHostKeyChecking=no -i /app/config/coredns/master.key root@$SDNC_LOCAL_K8S_CLUSTER_MASTER "su - ubuntu bash -c 'helm upgrade --set sdnc.config.geoEnabled=false dev local/onap --namespace onap; kubectl -n onap delete pods -l app=sdnc'" > /dev/null 2>&1 + + # Sleep here so prom can die without us passing control back to ensureSDNCActive + sleep 300 +fi + +echo $KEYWORD_success diff --git a/kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.monitor b/kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.monitor new file mode 100755 index 0000000000..0042ac368a --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/resources/bin/sdnc.monitor @@ -0,0 +1,125 @@ +#!/usr/bin/env python2 +# encoding: utf-8 + +# Copyright © 2018 Amdocs +# +# 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. + +import sys +import os +import json +import requests +from datetime import datetime + +consul_server = "consul-server:8500" +message_router = "message-router:3904" +topic = '{{.Values.config.messageRouterTopic}}' +log_file='/app/monitor.log' +status_file='/app/.health' +logEnabled=False + +siteName='sdnc01' +if os.environ.get('SDNC_IS_PRIMARY_CLUSTER', 'true') == 'false': + siteName='sdnc02' + +debug=False +if len(sys.argv) > 1 and sys.argv[1] == '--debug': + debug=True + +def get_state(healthcheck): + response = requests.get("http://" + consul_server + "/v1/health/checks/" + healthcheck) + if response.status_code != 200: + raise RuntimeError("HTTP " + str(response.status_code)) + data = response.json() + if len(data) == 0: + raise RuntimeError(healthcheck + " not found") + if len(data) > 1: + raise RuntimeError("Multiple states for " + healthcheck + " found") + + return data[0] + + +def log(message): + if logEnabled: + with open(log_file, 'a') as f: + f.write(str(datetime.now()) + " " + message + "\n") + +def healthcheck(checks, failFirst=True): + if len(checks) == 0: + return True + + for check in checks: + if type(check) is list: + passing = healthcheck(check, False) + else: + state = get_state(check) + status = state['Status'] + passing = status == "passing" or status == "warning" + log(check + " " + status) + if debug: + if status == "passing": + color = "\033[32m" # green + elif status == "warning": + color = "\033[33m" # yellow + else: + color = "\033[31m" # red + print check, color + status + "\033[0m" + if not passing: + print "\tCause:", state['Output'] + + + if passing: + if not failFirst: + # found a passing check so can stop here + return True + else: + if failFirst: + # found a failing check so can stop here + return False + + return failFirst + + +try: + with open("/app/config/healthchecks.json") as f: + checks = json.load(f) + + try: + with open(status_file) as f: + previous_result = f.read() + except IOError: + # file doesn't exist + previous_result = 'unknown' + + if healthcheck(checks): + result = "healthy" + else: + result = "unhealthy" + + print result + + # save current result to file + with open(status_file, 'w') as f: + f.write(result) + + if previous_result != 'unknown' and result != previous_result: + payload = { 'type' : 'health-change', 'status': result, 'site': siteName, 'deployment': '{{.Values.config.deployment}}', 'timestamp': str(datetime.now()) } + log("Posting event " + str(payload)) + try: + requests.post("http://" + message_router + "/events/" + topic, data=json.dumps(payload), headers={ 'Content-Type' : 'application/json' } ) + except Exception: + # events are best-effort + pass + +except Exception as e: + sys.exit(str(e)) diff --git a/kubernetes/sdnc/components/sdnc-prom/resources/bin/switchVoting.sh b/kubernetes/sdnc/components/sdnc-prom/resources/bin/switchVoting.sh new file mode 100755 index 0000000000..f13196e7e8 --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/resources/bin/switchVoting.sh @@ -0,0 +1,110 @@ +#/bin/sh + +# Copyright © 2018 Amdocs +# +# 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. + +set -e +primary=${SDNC_IS_PRIMARY_CLUSTER:-true} + +url=http://sdnc:8282/restconf/operations/cluster-admin:change-member-voting-states-for-all-shards +username="${ODL_USERNAME:-{{.Values.odl.restconf.username}}}" +password="${ODL_PASSWORD:-{{.Values.odl.restconf.password}}}" +LOGFILE="/app/geo.log" +enableDebugLogging=true + +debugLog(){ + if [ "$enableDebugLogging" == true ]; then + if [ $# -eq 0 ]; then + echo "" >> $LOGFILE + else + echo $( date ) $@ >> $LOGFILE + fi + fi +} + + +if [ "$primary" = "true" ]; then + votingState=' +{ + "input": { + "member-voting-state": [ + { + "member-name": "member-1", + "voting": true + }, + { + "member-name": "member-2", + "voting": true + }, + { + "member-name": "member-3", + "voting": true + }, + { + "member-name": "member-4", + "voting": false + }, + { + "member-name": "member-5", + "voting": false + }, + { + "member-name": "member-6", + "voting": false + } + ] + } +}' +else + votingState=' +{ + "input": { + "member-voting-state": [ + { + "member-name": "member-1", + "voting": false + }, + { + "member-name": "member-2", + "voting": false + }, + { + "member-name": "member-3", + "voting": false + }, + { + "member-name": "member-4", + "voting": true + }, + { + "member-name": "member-5", + "voting": true + }, + { + "member-name": "member-6", + "voting": true + } + ] + } +}' +fi + +status=$(curl -s -u $username:$password -o /dev/null -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d "$votingState" -w "%{http_code}\n" $url 2> /dev/null) +if [ $status -ne 200 ];then + debugLog "Switch voting failed. status: $status ,username: $username ,password: $password ,votingState: $votingState ,url:$url " + echo "failure" +else + echo "success" +fi + diff --git a/kubernetes/sdnc/components/sdnc-prom/resources/config/config.json b/kubernetes/sdnc/components/sdnc-prom/resources/config/config.json new file mode 100644 index 0000000000..54f95c140c --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/resources/config/config.json @@ -0,0 +1,19 @@ +{ + "app-name": "{{.Values.config.deployment}}", + "aid": "{{.Values.config.aid}}", + "namespace": "{{.Values.config.deployment}}", + "userid": "{{.Values.config.deployment}}", + "password": "{{.Values.config.password}}", + "prom-timeout": "{{.Values.config.promTimeout}}", + "core-monitor-sleep-time": "{{.Values.config.coreMonitorSleepTime}}", + "no-of-retry-attempts": "{{.Values.config.noOfRetryAttempts}}", + "restart-backoff-time": "{{.Values.config.restartBackoffTime}}", + "replica-id-list": [ "sdnc01", "sdnc02" ], + "ensure-active-sdnc01": "/app/bin/ensureSdncActive.sh", + "ensure-active-sdnc02": "/app/bin/ensureSdncActive.sh", + "ensure-passive-sdnc01": "/app/bin/ensureSdncStandby.sh", + "ensure-passive-sdnc02": "/app/bin/ensureSdncStandby.sh", + "music-connection-timeout-ms": "{{.Values.config.musicConnectionTimeoutMs}}", + "music-location": {{.Values.config.musicLocation|toJson}}, + "music-version": "2" +} diff --git a/kubernetes/sdnc/components/sdnc-prom/resources/config/healthchecks.json b/kubernetes/sdnc/components/sdnc-prom/resources/config/healthchecks.json new file mode 100644 index 0000000000..ea8ceccc0c --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/resources/config/healthchecks.json @@ -0,0 +1 @@ +{{.Values.config.healthChecks|toJson}} diff --git a/kubernetes/sdnc/components/sdnc-prom/templates/configmap.yaml b/kubernetes/sdnc/components/sdnc-prom/templates/configmap.yaml new file mode 100644 index 0000000000..927bb1e5be --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/templates/configmap.yaml @@ -0,0 +1,41 @@ +{{/* +# Copyright © 2018 Amdocs +# +# 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: {{ include "common.fullname" . }}-configmap + namespace: {{ include "common.namespace" . }} + labels: + app: {{ include "common.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ include "common.release" . }} + heritage: {{ .Release.Service }} +data: +{{ tpl (.Files.Glob "resources/config/*").AsConfig . | indent 2 }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "common.fullname" . }}-scripts + namespace: {{ include "common.namespace" . }} + labels: + app: {{ include "common.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ include "common.release" . }} + heritage: {{ .Release.Service }} +data: +{{ tpl (.Files.Glob "resources/bin/*").AsConfig . | indent 2 }} diff --git a/kubernetes/sdnc/components/sdnc-prom/templates/deployment.yaml b/kubernetes/sdnc/components/sdnc-prom/templates/deployment.yaml new file mode 100644 index 0000000000..7492b5501e --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/templates/deployment.yaml @@ -0,0 +1,101 @@ +{{/* +# Copyright © 2018 Amdocs +# +# 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: extensions/v1beta1 +kind: Deployment +metadata: + name: {{ include "common.fullname" . }} + namespace: {{ include "common.namespace" . }} + labels: + app: {{ include "common.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ include "common.release" . }} + heritage: {{ .Release.Service }} +spec: + replicas: 1 + template: + metadata: + labels: + app: {{ include "common.name" . }} + release: {{ include "common.release" . }} + spec: + initContainers: + - command: + - /root/ready.py + args: + - --container-name + - sdnc + - --container-name + - consul + env: + - name: NAMESPACE + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}" + imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }} + name: {{ include "common.name" . }}-readiness + containers: + - name: {{ include "common.name" . }} + image: "{{ include "common.repository" . }}/{{ .Values.image }}" + imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }} + envFrom: + - configMapRef: + name: {{ include "common.release" . }}-sdnc-env + workingDir: "/app" + command: [ "bin/prom.sh" ] + volumeMounts: + - name: localtime + mountPath: /etc/localtime + readOnly: true + - name: prom-config + mountPath: /app/config + - name: prom-scripts + mountPath: /app/bin + - name: core-dns-keyfile + mountPath: /app/config/coredns + + resources: +{{ include "common.resources" . | indent 12 }} + {{- if .Values.nodeSelector }} + nodeSelector: +{{ toYaml .Values.nodeSelector | indent 10 }} + {{- end -}} + {{- if .Values.affinity }} + affinity: +{{ toYaml .Values.affinity | indent 10 }} + {{- end }} + volumes: + - name: localtime + hostPath: + path: /etc/localtime + - name: prom-config + configMap: + name: {{ include "common.fullname" . }}-configmap + - name: prom-scripts + configMap: + name: {{ include "common.fullname" . }}-scripts + defaultMode: 0755 + - name: core-dns-keyfile + {{- if .Values.persistence.enabled }} + persistentVolumeClaim: + claimName: {{ include "common.fullname" . }} + {{- else }} + emptyDir: {} + {{- end }} + imagePullSecrets: + - name: {{ include "common.namespace" . }}-docker-registry-key" diff --git a/kubernetes/sdnc/components/sdnc-prom/templates/pv.yaml b/kubernetes/sdnc/components/sdnc-prom/templates/pv.yaml new file mode 100644 index 0000000000..bef2d6a85f --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/templates/pv.yaml @@ -0,0 +1,39 @@ +{{/* +# Copyright © 2019 Amdocs, Bell Canada, Orange +# +# 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. +*/}} +{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} +{{- if eq "True" (include "common.needPV" .) -}} +kind: PersistentVolume +apiVersion: v1 +metadata: + name: {{ include "common.fullname" . }}-data + namespace: {{ include "common.namespace" . }} + labels: + app: {{ include "common.fullname" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + release: "{{ include "common.release" . }}" + heritage: "{{ .Release.Service }}" + name: {{ include "common.fullname" . }} +spec: + capacity: + storage: {{ .Values.persistence.size}} + accessModes: + - {{ .Values.persistence.accessMode }} + persistentVolumeReclaimPolicy: {{ .Values.persistence.volumeReclaimPolicy }} + storageClassName: "{{ include "common.fullname" . }}-data" + hostPath: + path: {{ .Values.global.persistence.mountPath | default .Values.persistence.mountPath }}/{{ include "common.release" . }}/{{ .Values.persistence.mountSubPath }} +{{- end -}} +{{- end -}} diff --git a/kubernetes/sdnc/components/sdnc-prom/templates/pvc.yaml b/kubernetes/sdnc/components/sdnc-prom/templates/pvc.yaml new file mode 100644 index 0000000000..9933852f16 --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/templates/pvc.yaml @@ -0,0 +1,39 @@ +{{/* +# Copyright © 2019 Amdocs, Bell Canada, Orange +# +# 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. +*/}} +{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) -}} +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ include "common.fullname" . }} + namespace: {{ include "common.namespace" . }} + labels: + app: {{ include "common.name" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ include "common.release" . }}" + heritage: "{{ .Release.Service }}" + name: {{ include "common.fullname" . }} +{{- if .Values.persistence.annotations }} + annotations: +{{ toYaml .Values.persistence.annotations | indent 4 }} +{{- end }} +spec: + accessModes: + - {{ .Values.persistence.accessMode }} + resources: + requests: + storage: {{ .Values.persistence.size }} + storageClassName: {{ include "common.storageClass" . }} +{{- end }} diff --git a/kubernetes/sdnc/components/sdnc-prom/values.yaml b/kubernetes/sdnc/components/sdnc-prom/values.yaml new file mode 100644 index 0000000000..7216e81abf --- /dev/null +++ b/kubernetes/sdnc/components/sdnc-prom/values.yaml @@ -0,0 +1,102 @@ +# Copyright © 2018 Amdocs +# +# 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. + +################################################################# +# Global configuration defaults. +################################################################# +global: + nodePortPrefix: 302 + repository: nexus3.onap.org:10001 + readinessRepository: oomk8s + readinessImage: readiness-check:2.0.2 + loggingRepository: docker.elastic.co + loggingImage: beats/filebeat:5.5.0 + persistence: + mountPath: /dockerdata-nfs + +################################################################# +# Application configuration defaults. +################################################################# +# application image +repository: nexus3.onap.org:10001 +pullPolicy: Always +image: onap/music/prom:1.0.5 + +# application configuration +config: + # generate aid from onboarding your app in MUSIC + aid: "aid_for_your_app" + deployment: "test_onap" + password: "onap123" + musicLocation: + - "1.2.3.4" + - "1.2.3.5" + - "1.2.3.6" + musicConnectionTimeoutMs: "1000" + promTimeout: "35000" + coreMonitorSleepTime: "15000" + noOfRetryAttempts: "2" + restartBackoffTime: "15000" + healthChecks: + # All top-level checks must pass + - "Health Check: SDNC - SDN Host" + - "Health Check: SDNC" + - "Health Check: SDNC ODL Cluster" + - "Health Check: SDNC Portal" + # Within nested lists, only one must pass + - - "Health Check: SDNC-SDN-CTL-DB-01" + - "Health Check: SDNC-SDN-CTL-DB-02" + messageRouterTopic: "SDNC-GEO-REDUNDANCY" + +odl: + jolokia: + username: "admin" + password: "admin" + restconf: + username: "admin" + password: "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U" + +coreDNS: + host: 1.2.3.7 + sshUser: root + sshKeyFile: /app/config/coredns/coredns.key + switchScript: /home/ubuntu/dnsSwitch.bash + +nodeSelector: {} + +affinity: {} + +# probe configuration parameters +liveness: + initialDelaySeconds: 90 + periodSeconds: 90 + # necessary to disable liveness probe when setting breakpoints + # in debugger so K8s doesn't restart unresponsive container + enabled: true + +readiness: + initialDelaySeconds: 10 + periodSeconds: 10 + +persistence: + enabled: true + accessMode: ReadWriteOnce + size: 1Gi + mountPath: /dockerdata-nfs + mountSubPath: coredns + +ingress: + enabled: false + +resources: {} diff --git a/kubernetes/sdnc/sdnc-prom/Chart.yaml b/kubernetes/sdnc/sdnc-prom/Chart.yaml deleted file mode 100644 index 54fb337f04..0000000000 --- a/kubernetes/sdnc/sdnc-prom/Chart.yaml +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright © 2018 Amdocs -# -# 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 -description: ONAP SDNC Policy Driven Ownership Management -name: sdnc-prom -version: 6.0.0 diff --git a/kubernetes/sdnc/sdnc-prom/requirements.yaml b/kubernetes/sdnc/sdnc-prom/requirements.yaml deleted file mode 100644 index e4c7240290..0000000000 --- a/kubernetes/sdnc/sdnc-prom/requirements.yaml +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright © 2018 Amdocs -# -# 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. - -dependencies: - - name: common - version: ~6.x-0 - repository: '@local' diff --git a/kubernetes/sdnc/sdnc-prom/resources/bin/ensureSdncActive.sh b/kubernetes/sdnc/sdnc-prom/resources/bin/ensureSdncActive.sh deleted file mode 100755 index fb24653129..0000000000 --- a/kubernetes/sdnc/sdnc-prom/resources/bin/ensureSdncActive.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/bin/bash - -# Copyright © 2018 Amdocs -# -# 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. - -debugLog(){ - if [ "$enableDebugLogging" == true ]; then - if [ $# -eq 0 ]; then - echo "" >> $LOGFILE - else - echo $( date ) $@ >> $LOGFILE - fi - fi -} - -failover(){ - lockFile=/tmp/sdnc.failover.lock - # make sure that no failover is currently running - if [ -e ${lockFile} ] && kill -0 $(cat ${lockFile}) 2> /dev/null; then - debugLog "Currently running sdnc and dns failover" - return - fi - trap "rm -f ${lockFile}" INT TERM RETURN - echo $BASHPID > ${lockFile} - - # perform takeover - debugLog "Started executing sdnc.failover for $SITE_NAME" - takeoverResult=$( /app/bin/sdnc.failover ) - debugLog "Completed executing sdnc.failover. takeoverResult is: $takeoverResult" - if [ "success" = "$takeoverResult" ]; then - # update CoreDNS upon successful execution of sdnc.failover script - debugLog "Executing sdnc.dnsswitch" - /app/bin/sdnc.dnsswitch - rc=$? - debugLog "Completed executing sdnc.dnsswitch for $SITE_NAME. rc=$rc" - else - debugLog "Cluster takeover current status: $takeoverResult on $SITE_NAME." - rc=1 - fi - - if [ $rc -ne 0 ];then - takeoverResult="failure" - fi - - data="{\ -\"type\": \"failover\",\ -\"status\": \"$takeoverResult\",\ -\"site\": \"$SITE_NAME\",\ -\"deployment\": \"{{.Values.config.deployment}}\",\ -\"timestamp\": \"$(date '+%F %T')\"\ -}" - - # notifications are best-effort - ignore any failures - curl -H "Content-Type: application/json" -X POST --data "$data" http://$message_router/events/$topic >/dev/null 2>&1 - -} - -LOGFILE="/app/geo.log" -enableDebugLogging=true -message_router=message-router:3904 -topic={{.Values.config.messageRouterTopic}} -SITE_NAME="sdnc01" -if [ "$SDNC_IS_PRIMARY_CLUSTER" = "false" ];then - SITE_NAME="sdnc02" -fi - -debugLog -debugLog "Executing ensureSdncActive" - -# query SDN-C cluster status -debugLog "Started executing sdnc.cluster" -clusterStatus=$( /app/bin/sdnc.cluster ) -debugLog "Completed executing sdnc.cluster. Cluster status is: $clusterStatus" - -if [ "active" = "$clusterStatus" ]; then - # peform health-check - debugLog "Started excuting sdnc.monitor" - health=$( /app/bin/sdnc.monitor ) - debugLog "Completed executing sdnc.monitor. Cluster is: $health" - - if [ "healthy" = "$health" ]; then - # Cluster is ACTIVE and HEALTHY - exit 0 - fi - exit 1 - -elif [ "standby" = "$clusterStatus" ]; then - # Run failover in background process and allow PROM to continue - ( failover & ) - exit 0 -fi - -# Unknown cluster status -exit 1 diff --git a/kubernetes/sdnc/sdnc-prom/resources/bin/ensureSdncStandby.sh b/kubernetes/sdnc/sdnc-prom/resources/bin/ensureSdncStandby.sh deleted file mode 100755 index 8dd84bd3ea..0000000000 --- a/kubernetes/sdnc/sdnc-prom/resources/bin/ensureSdncStandby.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -# Copyright © 2018 Amdocs -# -# 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. - -debugLog(){ - if [ "$enableDebugLogging" == true ]; then - if [ $# -eq 0 ]; then - echo "" >> $LOGFILE - else - echo $( date ) $@ >> $LOGFILE - fi - fi -} - -LOGFILE="/app/geo.log" -enableDebugLogging=true - -debugLog -debugLog "Executing ensureSdncStandby" - -# query SDN-C cluster status -debugLog "Started executing sdnc.cluster" -clusterStatus=$( /app/bin/sdnc.cluster ) -debugLog "Completed executing sdnc.cluster. Cluster status is: $clusterStatus" - -if [ "active" = "$clusterStatus" ]; then - # assume transient error as other side transitions to ACTIVE - debugLog "Cluster status: $clusterStatus. exit 0" - exit 0 - -elif [ "standby" = "$clusterStatus" ]; then - # check that standby cluster is healthy - debugLog "Started executing sdnc.monitor. Cluster status is: $clusterStatus" - health=$( /app/bin/sdnc.monitor ) - debugLog "Completed executing sdnc.monitor. Cluster is: $health" - if [ "failure" = "$health" ];then - # Backup site is unhealthy - can't accept traffic! - exit 1 - fi - # Cluster is standing by - exit 0 -fi - -debugLog "Unknown cluster status: $clusterStatus" -# Unknown cluster status -exit 1 diff --git a/kubernetes/sdnc/sdnc-prom/resources/bin/prom.sh b/kubernetes/sdnc/sdnc-prom/resources/bin/prom.sh deleted file mode 100755 index c93ba24bd7..0000000000 --- a/kubernetes/sdnc/sdnc-prom/resources/bin/prom.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -# Copyright © 2018 Amdocs -# -# 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. - -if [ "${SDNC_IS_PRIMARY_CLUSTER:-true}" = "true" ];then - id=sdnc01 -else - id=sdnc02 -fi - -# should PROM start as passive? -state=$( bin/sdnc.cluster ) -if [ "$state" == "standby" ]; then - echo "Starting PROM in passive mode" - passive="-p" -fi - -# start PROM as foreground process -java -jar prom.jar --id $id $passive --config config diff --git a/kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.cluster b/kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.cluster deleted file mode 100755 index bdfa1a440b..0000000000 --- a/kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.cluster +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -# Copyright © 2018 Amdocs -# -# 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. - -# query ODL cluster state -USERNAME="{{.Values.odl.jolokia.username}}" -PASSWORD="{{.Values.odl.jolokia.password}}" - -count=${SDNC_ODL_COUNT:-1} -memberStart=0 -if [ "${SDNC_IS_PRIMARY_CLUSTER:-true}" != "true" ];then - memberStart=$(( $memberStart + $count )) -fi - -for instance in $(seq $count);do - shard=member-$(( $memberStart + $instance ))-shard-default-config - mbean=Category=Shards,name=$shard,type=DistributedConfigDatastore - url=http://{{ include "common.release" . }}-sdnc-$(( $instance-1 )).sdnc-cluster.{{.Release.Namespace}}:8181/jolokia/read/org.opendaylight.controller:$mbean - - response=$( curl -s -u $USERNAME:$PASSWORD $url ) - rc=$? - if [ $rc -ne 0 ];then - # failed to contact SDN-C instance - try another - continue - fi - status=$( echo -E "$response" | jq -r ".status" ) - if [ "$status" != "200" ];then - # query failed, try another instance - continue - fi - - voting=$( echo -E "$response" | jq -r ".value.Voting" ) - case $voting in - true) - echo "active" - exit 0 - ;; - false) - echo "standby" - exit 0 - ;; - *) - echo "Error: Voting status could not be determined." - exit 1 - ;; - esac -done -echo "Error: Voting status could not be determined." -exit 1 diff --git a/kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.dnsswitch b/kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.dnsswitch deleted file mode 100755 index 209352c4e3..0000000000 --- a/kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.dnsswitch +++ /dev/null @@ -1,22 +0,0 @@ -#! /bin/bash - -# Copyright © 2018 Amdocs -# -# 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. - -#################################################################################################### -# sdncDnsSwitchWrapper.bash: Wrapper script to invoke SDNC DNS Switch for domain: sdnc.example.com # -#################################################################################################### -ssh -i {{.Values.coreDNS.sshKeyFile}} -o StrictHostKeyChecking=no {{.Values.coreDNS.sshUser}}@{{.Values.coreDNS.host}} "{{.Values.coreDNS.switchScript}} $SDNC_LOCAL_K8S_CLUSTER_MASTER {{.Values.config.deployment}}" - -exit $? diff --git a/kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.failover b/kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.failover deleted file mode 100755 index e78b7eeee3..0000000000 --- a/kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.failover +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/bash - -# Copyright © 2018 Amdocs -# -# 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. - -LOGFILE="/app/geo.log" -enableDebugLogging=true -message_router=message-router:3904 -topic={{.Values.config.messageRouterTopic}} -KEYWORD_success="success" -KEYWORD_failure="failure" -SITE_NAME="sdnc01" -if [ "$SDNC_IS_PRIMARY_CLUSTER" = "false" ];then - SITE_NAME="sdnc02" -fi - -APP_BIN=/app/bin - -debugLog(){ - if [ "$enableDebugLogging" == true ]; then - if [ $# -eq 0 ]; then - echo "" >> $LOGFILE - else - echo $( date ) $@ >> $LOGFILE - fi - fi -} - -EXC_SIMPLE_FAILOVER=`${APP_BIN}/switchVoting.sh` - -if [ "$EXC_SIMPLE_FAILOVER" == "success" ]; then - debugLog "Simple failover success. SDNC failover completed." -else - # Simple failover failed. Trying catastrophic failover ... - debugLog "Simple failover failed. Trying catastrophic failover for $SITE_NAME ..." - - # Notify Dmaap before executing catastrophic failover, because all connections will be reset. - data="{\ - \"type\": \"Catastrophic failover\",\ - \"reason\": \"Simple failover failed\",\ - \"message_router\": \"$message_router\",\ - \"topic\": \"$topic\",\ - \"site\": \"$SITE_NAME\",\ - \"deployment\": \"{{.Values.config.deployment}}\",\ - \"timestamp\": \"$(date '+%F %T')\"\ - }" - - debugLog "$data" - - # notifications to Dmaap - curl -H "Content-Type: application/json" -X POST --data "$data" http://$message_router/events/$topic >/dev/null 2>&1 - - # We're going to kill prom, so we need to do dnsswitch now - - debugLog "Executing sdnc.dnsswitch" - - /app/bin/sdnc.dnsswitch > /dev/null 2>&1 - rc=$? - if [ $rc -ne 0 ];then - debugLog "sdnc.dnsswitch FAILED" - echo $KEYWORD_failure - exit 0 - fi - - # Now do catastrophic failure - - debugLog "Catastrophic failover in progress" - - ssh -o StrictHostKeyChecking=no -i /app/config/coredns/master.key root@$SDNC_LOCAL_K8S_CLUSTER_MASTER "su - ubuntu bash -c 'helm upgrade --set sdnc.config.geoEnabled=false dev local/onap --namespace onap; kubectl -n onap delete pods -l app=sdnc'" > /dev/null 2>&1 - - # Sleep here so prom can die without us passing control back to ensureSDNCActive - sleep 300 -fi - -echo $KEYWORD_success diff --git a/kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.monitor b/kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.monitor deleted file mode 100755 index 0042ac368a..0000000000 --- a/kubernetes/sdnc/sdnc-prom/resources/bin/sdnc.monitor +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/env python2 -# encoding: utf-8 - -# Copyright © 2018 Amdocs -# -# 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. - -import sys -import os -import json -import requests -from datetime import datetime - -consul_server = "consul-server:8500" -message_router = "message-router:3904" -topic = '{{.Values.config.messageRouterTopic}}' -log_file='/app/monitor.log' -status_file='/app/.health' -logEnabled=False - -siteName='sdnc01' -if os.environ.get('SDNC_IS_PRIMARY_CLUSTER', 'true') == 'false': - siteName='sdnc02' - -debug=False -if len(sys.argv) > 1 and sys.argv[1] == '--debug': - debug=True - -def get_state(healthcheck): - response = requests.get("http://" + consul_server + "/v1/health/checks/" + healthcheck) - if response.status_code != 200: - raise RuntimeError("HTTP " + str(response.status_code)) - data = response.json() - if len(data) == 0: - raise RuntimeError(healthcheck + " not found") - if len(data) > 1: - raise RuntimeError("Multiple states for " + healthcheck + " found") - - return data[0] - - -def log(message): - if logEnabled: - with open(log_file, 'a') as f: - f.write(str(datetime.now()) + " " + message + "\n") - -def healthcheck(checks, failFirst=True): - if len(checks) == 0: - return True - - for check in checks: - if type(check) is list: - passing = healthcheck(check, False) - else: - state = get_state(check) - status = state['Status'] - passing = status == "passing" or status == "warning" - log(check + " " + status) - if debug: - if status == "passing": - color = "\033[32m" # green - elif status == "warning": - color = "\033[33m" # yellow - else: - color = "\033[31m" # red - print check, color + status + "\033[0m" - if not passing: - print "\tCause:", state['Output'] - - - if passing: - if not failFirst: - # found a passing check so can stop here - return True - else: - if failFirst: - # found a failing check so can stop here - return False - - return failFirst - - -try: - with open("/app/config/healthchecks.json") as f: - checks = json.load(f) - - try: - with open(status_file) as f: - previous_result = f.read() - except IOError: - # file doesn't exist - previous_result = 'unknown' - - if healthcheck(checks): - result = "healthy" - else: - result = "unhealthy" - - print result - - # save current result to file - with open(status_file, 'w') as f: - f.write(result) - - if previous_result != 'unknown' and result != previous_result: - payload = { 'type' : 'health-change', 'status': result, 'site': siteName, 'deployment': '{{.Values.config.deployment}}', 'timestamp': str(datetime.now()) } - log("Posting event " + str(payload)) - try: - requests.post("http://" + message_router + "/events/" + topic, data=json.dumps(payload), headers={ 'Content-Type' : 'application/json' } ) - except Exception: - # events are best-effort - pass - -except Exception as e: - sys.exit(str(e)) diff --git a/kubernetes/sdnc/sdnc-prom/resources/bin/switchVoting.sh b/kubernetes/sdnc/sdnc-prom/resources/bin/switchVoting.sh deleted file mode 100755 index f13196e7e8..0000000000 --- a/kubernetes/sdnc/sdnc-prom/resources/bin/switchVoting.sh +++ /dev/null @@ -1,110 +0,0 @@ -#/bin/sh - -# Copyright © 2018 Amdocs -# -# 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. - -set -e -primary=${SDNC_IS_PRIMARY_CLUSTER:-true} - -url=http://sdnc:8282/restconf/operations/cluster-admin:change-member-voting-states-for-all-shards -username="${ODL_USERNAME:-{{.Values.odl.restconf.username}}}" -password="${ODL_PASSWORD:-{{.Values.odl.restconf.password}}}" -LOGFILE="/app/geo.log" -enableDebugLogging=true - -debugLog(){ - if [ "$enableDebugLogging" == true ]; then - if [ $# -eq 0 ]; then - echo "" >> $LOGFILE - else - echo $( date ) $@ >> $LOGFILE - fi - fi -} - - -if [ "$primary" = "true" ]; then - votingState=' -{ - "input": { - "member-voting-state": [ - { - "member-name": "member-1", - "voting": true - }, - { - "member-name": "member-2", - "voting": true - }, - { - "member-name": "member-3", - "voting": true - }, - { - "member-name": "member-4", - "voting": false - }, - { - "member-name": "member-5", - "voting": false - }, - { - "member-name": "member-6", - "voting": false - } - ] - } -}' -else - votingState=' -{ - "input": { - "member-voting-state": [ - { - "member-name": "member-1", - "voting": false - }, - { - "member-name": "member-2", - "voting": false - }, - { - "member-name": "member-3", - "voting": false - }, - { - "member-name": "member-4", - "voting": true - }, - { - "member-name": "member-5", - "voting": true - }, - { - "member-name": "member-6", - "voting": true - } - ] - } -}' -fi - -status=$(curl -s -u $username:$password -o /dev/null -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d "$votingState" -w "%{http_code}\n" $url 2> /dev/null) -if [ $status -ne 200 ];then - debugLog "Switch voting failed. status: $status ,username: $username ,password: $password ,votingState: $votingState ,url:$url " - echo "failure" -else - echo "success" -fi - diff --git a/kubernetes/sdnc/sdnc-prom/resources/config/config.json b/kubernetes/sdnc/sdnc-prom/resources/config/config.json deleted file mode 100644 index 54f95c140c..0000000000 --- a/kubernetes/sdnc/sdnc-prom/resources/config/config.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "app-name": "{{.Values.config.deployment}}", - "aid": "{{.Values.config.aid}}", - "namespace": "{{.Values.config.deployment}}", - "userid": "{{.Values.config.deployment}}", - "password": "{{.Values.config.password}}", - "prom-timeout": "{{.Values.config.promTimeout}}", - "core-monitor-sleep-time": "{{.Values.config.coreMonitorSleepTime}}", - "no-of-retry-attempts": "{{.Values.config.noOfRetryAttempts}}", - "restart-backoff-time": "{{.Values.config.restartBackoffTime}}", - "replica-id-list": [ "sdnc01", "sdnc02" ], - "ensure-active-sdnc01": "/app/bin/ensureSdncActive.sh", - "ensure-active-sdnc02": "/app/bin/ensureSdncActive.sh", - "ensure-passive-sdnc01": "/app/bin/ensureSdncStandby.sh", - "ensure-passive-sdnc02": "/app/bin/ensureSdncStandby.sh", - "music-connection-timeout-ms": "{{.Values.config.musicConnectionTimeoutMs}}", - "music-location": {{.Values.config.musicLocation|toJson}}, - "music-version": "2" -} diff --git a/kubernetes/sdnc/sdnc-prom/resources/config/healthchecks.json b/kubernetes/sdnc/sdnc-prom/resources/config/healthchecks.json deleted file mode 100644 index ea8ceccc0c..0000000000 --- a/kubernetes/sdnc/sdnc-prom/resources/config/healthchecks.json +++ /dev/null @@ -1 +0,0 @@ -{{.Values.config.healthChecks|toJson}} diff --git a/kubernetes/sdnc/sdnc-prom/templates/configmap.yaml b/kubernetes/sdnc/sdnc-prom/templates/configmap.yaml deleted file mode 100644 index 927bb1e5be..0000000000 --- a/kubernetes/sdnc/sdnc-prom/templates/configmap.yaml +++ /dev/null @@ -1,41 +0,0 @@ -{{/* -# Copyright © 2018 Amdocs -# -# 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: {{ include "common.fullname" . }}-configmap - namespace: {{ include "common.namespace" . }} - labels: - app: {{ include "common.name" . }} - chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} - release: {{ include "common.release" . }} - heritage: {{ .Release.Service }} -data: -{{ tpl (.Files.Glob "resources/config/*").AsConfig . | indent 2 }} ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ include "common.fullname" . }}-scripts - namespace: {{ include "common.namespace" . }} - labels: - app: {{ include "common.name" . }} - chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} - release: {{ include "common.release" . }} - heritage: {{ .Release.Service }} -data: -{{ tpl (.Files.Glob "resources/bin/*").AsConfig . | indent 2 }} diff --git a/kubernetes/sdnc/sdnc-prom/templates/deployment.yaml b/kubernetes/sdnc/sdnc-prom/templates/deployment.yaml deleted file mode 100644 index 7492b5501e..0000000000 --- a/kubernetes/sdnc/sdnc-prom/templates/deployment.yaml +++ /dev/null @@ -1,101 +0,0 @@ -{{/* -# Copyright © 2018 Amdocs -# -# 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: extensions/v1beta1 -kind: Deployment -metadata: - name: {{ include "common.fullname" . }} - namespace: {{ include "common.namespace" . }} - labels: - app: {{ include "common.name" . }} - chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} - release: {{ include "common.release" . }} - heritage: {{ .Release.Service }} -spec: - replicas: 1 - template: - metadata: - labels: - app: {{ include "common.name" . }} - release: {{ include "common.release" . }} - spec: - initContainers: - - command: - - /root/ready.py - args: - - --container-name - - sdnc - - --container-name - - consul - env: - - name: NAMESPACE - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: metadata.namespace - image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}" - imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }} - name: {{ include "common.name" . }}-readiness - containers: - - name: {{ include "common.name" . }} - image: "{{ include "common.repository" . }}/{{ .Values.image }}" - imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }} - envFrom: - - configMapRef: - name: {{ include "common.release" . }}-sdnc-env - workingDir: "/app" - command: [ "bin/prom.sh" ] - volumeMounts: - - name: localtime - mountPath: /etc/localtime - readOnly: true - - name: prom-config - mountPath: /app/config - - name: prom-scripts - mountPath: /app/bin - - name: core-dns-keyfile - mountPath: /app/config/coredns - - resources: -{{ include "common.resources" . | indent 12 }} - {{- if .Values.nodeSelector }} - nodeSelector: -{{ toYaml .Values.nodeSelector | indent 10 }} - {{- end -}} - {{- if .Values.affinity }} - affinity: -{{ toYaml .Values.affinity | indent 10 }} - {{- end }} - volumes: - - name: localtime - hostPath: - path: /etc/localtime - - name: prom-config - configMap: - name: {{ include "common.fullname" . }}-configmap - - name: prom-scripts - configMap: - name: {{ include "common.fullname" . }}-scripts - defaultMode: 0755 - - name: core-dns-keyfile - {{- if .Values.persistence.enabled }} - persistentVolumeClaim: - claimName: {{ include "common.fullname" . }} - {{- else }} - emptyDir: {} - {{- end }} - imagePullSecrets: - - name: {{ include "common.namespace" . }}-docker-registry-key" diff --git a/kubernetes/sdnc/sdnc-prom/templates/pv.yaml b/kubernetes/sdnc/sdnc-prom/templates/pv.yaml deleted file mode 100644 index bef2d6a85f..0000000000 --- a/kubernetes/sdnc/sdnc-prom/templates/pv.yaml +++ /dev/null @@ -1,39 +0,0 @@ -{{/* -# Copyright © 2019 Amdocs, Bell Canada, Orange -# -# 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. -*/}} -{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} -{{- if eq "True" (include "common.needPV" .) -}} -kind: PersistentVolume -apiVersion: v1 -metadata: - name: {{ include "common.fullname" . }}-data - namespace: {{ include "common.namespace" . }} - labels: - app: {{ include "common.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - release: "{{ include "common.release" . }}" - heritage: "{{ .Release.Service }}" - name: {{ include "common.fullname" . }} -spec: - capacity: - storage: {{ .Values.persistence.size}} - accessModes: - - {{ .Values.persistence.accessMode }} - persistentVolumeReclaimPolicy: {{ .Values.persistence.volumeReclaimPolicy }} - storageClassName: "{{ include "common.fullname" . }}-data" - hostPath: - path: {{ .Values.global.persistence.mountPath | default .Values.persistence.mountPath }}/{{ include "common.release" . }}/{{ .Values.persistence.mountSubPath }} -{{- end -}} -{{- end -}} diff --git a/kubernetes/sdnc/sdnc-prom/templates/pvc.yaml b/kubernetes/sdnc/sdnc-prom/templates/pvc.yaml deleted file mode 100644 index 9933852f16..0000000000 --- a/kubernetes/sdnc/sdnc-prom/templates/pvc.yaml +++ /dev/null @@ -1,39 +0,0 @@ -{{/* -# Copyright © 2019 Amdocs, Bell Canada, Orange -# -# 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. -*/}} -{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) -}} -kind: PersistentVolumeClaim -apiVersion: v1 -metadata: - name: {{ include "common.fullname" . }} - namespace: {{ include "common.namespace" . }} - labels: - app: {{ include "common.name" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ include "common.release" . }}" - heritage: "{{ .Release.Service }}" - name: {{ include "common.fullname" . }} -{{- if .Values.persistence.annotations }} - annotations: -{{ toYaml .Values.persistence.annotations | indent 4 }} -{{- end }} -spec: - accessModes: - - {{ .Values.persistence.accessMode }} - resources: - requests: - storage: {{ .Values.persistence.size }} - storageClassName: {{ include "common.storageClass" . }} -{{- end }} diff --git a/kubernetes/sdnc/sdnc-prom/values.yaml b/kubernetes/sdnc/sdnc-prom/values.yaml deleted file mode 100644 index 7216e81abf..0000000000 --- a/kubernetes/sdnc/sdnc-prom/values.yaml +++ /dev/null @@ -1,102 +0,0 @@ -# Copyright © 2018 Amdocs -# -# 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. - -################################################################# -# Global configuration defaults. -################################################################# -global: - nodePortPrefix: 302 - repository: nexus3.onap.org:10001 - readinessRepository: oomk8s - readinessImage: readiness-check:2.0.2 - loggingRepository: docker.elastic.co - loggingImage: beats/filebeat:5.5.0 - persistence: - mountPath: /dockerdata-nfs - -################################################################# -# Application configuration defaults. -################################################################# -# application image -repository: nexus3.onap.org:10001 -pullPolicy: Always -image: onap/music/prom:1.0.5 - -# application configuration -config: - # generate aid from onboarding your app in MUSIC - aid: "aid_for_your_app" - deployment: "test_onap" - password: "onap123" - musicLocation: - - "1.2.3.4" - - "1.2.3.5" - - "1.2.3.6" - musicConnectionTimeoutMs: "1000" - promTimeout: "35000" - coreMonitorSleepTime: "15000" - noOfRetryAttempts: "2" - restartBackoffTime: "15000" - healthChecks: - # All top-level checks must pass - - "Health Check: SDNC - SDN Host" - - "Health Check: SDNC" - - "Health Check: SDNC ODL Cluster" - - "Health Check: SDNC Portal" - # Within nested lists, only one must pass - - - "Health Check: SDNC-SDN-CTL-DB-01" - - "Health Check: SDNC-SDN-CTL-DB-02" - messageRouterTopic: "SDNC-GEO-REDUNDANCY" - -odl: - jolokia: - username: "admin" - password: "admin" - restconf: - username: "admin" - password: "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U" - -coreDNS: - host: 1.2.3.7 - sshUser: root - sshKeyFile: /app/config/coredns/coredns.key - switchScript: /home/ubuntu/dnsSwitch.bash - -nodeSelector: {} - -affinity: {} - -# probe configuration parameters -liveness: - initialDelaySeconds: 90 - periodSeconds: 90 - # necessary to disable liveness probe when setting breakpoints - # in debugger so K8s doesn't restart unresponsive container - enabled: true - -readiness: - initialDelaySeconds: 10 - periodSeconds: 10 - -persistence: - enabled: true - accessMode: ReadWriteOnce - size: 1Gi - mountPath: /dockerdata-nfs - mountSubPath: coredns - -ingress: - enabled: false - -resources: {} -- cgit 1.2.3-korg