Browse Source

fix: [compose-core] repair indirect action

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
cache-relation
Valentin Lab 2 years ago
parent
commit
084f9a0c0a
  1. 55
      bin/compose-core

55
bin/compose-core

@ -2771,35 +2771,24 @@ _run_service_action_relation() {
return 1
fi
export RELATION_DATA_FILE=$(get_relation_data_file "$service" "$target_service" "$relation_name" "$relation_config")
export action_errlvl_file="$state_tmpdir/action-$service-$charm-$action-errlvl"
export state_tmpdir
{
(
set +e ## Prevents unwanted leaks from parent shell
export METADATA_CONFIG=$(charm.metadata "$charm")
export SERVICE_NAME=$service
export RELATION_TARGET_SERVICE="$target_service"
export RELATION_TARGET_CHARM="$target_charm"
export RELATION_BASE_SERVICE="$service"
export RELATION_BASE_CHARM="$charm"
export ACTION_NAME=$action
export CONTAINER_NAME=$(get_top_master_service_for_service "$service")
export DOCKER_BASE_IMAGE=$(service_base_docker_image "$CONTAINER_NAME")
export SERVICE_DATASTORE="$DATASTORE/$service"
export SERVICE_CONFIGSTORE="$CONFIGSTORE/$service"
exname="$exname $ACTION_NAME $SERVICE_NAME" \
stdbuf -oL -eL bash -c 'charm.run_relation_action "$@"' -- "$target_charm" "$relation_name" "$action" "$@"
echo "$?" > "$action_errlvl_file"
) | logstdout "$DARKYELLOW$service$NORMAL/${DARKCYAN}$action${NORMAL} ${GREEN}@${NORMAL}"
} 3>&1 1>&2 2>&3 | logstderr "$DARKYELLOW$service$NORMAL/${DARKCYAN}$action${NORMAL} ${RED}@$NORMAL" 3>&1 1>&2 2>&3
if ! [ -e "$action_errlvl_file" ]; then
err "Action $DARKYELLOW$service$NORMAL:$DARKCYAN$action$NORMAL has failed without having time" \
"to output an errlvl"
return 1
fi
return "$(cat "$action_errlvl_file")"
(
set +e ## Prevents unwanted leaks from parent shell
export METADATA_CONFIG=$(charm.metadata "$charm")
export SERVICE_NAME=$service
export RELATION_TARGET_SERVICE="$target_service"
export RELATION_TARGET_CHARM="$target_charm"
export RELATION_BASE_SERVICE="$service"
export RELATION_BASE_CHARM="$charm"
export ACTION_NAME=$action
export CONTAINER_NAME=$(get_top_master_service_for_service "$service")
export DOCKER_BASE_IMAGE=$(service_base_docker_image "$CONTAINER_NAME")
export SERVICE_DATASTORE="$DATASTORE/$service"
export SERVICE_CONFIGSTORE="$CONFIGSTORE/$service"
exname="$exname $ACTION_NAME $SERVICE_NAME" \
stdbuf -oL -eL bash -c 'charm.run_relation_action "$@"' -- "$target_charm" "$relation_name" "$action" "$@"
) 0<&6 ## inject general stdin
}
export -f _run_service_action_relation
@ -3733,6 +3722,7 @@ get_docker_charm_action_help() {
local services service charm relation_name target_service relation_config \
target_charm
services=($(get_compose_yml_content | shyaml keys 2>/dev/null))
get_all_relations "${services[@]}" >/dev/null 2>&1 || exit 1
for service in "${services[@]}"; do
out=$(
charm=$(get_service_charm "$service") || return 1
@ -3744,7 +3734,7 @@ get_docker_charm_action_help() {
for action in $(charm.ls_relation_actions "$target_charm" "$relation_name"); do
printf " %-28s %s\n" "$action $service" "Indirect action from ${DARKPINK}$target_charm${NORMAL}"
done
done < <(get_compose_relations "$service")
done < <(get_service_relations "$service")
)
if [ "$out" ]; then
echo " for ${DARKYELLOW}$service${NORMAL}:"
@ -4226,6 +4216,12 @@ if [ -z "$is_docker_compose_action" -a "$action" ]; then
display_commands_help
exit 1
fi
## Required by has_service_action
array_read-0 services_args < <(printf "%s" "$COMPOSE_YML_CONTENT" | shyaml keys-0 2>/dev/null)
get_all_relations "${services_args[@]}" >/dev/null 2>&1 || return 1
remainder_args=("${remainder_args[@]:1}")
if has_service_action "$action_service" "$action" >/dev/null; then
is_service_action=true
@ -4242,6 +4238,7 @@ if [ -z "$is_docker_compose_action" -a "$action" ]; then
esac
} < <(has_service_action "$action_service" "$action")
services_args=("$action_service")
get_all_relations "${services_args[@]}" >/dev/null 2>&1 || return 1
## Divert logging to stdout to stderr
log () { cat >&2; }
@ -4420,7 +4417,7 @@ case "$action" in
;;
*)
if [ "$is_service_action" ]; then
run_service_action "$SERVICE_PACK" "$action" "${remainder_args[@]}"
run_service_action "$action_service" "$action" "${remainder_args[@]}"
errlvl="$?"
errlvl "$errlvl"
else

Loading…
Cancel
Save