From 5caf1654683a567da7e4158e4e7e108dd2232a13 Mon Sep 17 00:00:00 2001 From: Jack Lucas Date: Fri, 8 Feb 2019 14:21:58 -0500 Subject: Move ph and dh to Helm -- Helm charts for ph and dh -- New container to do Consul k-v storage and service reg -- Bootstrap container no longer deploys ph and dh -- Healthcheck looks for ph and dh as Helm deployments -- Updated/added licensing information Issue-ID: DCAEGEN2-1091 Issue-ID: DCAEGEN2-1092 Change-Id: I5340bee6fba1340d4c05b0f37ddfb539c543469e Signed-off-by: Jack Lucas --- consul-loader-container/Dockerfile | 23 ++++ consul-loader-container/README.md | 11 ++ consul-loader-container/consul_store.sh | 94 ++++++++++++++++ consul-loader-container/pom.xml | 172 +++++++++++++++++++++++++++++ healthcheck-container/healthcheck.js | 6 +- healthcheck-container/package.json | 2 +- healthcheck-container/pom.xml | 4 +- k8s-bootstrap-container/bootstrap.sh | 20 +--- k8s-bootstrap-container/load-blueprints.sh | 17 ++- k8s-bootstrap-container/pom.xml | 4 +- pom.xml | 7 +- 11 files changed, 329 insertions(+), 31 deletions(-) create mode 100644 consul-loader-container/Dockerfile create mode 100644 consul-loader-container/README.md create mode 100755 consul-loader-container/consul_store.sh create mode 100644 consul-loader-container/pom.xml diff --git a/consul-loader-container/Dockerfile b/consul-loader-container/Dockerfile new file mode 100644 index 0000000..868b41f --- /dev/null +++ b/consul-loader-container/Dockerfile @@ -0,0 +1,23 @@ +# ============LICENSE_START======================================================= +# org.onap.dcae +# ================================================================================ +# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +# +FROM ubuntu:16.04 +RUN apt-get update && apt-get install -y curl && mkdir -p /opt/app +COPY *.sh /opt/app/ +WORKDIR /opt/app +ENTRYPOINT ["/opt/app/consul_store.sh"] diff --git a/consul-loader-container/README.md b/consul-loader-container/README.md new file mode 100644 index 0000000..f3869d7 --- /dev/null +++ b/consul-loader-container/README.md @@ -0,0 +1,11 @@ +# DCAE Consul Loader Container + +The Dockerfile in this directory builds an image that can be used to spin up a container (typical a Kubernetes init container) that can load +service registrations and key-value pairs into a Consul instance. This capability supports moving certain DCAE platform components from +deployment using a Cloudify blueprint and the ONAP Kubernetes plugin to a Helm-based deployment. An init container can do the Consul +setup previously handled by the ONAP Kubernetes plugin and the ONAP DCAE bootstrap script. + +The entrypoint for the container is the script `consul_store.sh`. See the documentation for `consul_store.sh` to see how to provide arguments to the script +as well as how to use environment variables to set the Consul API protocol, host, and port. + +Note that the container runs the script to completion. It is not intended to be a long-running service. \ No newline at end of file diff --git a/consul-loader-container/consul_store.sh b/consul-loader-container/consul_store.sh new file mode 100755 index 0000000..4e64fc3 --- /dev/null +++ b/consul-loader-container/consul_store.sh @@ -0,0 +1,94 @@ +#!/bin/bash +# ================================================================================ +# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= + +# Push service registrations and key-value pairs to consul +# +# Environment variables control the consul address used: +# -- CONSUL_PROTO: The protocol (http or https) used to access consul. DEFAULT: http +# -- CONSUL_HOST: The Consul host address. DEFAULT: consul +# -- CONSUL_PORT: The Consul API port. DEFAULT: 8500 +# +# Command line options +# --service name|address|port : Register a service with name 'name', address 'address', and port 'port'. +# --key keyname|filepath: Register a key-value pair with key 'keyname' and the contents of a file at 'filepath' as its value +# A command can include multiple instances of each option. + +CONSUL_ADDR=${CONSUL_PROTO:-http}://${CONSUL_HOST:-consul}:${CONSUL_PORT:-8500} +KV_URL=${CONSUL_ADDR}/v1/kv +REG_URL=${CONSUL_ADDR}/v1/catalog/register + +# Register a service into Consul so that it can be discovered via the Consul service discovery API +# $1: Name under which service is registered +# $2: Address (typically DNS name, but can be IP) of the service +# $3: Port used by the service +function register_service { + service="{\"Node\": \"dcae\", \"Address\": \"$2\", \"Service\": {\"Service\": \"$1\", \"Address\": \"$2\", \"Port\": $3}}" + echo $service + curl -v -X PUT --data-binary "${service}" -H 'Content-Type: application/json' $REG_URL +} + +# Store the contents of a file into Consul KV store +# $1: Key under which content is stored +# $2: Path to file whose content will be the value associated with the key +function put_key { + curl -v -X PUT --data-binary @$2 -H 'Content-Type: application/json' ${KV_URL}/$1 +} + +set -x + +# Check Consul readiness +# The readiness container waits for a "consul-server" container to be ready, +# but this isn't always enough. We need the Consul API to be up and for +# the cluster to be formed, otherwise our Consul accesses might fail. +# Wait for Consul API to come up +until curl ${CONSUL_ADDR}/v1/agent/services +do + echo Waiting for Consul API + sleep 60 +done +# Wait for a leader to be elected +until [[ "$(curl -Ss {$CONSUL_ADDR}/v1/status/leader)" != '""' ]] +do + echo Waiting for leader + sleep 30 +done + +while (( "$#" )) +do + case $1 in + + "--service") + # ${2//|/ } turns all of the | characters in argument 2 into spaces + # () uses the space delimited string to initialize an array + # this turns an argument like inventory-api|inventory.onap|8080 into + # a three-element array with elements "inventory-api", "inventory.onap", and "8080" + s=(${2//|/ }) + register_service ${s[@]} + shift 2; + ;; + "--key") + # See above for explanation of (${2//|/ }) + kv=(${2//|/ }) + put_key ${kv[@]} + shift 2; + ;; + *) + echo "ignoring $1" + shift + ;; + esac +done diff --git a/consul-loader-container/pom.xml b/consul-loader-container/pom.xml new file mode 100644 index 0000000..dd68443 --- /dev/null +++ b/consul-loader-container/pom.xml @@ -0,0 +1,172 @@ + + + + 4.0.0 + + org.onap.dcaegen2.deployments + deployments + 1.2.0-SNAPSHOT + + org.onap.dcaegen2.deployments + consul-loader-container + dcaegen2-deployments-consul-loader-container + 1.0.0 + http://maven.apache.org + + UTF-8 + true + . + + + + + py + Python + **/*.py + + + + + ${project.artifactId}-${project.version} + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + clean phase script + clean + + exec + + + + ${project.artifactId} + clean + + + + + generate-sources script + generate-sources + + exec + + + + ${project.artifactId} + generate-sources + + + + + compile script + compile + + exec + + + + ${project.artifactId} + compile + + + + + package script + package + + exec + + + + ${project.artifactId} + package + + + + + test script + test + + exec + + + + ${project.artifactId} + test + + + + + install script + install + + exec + + + + ${project.artifactId} + install + + + + + deploy script + deploy + + exec + + + + ${project.artifactId} + deploy + + + + + + + + diff --git a/healthcheck-container/healthcheck.js b/healthcheck-container/healthcheck.js index 1d6fccb..c4f2dd7 100644 --- a/healthcheck-container/healthcheck.js +++ b/healthcheck-container/healthcheck.js @@ -29,14 +29,14 @@ const helmDeps = 'dcae-cloudify-manager', 'dcae-config-binding-service', 'dcae-inventory-api', - 'dcae-servicechange-handler' + 'dcae-servicechange-handler', + 'dcae-deployment-handler', + 'dcae-policy-handler' ]; // List of deployments expected to be created by CM at boot time const bootDeps = [ - 'dep-deployment-handler', - 'dep-policy-handler', 'dep-dcae-ves-collector', 'dep-dcae-tca-analytics', 'dep-dcae-prh', diff --git a/healthcheck-container/package.json b/healthcheck-container/package.json index 31f1493..cc20578 100644 --- a/healthcheck-container/package.json +++ b/healthcheck-container/package.json @@ -1,7 +1,7 @@ { "name": "k8s-healthcheck", "description": "DCAE healthcheck server", - "version": "1.2.2", + "version": "1.2.4", "main": "healthcheck.js", "author": "author", "license": "(Apache-2.0)" diff --git a/healthcheck-container/pom.xml b/healthcheck-container/pom.xml index e728a66..abc7965 100644 --- a/healthcheck-container/pom.xml +++ b/healthcheck-container/pom.xml @@ -1,7 +1,7 @@ - org.apache.maven.plugins @@ -128,7 +129,7 @@ limitations under the License. - org.apache.maven.plugins -- cgit 1.2.3-korg