Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused code, fix guestinfo data paths #166

Merged
merged 2 commits into from
Feb 24, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions images/capi/hack/image-govc-cloudinit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ fi

export GOVC_VM="${1-}"

create_snapshot() {
snapshots="$(govc snapshot.tree)"
if [[ ${snapshots} = *${1-}* ]]; then
echo "image-govc-cloudinit: skip snapshot '${1-}'; already exists"
else
echo "image-post-cloudinit: create snapshot '${1-}'"
vmrun snapshot "${VMX_FILE}" "${1-}"
fi
}

cd "$(dirname "${BASH_SOURCE[0]}")/.."

# If the VM has a "new" snapshot then revert to it and delete all other
# snapshots.
snapshots="$(govc snapshot.tree 2>/dev/null)" || true
Expand All @@ -69,8 +57,8 @@ echo "image-govc-cloudinit: initializing cloud-init data"
govc vm.change \
-e "guestinfo.userdata.encoding=base64" \
-e "guestinfo.metadata.encoding=base64" \
-e "guestinfo.userdata='$(base64 -w0 <build/images/cloudinit/user-data)'" \
-e "guestinfo.metadata='$(base64 -w0 <build/images/cloudinit/meta-data)'"
-e "guestinfo.userdata='$(base64 -w0 <$( cd "$( dirname "$0" )" && pwd )/../cloudinit/user-data)'" \
-e "guestinfo.metadata='$(base64 -w0 <$( cd "$( dirname "$0" )" && pwd )/../cloudinit/meta-data)'"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried it, but this looks weird to me. why the pwd call? Also, it seems like a couple sets of nested double-quotes without escaping...

shellcheck also does not like this:

$ shellcheck image-govc-cloudinit.sh

In image-govc-cloudinit.sh line 72:
  -e "guestinfo.userdata='$(base64 -w0 <$( cd "$( dirname "$0" )" && pwd )/../cloudinit/user-data)'" \
                                        ^-- SC2046: Quote this to prevent word splitting.


In image-govc-cloudinit.sh line 73:
  -e "guestinfo.metadata='$(base64 -w0 <$( cd "$( dirname "$0" )" && pwd )/../cloudinit/meta-data)'"
                                        ^-- SC2046: Quote this to prevent word splitting.

I might suggest an alternative. Rather than deleting the cd "$(dirname "${BASH_SOURCE[0]}")/.." above, keep it, and change build/images/cloudinit/... to cloudinit/....

The way I see it, we've basically changed from do a cd to the directory above us once to doing it twice. Any compelling reason to do that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why the pwd now. But still, I think there's a much simpler way. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was just more explicit in terms of reading for me, but the suggestion is fine and have pushed an update to reflect


echo "image-govc-cloudinit: creating snapshot 'cloudinit'"
govc snapshot.create cloudinit