Browse Source

new: allow relations to avoid creating any links.

This is done through a new ``tech-dep`` attribute in the
definition of the relation (done in the ``provide`` part of
the ``metadata.yml`` of a charm).

This replaces the ``reverse-tech-dep`` as it no allows 3 values.
The default one is ``True`` which simply allow the creation of
a ``link`` in the ``docker-compose`` file.
The value ``False`` will prevent creation of any ``link``, and the
``reversed`` value will reverse the ``link`` created.
raw-remaining-args
Valentin Lab 9 years ago
parent
commit
7c77658ff8
  1. 35
      bin/compose

35
bin/compose

@ -212,12 +212,12 @@ _get_docker_compose_links() {
master_charm=$(_get_top_master_charm_for_service "$service") || return 1 master_charm=$(_get_top_master_charm_for_service "$service") || return 1
deps=() deps=()
while read-0 relation_name target_service relation_config reverse; do
while read-0 relation_name target_service relation_config tech_dep; do
master_target_charm="$(_get_top_master_charm_for_service "$target_service")" master_target_charm="$(_get_top_master_charm_for_service "$target_service")"
[ "$master_charm" == "$master_target_charm" ] && continue [ "$master_charm" == "$master_target_charm" ] && continue
if [ "$reverse" ]; then
if [ "$tech_dep" == "reversed" ]; then
deps+=("$(echo -en "$master_target_charm:\n links:\n - $master_charm")") deps+=("$(echo -en "$master_target_charm:\n links:\n - $master_charm")")
else
elif [ "$tech_dep" == "True" ]; then
deps+=("$(echo -en "$master_charm:\n links:\n - $master_target_charm")") deps+=("$(echo -en "$master_charm:\n links:\n - $master_target_charm")")
fi fi
done < <(get_compose_relations "$service") || return 1 done < <(get_compose_relations "$service") || return 1
@ -580,7 +580,7 @@ get_charm_relation_def () {
export -f get_charm_relation_def export -f get_charm_relation_def
get_charm_reverse_tech_dep_relation() {
get_charm_tech_dep_orientation_for_relation() {
local charm="$1" relation_name="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \ local charm="$1" relation_name="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \
relation_def metadata value relation_def metadata value
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
@ -589,14 +589,15 @@ get_charm_reverse_tech_dep_relation() {
return 0 return 0
fi fi
relation_def=$(get_charm_relation_def "$charm" "$relation_name" 2>/dev/null) relation_def=$(get_charm_relation_def "$charm" "$relation_name" 2>/dev/null)
value=$(echo "$relation_def" | shyaml get-value 'reverse-tech-dep' 2>/dev/null)
value=$(echo "$relation_def" | shyaml get-value 'tech-dep' 2>/dev/null)
value=${value:-True}
echo "$value" | tee "$cache_file" echo "$value" | tee "$cache_file"
} }
export -f get_charm_reverse_tech_dep_relation
export -f get_charm_tech_dep_orientation_for_relation
## ##
## Use compose file to get deps, and relation definition in metadata.yml ## Use compose file to get deps, and relation definition in metadata.yml
## for reverse-tech-dep attribute.
## for tech-dep attribute.
get_service_deps() { get_service_deps() {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)"
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
@ -607,7 +608,7 @@ get_service_deps() {
( (
set -o pipefail set -o pipefail
get_compose_relations "$service" | \ get_compose_relations "$service" | \
while read-0 relation_name target_service _relation_config reverse; do
while read-0 relation_name target_service _relation_config tech_dep; do
echo "$target_service" echo "$target_service"
done | tee "$cache_file" done | tee "$cache_file"
) || return 1 ) || return 1
@ -923,19 +924,19 @@ get_compose_relations () {
case "$(echo "$relation_def" | shyaml get-type 2>/dev/null)" in case "$(echo "$relation_def" | shyaml get-type 2>/dev/null)" in
"str") "str")
target_service="$(echo "$relation_def" | shyaml get-value 2>/dev/null)" target_service="$(echo "$relation_def" | shyaml get-value 2>/dev/null)"
reverse="$(get_charm_reverse_tech_dep_relation "$target_service" "$relation_name")"
echo -en "$relation_name\0$target_service\0\0$reverse\0"
tech_dep="$(get_charm_tech_dep_orientation_for_relation "$target_service" "$relation_name")"
echo -en "$relation_name\0$target_service\0\0$tech_dep\0"
;; ;;
"sequence") "sequence")
while read-0 target_service; do while read-0 target_service; do
reverse="$(get_charm_reverse_tech_dep_relation "$target_service" "$relation_name")"
echo -en "$relation_name\0$target_service\0\0$reverse\0"
tech_dep="$(get_charm_tech_dep_orientation_for_relation "$target_service" "$relation_name")"
echo -en "$relation_name\0$target_service\0\0$tech_dep\0"
done < <(echo "$relation_def" | shyaml get-values-0 2>/dev/null) done < <(echo "$relation_def" | shyaml get-values-0 2>/dev/null)
;; ;;
"struct") "struct")
while read-0 target_service relation_config; do while read-0 target_service relation_config; do
reverse="$(get_charm_reverse_tech_dep_relation "$target_service" "$relation_name")"
echo -en "$relation_name\0$target_service\0$relation_config\0$reverse\0"
tech_dep="$(get_charm_tech_dep_orientation_for_relation "$target_service" "$relation_name")"
echo -en "$relation_name\0$target_service\0$relation_config\0$tech_dep\0"
done < <(echo "$relation_def" | shyaml key-values-0 2>/dev/null) done < <(echo "$relation_def" | shyaml key-values-0 2>/dev/null)
;; ;;
esac esac
@ -961,7 +962,7 @@ run_service_relations () {
for subservice in $(get_service_deps "$service") "$service"; do for subservice in $(get_service_deps "$service") "$service"; do
[ "${loaded[$subservice]}" ] && continue [ "${loaded[$subservice]}" ] && continue
# debug " Relations of ${DARKYELLOW}$subservice${NORMAL}:" # debug " Relations of ${DARKYELLOW}$subservice${NORMAL}:"
while read-0 relation_name target_service relation_config reverse; do
while read-0 relation_name target_service relation_config tech_dep; do
export relation_config export relation_config
Wrap -d "Building $DARKYELLOW$subservice$NORMAL --$DARKBLUE$relation_name$NORMAL--> $DARKYELLOW$target_service$NORMAL" <<EOF || return 1 Wrap -d "Building $DARKYELLOW$subservice$NORMAL --$DARKBLUE$relation_name$NORMAL--> $DARKYELLOW$target_service$NORMAL" <<EOF || return 1
_run_service_relation "$relation_name" "$subservice" "$target_service" "\$relation_config" _run_service_relation "$relation_name" "$subservice" "$target_service" "\$relation_config"
@ -1123,7 +1124,7 @@ has_service_action () {
return 0 return 0
fi fi
## Action provided by relation ? ## Action provided by relation ?
while read-0 relation_name target_service relation_config reverse; do
while read-0 relation_name target_service relation_config tech_dep; do
target_charm=$(get_service_charm "$target_service") || return 1 target_charm=$(get_service_charm "$target_service") || return 1
target_script="$CHARM_STORE/$target_charm/actions/relations/$relation_name/$action" target_script="$CHARM_STORE/$target_charm/actions/relations/$relation_name/$action"
if [ -x "$target_script" ]; then if [ -x "$target_script" ]; then
@ -1237,7 +1238,7 @@ _get_master_charm_for_service() {
## Action provided by relation ? ## Action provided by relation ?
target_service= target_service=
while read-0 relation_name candidate_target_service _relation_config _reverse; do
while read-0 relation_name candidate_target_service _relation_config _tech_dep; do
[ "$interface" == "$relation_name" ] && { [ "$interface" == "$relation_name" ] && {
target_service="$candidate_target_service" target_service="$candidate_target_service"
break break

Loading…
Cancel
Save