diff --git a/config/config_test.go b/config/config_test.go old mode 100644 new mode 100755 diff --git a/config/data_funcs.go b/config/data_funcs.go old mode 100644 new mode 100755 diff --git a/config/disk.go b/config/disk.go old mode 100644 new mode 100755 index 717dd018..57927e4f --- a/config/disk.go +++ b/config/disk.go @@ -69,6 +69,17 @@ func LoadConfigWithPrefix(dirPrefix string) *CloudConfig { return cfg } +func SaveInitCmdline(cmdLineArgs string) { + log.Infof("INITINIT: %s", cmdLineArgs) + + elidedCfg := parseCmdline(cmdLineArgs) + log.Infof("SaveInitCmdline: %#v", elidedCfg) + + if err := WriteToFile(elidedCfg, CloudConfigInitFile); err != nil { + log.Errorf("Failed to write init-cmdline config: %s", err) + } +} + func CloudConfigDirFiles(dirPrefix string) []string { cloudConfigDir := path.Join(dirPrefix, CloudConfigDir) diff --git a/config/types.go b/config/types.go index db9267c9..683c319c 100755 --- a/config/types.go +++ b/config/types.go @@ -40,6 +40,7 @@ const ( OsConfigFile = "/usr/share/ros/os-config.yml" VarRancherDir = "/var/lib/rancher" CloudConfigDir = "/var/lib/rancher/conf/cloud-config.d" + CloudConfigInitFile = "/var/lib/rancher/conf/cloud-config.d/init.yml" CloudConfigBootFile = "/var/lib/rancher/conf/cloud-config.d/boot.yml" CloudConfigNetworkFile = "/var/lib/rancher/conf/cloud-config.d/network.yml" CloudConfigScriptFile = "/var/lib/rancher/conf/cloud-config-script" @@ -85,9 +86,9 @@ type Repository struct { type Repositories map[string]Repository type CloudConfig struct { - SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"` - WriteFiles []File `yaml:"write_files"` - Hostname string `yaml:"hostname"` + SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys,omitempty"` + WriteFiles []File `yaml:"write_files,omitempty"` + Hostname string `yaml:"hostname,omitempty"` Mounts [][]string `yaml:"mounts,omitempty"` Rancher RancherConfig `yaml:"rancher,omitempty"` Runcmd []yaml.StringandSlice `yaml:"runcmd,omitempty"` diff --git a/init/init.go b/init/init.go index 47594b28..4b61ee6f 100755 --- a/init/init.go +++ b/init/init.go @@ -227,6 +227,13 @@ func RunInit() error { func(c *config.CloudConfig) (*config.CloudConfig, error) { return c, dfs.PrepareFs(&mountConfig) }, + func(c *config.CloudConfig) (*config.CloudConfig, error) { + // will this be passed to cloud-init-save? + cmdLineArgs := strings.Join(os.Args, " ") + config.SaveInitCmdline(cmdLineArgs) + + return c, nil + }, mountOem, func(_ *config.CloudConfig) (*config.CloudConfig, error) { cfg := config.LoadConfig() @@ -303,6 +310,7 @@ func RunInit() error { }, func(cfg *config.CloudConfig) (*config.CloudConfig, error) { filesToCopy := []string{ + config.CloudConfigInitFile, config.CloudConfigBootFile, config.CloudConfigNetworkFile, config.MetaDataFile, diff --git a/scripts/run b/scripts/run index 5b401d10..5c008005 100755 --- a/scripts/run +++ b/scripts/run @@ -29,6 +29,10 @@ while [ "$#" -gt 0 ]; do shift 1 QEMU_APPEND="${QEMU_APPEND} $1" ;; + --append-init) + shift 1 + APPEND_INIT="${APPEND_INIT} $1" + ;; --memory) shift 1 MEMORY="$1" @@ -125,6 +129,9 @@ fi if [ "$RM_USR" == "1" ]; then KERNEL_ARGS="${KERNEL_ARGS} rancher.rm_usr" fi +if [ "$APPEND_INIT" != "" ]; then + KERNEL_ARGS="${KERNEL_ARGS} -- ${APPEND_INIT}" +fi if [ "$BOOT_PXE" == "1" ]; then sudo pixiecore boot \ diff --git a/tests/cmdline_test.go b/tests/cmdline_test.go new file mode 100755 index 00000000..ae53dbb4 --- /dev/null +++ b/tests/cmdline_test.go @@ -0,0 +1,15 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestElideCmdLine(c *C) { + runArgs := []string{ + "--fresh", + "--append-init", + "cc.hostname=nope rancher.debug=true", + } + s.RunQemuWith(c, runArgs...) + + s.CheckOutput(c, "nope\n", Equals, "hostname") + s.CheckOutput(c, "printk.devkmsg=on rancher.debug=true rancher.password=rancher console=ttyS0 rancher.autologin=ttyS0 rancher.state.dev=LABEL=RANCHER_STATE rancher.state.autoformat=[/dev/sda,/dev/vda] rancher.rm_usr -- \n", Equals, "cat /proc/cmdline") +}