@@ -242,12 +242,6 @@ function main {
242
242
243
243
kayobe_init
244
244
245
- # We need to use the same path for source and target to avoid noise in the diff output.
246
- # Example: https://github.com/openstack/kolla-ansible/blob/5e638b757bdda9fbddf0fe0be5d76caa3419af74/ansible/roles/common/templates/td-agent.conf.j2#L9
247
- environment_path=/tmp/kayobe-env
248
-
249
- local ANSIBLE_VAULT=" $environment_path /venvs/kayobe/bin/ansible-vault"
250
-
251
245
# These directories will contain the generated output.
252
246
target_dir=$( mktemp -d --suffix -configgen-target)
253
247
source_dir=$( mktemp -d --suffix -configgen-source)
@@ -257,27 +251,54 @@ function main {
257
251
clean_copy " $KAYOBE_CONFIG_SOURCE_PATH " " $source_kayobe_config_dir "
258
252
clean_copy " $KAYOBE_CONFIG_SOURCE_PATH " " $target_kayobe_config_dir "
259
253
260
- # Checkout the git reference provided as an argument to this script
261
- checkout " $target_kayobe_config_dir " $1
262
- create_kayobe_environment " $environment_path " " $target_kayobe_config_dir "
263
- redact_config_dir " $environment_path "
264
- # Encryption expected on passwords.yml due to lookup in kayobe, see:
265
- # https://github.com/openstack/kayobe/blob/869185ea7be5d6b5b21c964a620839d5475196fd/ansible/roles/kolla-ansible/library/kolla_passwords.py#L81
266
- encrypt_config_dir " $environment_path "
267
- generate_config " $environment_path " " $target_dir "
268
-
269
- # Move it out the way so that we can use the same path
270
- mv " $environment_path " " $environment_path -$( date ' +%Y-%m-%d-%H.%M.%S' ) "
271
-
272
- # Perform same steps as above, but for the source branch
273
- # Merge in the target branch so that we don't see changes that were added since we branched.
274
- merge " $source_kayobe_config_dir " $1
275
- find_redacted_files " $source_kayobe_config_dir /etc/kayobe"
276
- create_kayobe_environment " $environment_path " " $source_kayobe_config_dir "
277
- # Supplying a reference kayobe-config will do a diff on the secrets
278
- redact_config_dir " $environment_path " " $target_kayobe_config_dir "
279
- encrypt_config_dir " $environment_path "
280
- generate_config " $environment_path " " $source_dir "
254
+ function normalize_file_text() {
255
+ local file=" $1 "
256
+ local text=" $2 "
257
+
258
+ sed -i " s#/tmp/$text /\(.*\)#/tmp/\1#g" " $file "
259
+ }
260
+
261
+ function normalize_files_in_folder() {
262
+ local folder=" $1 "
263
+ local text=" $2 "
264
+
265
+ # Find all files in the folder and its subfolders and loop through them
266
+ find " $folder " -type f -print0 | while IFS= read -r -d ' ' file; do
267
+ normalize_file_text " $file " " $text "
268
+ done
269
+ }
270
+
271
+ function generate_target_config {
272
+ target_environment_path=/tmp/target-kayobe-env
273
+ export ANSIBLE_LOG_PATH=/tmp/target-kayobe.log
274
+ local ANSIBLE_VAULT=" $target_environment_path /venvs/kayobe/bin/ansible-vault"
275
+ # Checkout the git reference provided as an argument to this script
276
+ checkout " $target_kayobe_config_dir " $1
277
+ create_kayobe_environment " $target_environment_path " " $target_kayobe_config_dir "
278
+ redact_config_dir " $target_environment_path "
279
+ encrypt_config_dir " $target_environment_path "
280
+ generate_config " $target_environment_path " " $target_dir "
281
+ normalize_files_in_folder " $target_environment_path " " target-kayobe-env"
282
+ }
283
+
284
+ function generate_source_config {
285
+ source_environment_path=/tmp/source-kayobe-env
286
+ export ANSIBLE_LOG_PATH=/tmp/source-kayobe.log
287
+ local ANSIBLE_VAULT=" $source_environment_path /venvs/kayobe/bin/ansible-vault"
288
+ # Perform same steps as above, but for the source branch
289
+ # Merge in the target branch so that we don't see changes that were added since we branched.
290
+ merge " $source_kayobe_config_dir " $1
291
+ find_redacted_files " $source_kayobe_config_dir /etc/kayobe"
292
+ create_kayobe_environment " $source_environment_path " " $source_kayobe_config_dir "
293
+ redact_config_dir " $source_environment_path " " $target_kayobe_config_dir "
294
+ encrypt_config_dir " $source_environment_path "
295
+ generate_config " $source_environment_path " " $source_dir "
296
+ normalize_files_in_folder " $source_environment_path " " source-kayobe-env"
297
+ }
298
+
299
+ generate_target_config $1 > /dev/null 2>&1 &
300
+ generate_source_config $1 &
301
+ wait < <( jobs -p)
281
302
282
303
# diff gives non-zero exit status if there is a difference
283
304
if sudo_if_available diff -Nur $target_dir $source_dir > /tmp/kayobe-config-diff; then
0 commit comments