From 550245112d9c290f720628593ec5db1c5a494fb2 Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp Date: Thu, 23 Oct 2025 11:43:32 +0200 Subject: [PATCH] Improve docker compose setup - add start_period and check intervals to healthcheck in compose - log error message when reading the config file fails Issue-ID: MULTICLOUD-1522 Change-Id: I3ca1f4c33accba5a5b6329e7e84343fc4b6ac055 Signed-off-by: Fiete Ostkamp --- deployments/build.sh | 1 - deployments/docker-compose.yml | 70 ++++++++++++++++----------------- deployments/k8sconfig.json | 9 +++++ deployments/start.sh | 2 - kud/tests/_functions.sh | 9 ++++- kud/tests/plugin.sh | 3 ++ src/k8splugin/internal/config/config.go | 3 +- 7 files changed, 55 insertions(+), 42 deletions(-) create mode 100644 deployments/k8sconfig.json diff --git a/deployments/build.sh b/deployments/build.sh index 0ffd77cc..3a228f86 100755 --- a/deployments/build.sh +++ b/deployments/build.sh @@ -19,7 +19,6 @@ export IMAGE_NAME="nexus3.onap.org:10003/onap/multicloud/k8s" function _compile_src { echo "Compiling source code" - ls pushd $k8s_path/src/k8splugin/ pwd # mount directory and build in container (thus not relying on the state of the runner) diff --git a/deployments/docker-compose.yml b/deployments/docker-compose.yml index af8c9906..525c2ab1 100644 --- a/deployments/docker-compose.yml +++ b/deployments/docker-compose.yml @@ -9,56 +9,54 @@ # See the License for the specific language governing permissions and # limitations under the License. -version: '3' - +# network_mode: host is necessary because +# the multicloud-k8s needs to be able to access the +# kubernetes cluster that is running on the host (in the pipeline) services: + mongo-service: + container_name: mongo-service + image: nexus3.onap.org:10001/mongo:5.0.28 + healthcheck: + test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"] + interval: 10s + timeout: 3s + retries: 3 + start_period: 10s + network_mode: host + # ports: + # - 27017:27017 + restart: always + etcd-service: + container_name: etcd-service + image: nexus3.onap.org:10001/bitnami/etcd:3 + environment: + - ALLOW_NONE_AUTHENTICATION=yes + volumes: + - etcd_data:/bitnami/etcd + network_mode: host + # ports: + # - 2379:2379 + # - 2380:2380 multicloud-k8s: image: ${IMAGE_NAME} build: context: ./ - args: - - HTTP_PROXY=${HTTP_PROXY} - - HTTPS_PROXY=${HTTPS_PROXY} - - NO_PROXY=${NO_PROXY} - environment: - - HTTP_PROXY=${HTTP_PROXY} - - HTTPS_PROXY=${HTTPS_PROXY} - - NO_PROXY=${NO_PROXY},mongo depends_on: - mongo: + mongo-service: condition: service_healthy + # ports: + # - 9015:9015 network_mode: host - ports: - - 9015:9015 volumes: - /opt/csar:/opt/csar - ${PWD}/k8sconfig.json:/opt/multicloud/k8splugin/k8sconfig.json:ro restart: always healthcheck: test: ["CMD", "curl", "http://localhost:9015/v1"] - mongo: - image: nexus3.onap.org:10001/mongo:5.0.28 - environment: - - HTTP_PROXY=${HTTP_PROXY} - - HTTPS_PROXY=${HTTPS_PROXY} - - NO_PROXY=${NO_PROXY} - healthcheck: - test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"] - ports: - - 27017:27017 - restart: always - etcd: - image: nexus3.onap.org:10001/bitnami/etcd:3 - environment: - - ALLOW_NONE_AUTHENTICATION=yes - - HTTP_PROXY=${HTTP_PROXY} - - HTTPS_PROXY=${HTTPS_PROXY} - - NO_PROXY=${NO_PROXY} - volumes: - - etcd_data:/bitnami/etcd - ports: - - 2379:2379 - - 2380:2380 + interval: 10s + timeout: 3s + retries: 3 + start_period: 5s volumes: etcd_data: diff --git a/deployments/k8sconfig.json b/deployments/k8sconfig.json new file mode 100644 index 00000000..59db2a40 --- /dev/null +++ b/deployments/k8sconfig.json @@ -0,0 +1,9 @@ +{ + "database-address": "localhost", + "database-ip": "localhost", + "etcd-ip": "localhost", + "database-type": "mongo", + "plugin-dir": "plugins", + "service-port": "9015" + +} diff --git a/deployments/start.sh b/deployments/start.sh index 61af504c..aca7d10a 100755 --- a/deployments/start.sh +++ b/deployments/start.sh @@ -18,7 +18,5 @@ source _functions.sh # Start k8splugin from containers. build.sh should be run prior this script. # stop_all -start_mongo -generate_k8sconfig start_all wait_for_service diff --git a/kud/tests/_functions.sh b/kud/tests/_functions.sh index 6d24602d..9a01fcf4 100755 --- a/kud/tests/_functions.sh +++ b/kud/tests/_functions.sh @@ -91,11 +91,16 @@ function call_api { return 2 else echo "[INFO] Server replied with status: ${status}" >&2 - cat "${curl_response_file}" - rm "${curl_response_file}" if [[ "${status:0:1}" =~ [45] ]]; then + echo $(cat "${curl_response_file}") >&2 + echo $(docker compose logs -f $WORKSPACE/deployments/docker-compose.yml --tail=30 multicloud-k8s) >&2 + # `cat` determines the return value on stdout for the caller here + cat "${curl_response_file}" + rm "${curl_response_file}" return 1 else + cat "${curl_response_file}" + rm "${curl_response_file}" return 0 fi fi diff --git a/kud/tests/plugin.sh b/kud/tests/plugin.sh index 816a4d87..d1c2efc1 100755 --- a/kud/tests/plugin.sh +++ b/kud/tests/plugin.sh @@ -86,10 +86,13 @@ print_msg "Upload Resource Bundle Definition Content" call_api --data-binary "@${CSAR_DIR}/${csar_id}/vault-consul-dev-0.0.0.tgz" "${base_url}/rb/definition/$rb_name/$rb_version/content" print_msg "Listing Resource Bundle Definitions" +sleep 2 rb_list=$(call_api "${base_url}/rb/definition/$rb_name") if [[ "$rb_list" != *"${rb_name}"* ]]; then echo $rb_list echo "Resource Bundle Definition not stored" + echo "Last container logs: " + echo $(docker compose -f $WORKSPACE/deployments/docker-compose.yml logs --tail=30 multicloud-k8s) >&2 exit 1 fi diff --git a/src/k8splugin/internal/config/config.go b/src/k8splugin/internal/config/config.go index 89f2553d..235732f1 100644 --- a/src/k8splugin/internal/config/config.go +++ b/src/k8splugin/internal/config/config.go @@ -48,6 +48,7 @@ var gConfig *Configuration func readConfigFile(file string) (*Configuration, error) { f, err := os.Open(file) if err != nil { + log.Printf("Error loading config file: %v. Using defaults.", err) return defaultConfiguration(), err } defer f.Close() @@ -96,7 +97,7 @@ func GetConfiguration() *Configuration { if gConfig == nil { conf, err := readConfigFile("k8sconfig.json") if err != nil { - log.Println("Error loading config file. Using defaults.") + log.Printf("Error loading config file: %v", err) } gConfig = conf } -- 2.16.6