mirror of
https://github.com/flatcar/scripts.git
synced 2026-05-04 11:51:14 +02:00
feat(coreos-base/oem-gce): support cloudconfig
With this pull request we can support a cloudconfig sent to the user-data metadata key. Tested etcd and fleet bootstrapping and ssh key insertion.
This commit is contained in:
parent
c6fad7f423
commit
729fe0e6ae
@ -2,7 +2,27 @@
|
||||
|
||||
coreos:
|
||||
units:
|
||||
- name: ec2-ssh-key.service
|
||||
- name: gce-coreos-cloudinit.service
|
||||
runtime: yes
|
||||
content: |
|
||||
[Unit]
|
||||
Requires=gce-setup-environment.service
|
||||
After=gce-setup-environment.service
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=/etc/environment
|
||||
ExecStart=/usr/share/oem/bin/gce-coreos-cloudinit
|
||||
- name: gce-setup-environment.service
|
||||
runtime: yes
|
||||
content: |
|
||||
[Unit]
|
||||
Description=Setup environment variables from metadata
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
StandardOutput=journal+console
|
||||
ExecStart=/usr/share/oem/bin/gce-setup-environment /etc/environment
|
||||
- name: gce-ssh-key.service
|
||||
runtime: yes
|
||||
content: |
|
||||
[Unit]
|
||||
|
||||
10
sdk_container/src/third_party/coreos-overlay/coreos-base/oem-gce/files/gce-coreos-cloudinit
vendored
Normal file
10
sdk_container/src/third_party/coreos-overlay/coreos-base/oem-gce/files/gce-coreos-cloudinit
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
TMPFILE=$(mktemp /tmp/XXXXXX-cloud-init)
|
||||
trap 'echo "removing ${TMPFILE}"; rm -f ${TMPFILE}' INT TERM EXIT
|
||||
|
||||
curl --retry 5 --retry-delay 2 --silent --fail \
|
||||
"http://169.254.169.254/computeMetadata/v1/instance/attributes/user-data" \
|
||||
-H "X-Google-Metadata-Request: True" > ${TMPFILE}
|
||||
|
||||
/usr/bin/coreos-cloudinit --from-file=${TMPFILE}
|
||||
31
sdk_container/src/third_party/coreos-overlay/coreos-base/oem-gce/files/gce-setup-environment
vendored
Executable file
31
sdk_container/src/third_party/coreos-overlay/coreos-base/oem-gce/files/gce-setup-environment
vendored
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/bash +x
|
||||
|
||||
ENV=$1
|
||||
|
||||
if [ -z "$ENV" ]; then
|
||||
echo usage: $0 /etc/environment
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# test for rw
|
||||
touch $ENV
|
||||
if [ $? -ne 0 ]; then
|
||||
echo exiting, unable to modify: $ENV
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sed -i -e '/^COREOS_PUBLIC_IPV4=/d' \
|
||||
-e '/^COREOS_PRIVATE_IPV4=/d' \
|
||||
"${ENV}"
|
||||
|
||||
external_ip=$(curl --retry 5 --retry-delay 2 --silent --fail \
|
||||
"http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip" \
|
||||
-H "X-Google-Metadata-Request: True")
|
||||
|
||||
|
||||
public_ip=$(curl --retry 5 --retry-delay 2 --silent --fail \
|
||||
"http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/ip" \
|
||||
-H "X-Google-Metadata-Request: True")
|
||||
|
||||
echo COREOS_PUBLIC_IPV4=${external_ip} >> $ENV
|
||||
echo COREOS_PRIVATE_IPV4=${public_ip} >> $ENV
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
set -e
|
||||
|
||||
URL_PREFIX="http://metadata/computeMetadata/v1beta1/"
|
||||
URL_PREFIX="http://169.254.169.254/computeMetadata/v1beta1/"
|
||||
|
||||
update_keys() {
|
||||
local id="$1"
|
||||
|
||||
@ -19,6 +19,12 @@ src_install() {
|
||||
into "/"
|
||||
dobin ${FILESDIR}/gce-ssh-key
|
||||
|
||||
into "/"
|
||||
dobin ${FILESDIR}/gce-coreos-cloudinit
|
||||
|
||||
into "/"
|
||||
dobin ${FILESDIR}/gce-setup-environment
|
||||
|
||||
insinto "/"
|
||||
doins ${FILESDIR}/cloud-config.yml
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user