Skip to content

Commit

Permalink
Merge pull request rancher#14 from rancher-sandbox/fixups/cloud-init
Browse files Browse the repository at this point in the history
Cloud init fixups
  • Loading branch information
mudler authored Feb 14, 2022
2 parents b051e08 + d035c47 commit 7acfcdb
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 43 deletions.
2 changes: 1 addition & 1 deletion cmd/ros-installer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
var (
automatic = flag.Bool("automatic", false, "Check for and run automatic installation")
printConfig = flag.Bool("print-config", false, "Print effective configuration and exit")
configFile = flag.String("config-file", "", "Config file to use, local file or http/tftp URL")
configFile = flag.String("config-file", "/oem/userdata", "Config file to use, local file or http/tftp URL")
powerOff = flag.Bool("power-off", false, "Power off after installation")
yes = flag.Bool("y", false, "Do not prompt for questions")
)
Expand Down
2 changes: 2 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ users:
- name: "bar"
passwd: "foo"
groups: "users"
homedir: "/home/foo"
shell: "/bin/bash"
ssh_authorized_keys:
- faaapploo

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[Unit]
ConditionPathExists=!/run/cos/live_mode
ConditionPathExists=!/run/cos/recovery_mode
After=
After=cos-setup-network.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Unit]
After=
After=cos-setup-network.service
31 changes: 24 additions & 7 deletions framework/files/system/oem/01_ros-rootfs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,40 @@ stages:
/var/lib/cni
PERSISTENT_STATE_BIND: "true"
rootfs.before:
- name: "Pull data from provider"
# Try to get network before trying to fetch datasource from the net
- commands:
- wicked ifup eth0
- &datasource
name: "Pull data from provider"
datasource:
providers: ["cdrom"]
providers: ["cdrom", "gcp", "openstack", "aws", "azure", "hetzner", "packet", "scaleway", "vultr", "digitalocean", "metaldata" ]
path: "/oem"
# Ensures that if no userdata is found at this stage,
# we retry later and run the boot hook
# This is relevant only on first-boot
# Mind that userdata can be in the standard cloud-init syntax.
# If we don't find any userdata at this stage (because no network is present)
# We source the respective fields afterwards
- if: '[ ! -f /oem/userdata ]'
files:
- path: /oem/userdata_load
rootfs.after:
- if: '[ ! -f /run/cos/recovery_mode ] && [ ! -f /run/cos/live_mode ]'
name: "Grow persistent"
layout:
device:
label: COS_PERSISTENT
expand_partition:
size: 0
network:
- name: "Pull data from provider (local)"
datasource:
providers: ["aws", "gcp", "openstack", "cdrom"]
path: "/oem"
- <<: *datasource
# Trigger /oem/userdata if was fetched late
# when network was available
# This is relevant only on first-boot
- if: '[ -f /oem/userdata ] && [ -f /oem/userdata_load ]'
commands:
- elemental cloud-init -s initramfs /oem/userdata
- elemental cloud-init -s boot /oem/userdata
- rm -rf /oem/userdata_load
fs.before:
- if: '[ ! -f "/run/cos/recovery_mode" ] && [ ! -f /run/cos/live_mode ]'
name: "Grow persistent fs"
Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export CLOUD_INIT_ISO?=$(ROOT_DIR)/build/ci.iso
clean: clean_vm_from_iso
(vagrant destroy -f) 2> /dev/null || true
(vagrant box remove $(BOX_IMAGE)) 2> /dev/null || true
rm -rf build-box || true
rm -rf build-box build || true

add:
vagrant box add --force $(BOX_IMAGE) $(BOX)
Expand Down
3 changes: 2 additions & 1 deletion tests/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

Vagrant.configure("2") do |config|
config.vm.guest = :linux
config.ssh.username = "vagrant"
# Temp workaround for https://github.com/rancher-sandbox/os2/issues/15
config.ssh.username = "root"
config.vm.boot_timeout = 460
config.ssh.connect_timeout = 360
config.vm.synced_folder ".", "/vagrant", disabled: true
Expand Down
54 changes: 24 additions & 30 deletions tests/assets/cloud_init.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
# Note: This cloud-init doesn't use the standard cloud-init config probably due to: https://github.com/rancher/os2/issues/7
# As a workaround, use the internal extended syntax
stages:
network:
- name: "Setup users"
ensure_entities:
- path: /etc/passwd
entity: |
kind: "user"
username: "vagrant"
password: "x"
homedir: "/run/tmp/vagrant"
shell: "/bin/bash"
- path: /etc/shadow
entity: |
kind: "shadow"
username: "vagrant"
password: ""
- path: /etc/shadow
entity: |
kind: "shadow"
username: "root"
password: "ros"
commands:
- mkdir -p /run/tmp/vagrant
- name: "Setup pubkey"
authorized_keys:
vagrant:
- https://raw.githubusercontent.com/hashicorp/vagrant/main/keys/vagrant.pub
name: "Setup for the vagrant user"
#cloud-config

# Add additional users or set the password/ssh keys for root
users:
- name: "root"
passwd: "ros"
ssh_authorized_keys:
- https://raw.githubusercontent.com/hashicorp/vagrant/main/keys/vagrant.pub
# - name: "vagrant"
# passwd: "vagrant"
# shell: "/bin/bash"
# homedir: "/run/vagrant"
# ssh_authorized_keys:
# - https://raw.githubusercontent.com/hashicorp/vagrant/main/keys/vagrant.pub

# Temp workaround for https://github.com/rancher-sandbox/os2/issues/15.
# Uncomment the lines commented before and drop runcmd when it is closed.
runcmd:
- systemctl start wicked
#- useradd -d /run/vagrant -U -s /bin/bash -m vagrant
- mkdir /root/.ssh
- curl -L https://raw.githubusercontent.com/hashicorp/vagrant/main/keys/vagrant.pub -o /root/.ssh/authorized_keys
- chmod 700 /root/.ssh
- chmod 600 /root/.ssh/authorized_keys
6 changes: 3 additions & 3 deletions tests/smoke/smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ var _ = Describe("os2 Smoke tests", func() {
Eventually(func() string {
out, _ := s.Command("k3s kubectl apply -f /usr/local/setting.yaml")
return out
}, 6*time.Minute, 30*time.Second).Should(
}, 15*time.Minute, 30*time.Second).Should(
Or(
ContainSubstring("unchanged"),
ContainSubstring("configured"),
Expand All @@ -163,12 +163,12 @@ var _ = Describe("os2 Smoke tests", func() {
Eventually(func() string {
out, _ := s.Command("KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm -n cattle-rancheros-operator-system install --create-namespace rancheros-operator /usr/local/ros.tgz")
return out
}, 6*time.Minute, 2*time.Second).Should(ContainSubstring("STATUS: deployed"))
}, 15*time.Minute, 2*time.Second).Should(ContainSubstring("STATUS: deployed"))

Eventually(func() string {
out, _ := s.Command("k3s kubectl get pods --all-namespaces")
return out
}, 6*time.Minute, 2*time.Second).Should(ContainSubstring("rancheros-operator-"))
}, 15*time.Minute, 2*time.Second).Should(ContainSubstring("rancheros-operator-"))
})

By("adding a machine registration", func() {
Expand Down

0 comments on commit 7acfcdb

Please sign in to comment.