summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVijay Venkatesh Kumar <vv770d@att.com>2021-02-08 16:19:30 +0000
committerGerrit Code Review <gerrit@onap.org>2021-02-08 16:19:30 +0000
commitf706e2f0f401c26a507f38b13c6f6bac7f6594bb (patch)
tree379bf9d05f1bd2b2d6564cb2f620443db04b895b
parentd6f51329c094b7264a9aebdbb76496b40966ce6b (diff)
parentb65d4c1fc374af0f4b3bb5ea55641efd88f65ab3 (diff)
Merge "Add yaml load and key delete to consul-loader-container"4.2.0-cm-container1.1.0-consul-loader-container
-rw-r--r--consul-loader-container/Changelog.md15
-rw-r--r--consul-loader-container/Dockerfile13
-rwxr-xr-xconsul-loader-container/consul_store.sh22
-rw-r--r--consul-loader-container/pom.xml3
-rwxr-xr-xconsul-loader-container/yaml2json.py33
5 files changed, 82 insertions, 4 deletions
diff --git a/consul-loader-container/Changelog.md b/consul-loader-container/Changelog.md
new file mode 100644
index 0000000..88d4818
--- /dev/null
+++ b/consul-loader-container/Changelog.md
@@ -0,0 +1,15 @@
+# Change Log
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](http://keepachangelog.com/)
+and this project adheres to [Semantic Versioning](http://semver.org/).
+
+## [1.1.0] - 2021-02-05:
+In support of deploying DCAE service components using Helm, the Consul loader
+has been enhanced to:
+ -- Convert YAML configuration files to JSON before storing the configuration into Consul
+ -- Provide an option to delete a Consul key so that a component's configuration can be
+ removed from Consul when the component is undeployed.
+
+This version also changes the base image for the container to the ONAP integration team's
+Python image (integration-python:8.0.0). \ No newline at end of file
diff --git a/consul-loader-container/Dockerfile b/consul-loader-container/Dockerfile
index 868b41f..741d5f3 100644
--- a/consul-loader-container/Dockerfile
+++ b/consul-loader-container/Dockerfile
@@ -2,6 +2,7 @@
# org.onap.dcae
# ================================================================================
# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2021 J. F. Lucas. 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.
@@ -16,8 +17,14 @@
# 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/
+FROM nexus3.onap.org:10001/onap/integration-python:8.0.0
+USER root
+RUN apk update \
+ && apk add bash \
+ && apk add curl \
+ && pip install --upgrade pip \
+ && pip install pyyaml
+COPY *.sh *.py /opt/app/
WORKDIR /opt/app
ENTRYPOINT ["/opt/app/consul_store.sh"]
+USER $user \ No newline at end of file
diff --git a/consul-loader-container/consul_store.sh b/consul-loader-container/consul_store.sh
index 4e64fc3..e60dbc4 100755
--- a/consul-loader-container/consul_store.sh
+++ b/consul-loader-container/consul_store.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# ================================================================================
# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2021 J. F. Lucas. 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.
@@ -25,6 +26,11 @@
# 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
+# --key-yaml keyname|filepath: Register a key-value pair with name 'keyname', converting the YAML content of the file at 'filepath'
+# to JSON, and storing the JSON result as the value. This is used for Helm deployment of DCAE microservices, where the initial
+# application configuration is stored in a Helm values.yaml file in YAML form. --key-yaml converts the YAML configuration into
+# JSON, which is the format that microservices expect.
+# -- delete-key
# A command can include multiple instances of each option.
CONSUL_ADDR=${CONSUL_PROTO:-http}://${CONSUL_HOST:-consul}:${CONSUL_PORT:-8500}
@@ -48,6 +54,12 @@ function put_key {
curl -v -X PUT --data-binary @$2 -H 'Content-Type: application/json' ${KV_URL}/$1
}
+# Delete a key from the Consul KV store
+# $1: Key to be deleted
+function delete_key {
+ curl -v -X DELETE ${KV_URL}/$1
+}
+
set -x
# Check Consul readiness
@@ -86,6 +98,16 @@ do
put_key ${kv[@]}
shift 2;
;;
+ "--key-yaml")
+ # See above for explanation of (${2//|/ })
+ kv=(${2//|/ })
+ cat ${kv[1]} | /opt/app/yaml2json.py | put_key ${kv[0]} -
+ shift 2;
+ ;;
+ "--delete-key")
+ delete_key $2
+ shift 2;
+ ;;
*)
echo "ignoring $1"
shift
diff --git a/consul-loader-container/pom.xml b/consul-loader-container/pom.xml
index dd68443..f347ef9 100644
--- a/consul-loader-container/pom.xml
+++ b/consul-loader-container/pom.xml
@@ -2,6 +2,7 @@
<!--
================================================================================
Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+Copyright (c) 2021 J. F. Lucas. 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.
@@ -27,7 +28,7 @@ limitations under the License.
<groupId>org.onap.dcaegen2.deployments</groupId>
<artifactId>consul-loader-container</artifactId>
<name>dcaegen2-deployments-consul-loader-container</name>
- <version>1.0.0</version>
+ <version>1.1.0</version>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
diff --git a/consul-loader-container/yaml2json.py b/consul-loader-container/yaml2json.py
new file mode 100755
index 0000000..d1ef2da
--- /dev/null
+++ b/consul-loader-container/yaml2json.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+# ================================================================================
+# Copyright (c) 2021 J. F. Lucas. 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=========================================================
+#
+import yaml
+import json
+import sys
+
+def _yaml_to_json (y):
+ return json.dumps(yaml.safe_load(y), indent=2)
+
+def main():
+ try:
+ print (_yaml_to_json(sys.stdin.read()))
+ except Exception as e:
+ print(e, file=sys.stderr)
+ sys.exit(1)
+
+if __name__ == "__main__":
+ main() \ No newline at end of file