Skip to content

Commit

Permalink
fix cloud-init behaviour
Browse files Browse the repository at this point in the history
- the corectl hooks being passed though the default ignition
  template weren't being passed exactly in the desired order
  which made some features to not work as expected.
  In particular $private_ipv4 and $pubic_ipv4 were not being
  recognized properly in user provided cloud-configs since
  /etc/environment was being setup too late.
  The etcd cluster example was updated to reflect this.
- while working in the above issue another related surfaced
  with the fix - let’s say an user is scripting and passes a
  templated cloud-config to corectl and then progmamatically
  deletes it from its local fs after corectl ends booting.
  corectl would exit before actually have fetching that
  cloud-config file (and when it would do it then it would
  be gone). Now, and to cover this precise corner case, if
  there's an user-provided cloud-config it is fetched and
  saved early, at the same time as the ignition one and
  saved for later use.

Signed-off-by: António Meireles <antonio.meireles@reformi.st>
  • Loading branch information
AntonioMeireles committed Jul 21, 2016
1 parent 4b2876e commit 750d31b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 24 deletions.
20 changes: 10 additions & 10 deletions components/common/assets/assets_vfsdata.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,46 @@ systemd:
ExecStart=/bin/bash -c "/usr/bin/hostnamectl set-hostname __vm.Name__ "
[Install]
WantedBy=basic.target
- name: phone-home.service
- name: setEnv.service
enable: true
contents: |
[Unit]
Description=Tell corectld that this machine is online.
Description=Setups /etc/environment
Requires=system-config.target
Before=system-config.target
[Service]
Type=oneshot
RemainAfterExit=yes
StandardOutput=journal+console
ExecStart=/bin/bash -c "\
/home/core/bin/find-ip4.sh eth0 /etc/environment COREOS_PRIVATE_IPV4 &&\
/home/core/bin/find-ip4.sh eth0 /etc/environment COREOS_PUBLIC_IPV4 &&\
/home/core/bin/find-ip4.sh eth0 /etc/environment COREOS_PUBLIC_IPV4"
[Install]
RequiredBy=system-config.target
- name: phone-home.service
enable: true
contents: |
[Unit]
Description=Tells corectld that machine got up
Requires=setEnv.service
After=setEnv.service
[Service]
Type=oneshot
RemainAfterExit=yes
StandardOutput=journal+console
ExecStart=/bin/bash -c " \
[[ $$(</proc/cmdline) =~ corectl.endpoint=([^\\ ]+) ]] && \
curl -Ls $${BASH_REMATCH[1]}/ping "
[Install]
WantedBy=network.target
RequiredBy=setEnv.service
- name: corectl-host-homedir-sharing.service
enable: true
contents: |
[Unit]
Description=Mounts host's caller homedir via NFS
ConditionKernelCommandLine=corectl.sharedhomedir=true
Requires=phone-home.service
After=phone-home.service
Requires=setEnv.service
After=setEnv.service
[Service]
Type=oneshot
RemainAfterExit=yes
Expand All @@ -112,8 +128,8 @@ systemd:
contents: |
[Unit]
Description=Check that VM actually has a path the the outter world
Requires=phone-home.service
After=phone-home.service
Requires=system-config.target
After=system-config.target
[Service]
Type=oneshot
RemainAfterExit=yes
Expand All @@ -123,4 +139,4 @@ systemd:
[[ $$(</proc/cmdline) =~ corectl.endpoint=([^\\ ]+) ]] && \
curl -Ls $${BASH_REMATCH[1]}/NotIsolated "
[Install]
RequiredBy=phone-home.service
RequiredBy=system-config.target
7 changes: 5 additions & 2 deletions components/server/httpservices.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ func httpInstanceCloudConfig(w http.ResponseWriter, r *http.Request) {
vm := Daemon.Active[mux.Vars(r)["uuid"]]
if vm.CloudConfig == "" || vm.CClocation != Local {
httpError(w, http.StatusPreconditionFailed)
} else if t, err := ioutil.ReadFile(vm.CloudConfig); err != nil {
} else if vm.cloudConfigContents == nil {
httpError(w, http.StatusInternalServerError)
} else {
vars := strings.NewReplacer("__vm.Name__", vm.Name)
w.Write([]byte(vars.Replace(string(t))))
w.Write([]byte(vars.Replace(string(vm.cloudConfigContents))))
}
}
}
Expand All @@ -107,6 +107,9 @@ func httpInstanceIgnitionConfig(w http.ResponseWriter, r *http.Request) {
"__vm.DomainName__", LocalDomainName,
"__vm.Gateway__", session.Caller.Network.Address,
"__corectl.Version__", Daemon.Meta.Version)
if vm.CloudConfig != "" && vm.CClocation == Local {
vm.cloudConfigContents, _ = ioutil.ReadFile(vm.CloudConfig)
}
if cfgIn, err := config.ParseAsV2_0_0(
[]byte(mods.Replace(coreos.CoreOSIgnitionTmpl))); err != nil {
httpError(w, http.StatusInternalServerError)
Expand Down
1 change: 1 addition & 0 deletions components/server/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type (
done chan struct{}
exec *exec.Cmd
isolationCheck, callBack sync.Once
cloudConfigContents []byte
}
// NetworkInterface ...
NetworkInterface struct {
Expand Down
6 changes: 3 additions & 3 deletions examples/etcd-cluster/etcd-cloud-config.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ coreos:
etcd2:
name: __ETCD_NODE_NAME__
initial-cluster: __ETCD_INITIAL_CLUSTER__
advertise-client-urls: http://__ETCD_NODE_NAME__:2379
advertise-client-urls: http://$public_ipv4:2379
listen-client-urls: http://0.0.0.0:2379
initial-advertise-peer-urls: http://__ETCD_NODE_NAME__:2380
listen-peer-urls: http://__ETCD_NODE_NAME__:2380
initial-advertise-peer-urls: http://$private_ipv4:2380
listen-peer-urls: http://$private_ipv4:2380

units:

Expand Down

0 comments on commit 750d31b

Please sign in to comment.