Skip to content

Commit d845a5f

Browse files
committed
feat: perform config generation in parallel
1 parent a12a843 commit d845a5f

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

scripts/config-diff.sh

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,6 @@ function main {
232232

233233
kayobe_init
234234

235-
# We need to use the same path for source and target to avoid noise in the diff output.
236-
# Example: https://github.com/openstack/kolla-ansible/blob/5e638b757bdda9fbddf0fe0be5d76caa3419af74/ansible/roles/common/templates/td-agent.conf.j2#L9
237-
environment_path=/tmp/kayobe-env
238-
239-
local ANSIBLE_VAULT="$environment_path/venvs/kayobe/bin/ansible-vault"
240-
241235
# These directories will contain the generated output.
242236
target_dir=$(mktemp -d --suffix -configgen-target)
243237
source_dir=$(mktemp -d --suffix -configgen-source)
@@ -247,27 +241,35 @@ function main {
247241
clean_copy "$KAYOBE_CONFIG_SOURCE_PATH" "$source_kayobe_config_dir"
248242
clean_copy "$KAYOBE_CONFIG_SOURCE_PATH" "$target_kayobe_config_dir"
249243

250-
# Checkout the git reference provided as an argument to this script
251-
checkout "$target_kayobe_config_dir" $1
252-
create_kayobe_environment "$environment_path" "$target_kayobe_config_dir"
253-
redact_config_dir "$environment_path"
254-
# Encryption expected on passwords.yml due to lookup in kayobe, see:
255-
# https://github.com/openstack/kayobe/blob/869185ea7be5d6b5b21c964a620839d5475196fd/ansible/roles/kolla-ansible/library/kolla_passwords.py#L81
256-
encrypt_config_dir "$environment_path"
257-
generate_config "$environment_path" "$target_dir"
258-
259-
# Move it out the way so that we can use the same path
260-
mv "$environment_path" "$environment_path-$(date '+%Y-%m-%d-%H.%M.%S')"
261-
262-
# Perform same steps as above, but for the source branch
263-
# Merge in the target branch so that we don't see changes that were added since we branched.
264-
merge "$source_kayobe_config_dir" $1
265-
find_redacted_files "$source_kayobe_config_dir/etc/kayobe"
266-
create_kayobe_environment "$environment_path" "$source_kayobe_config_dir"
267-
# Supplying a reference kayobe-config will do a diff on the secrets
268-
redact_config_dir "$environment_path" "$target_kayobe_config_dir"
269-
encrypt_config_dir "$environment_path"
270-
generate_config "$environment_path" "$source_dir"
244+
function generate_target_config {
245+
target_environment_path=/tmp/target-kayobe-env
246+
export ANSIBLE_LOG_PATH=/tmp/target-kayobe.log
247+
local ANSIBLE_VAULT="$target_environment_path/venvs/kayobe/bin/ansible-vault"
248+
# Checkout the git reference provided as an argument to this script
249+
checkout "$target_kayobe_config_dir" $1
250+
create_kayobe_environment "$target_environment_path" "$target_kayobe_config_dir"
251+
redact_config_dir "$target_environment_path"
252+
encrypt_config_dir "$target_environment_path"
253+
generate_config "$target_environment_path" "$target_dir"
254+
}
255+
256+
function generate_source_config {
257+
source_environment_path=/tmp/source-kayobe-env
258+
export ANSIBLE_LOG_PATH=/tmp/source-kayobe.log
259+
local ANSIBLE_VAULT="$source_environment_path/venvs/kayobe/bin/ansible-vault"
260+
# Perform same steps as above, but for the source branch
261+
# Merge in the target branch so that we don't see changes that were added since we branched.
262+
merge "$source_kayobe_config_dir" $1
263+
find_redacted_files "$source_kayobe_config_dir/etc/kayobe"
264+
create_kayobe_environment "$source_environment_path" "$source_kayobe_config_dir"
265+
redact_config_dir "$source_environment_path" "$target_kayobe_config_dir"
266+
encrypt_config_dir "$source_environment_path"
267+
generate_config "$source_environment_path" "$source_dir"
268+
}
269+
270+
generate_target_config $1 >/dev/null 2>&1 &
271+
generate_source_config $1 &
272+
wait < <(jobs -p)
271273

272274
# diff gives non-zero exit status if there is a difference
273275
if sudo_if_available diff -Nur $target_dir $source_dir >/tmp/kayobe-config-diff; then

0 commit comments

Comments
 (0)