mirror of
https://github.com/rancher/os.git
synced 2025-09-01 06:40:31 +00:00
Use the kernel cmdline elide patch to load config into RancherOS that isn't visible in /pro/cmdline
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
0
config/config_test.go
Normal file → Executable file
0
config/config_test.go
Normal file → Executable file
0
config/data_funcs.go
Normal file → Executable file
0
config/data_funcs.go
Normal file → Executable file
11
config/disk.go
Normal file → Executable file
11
config/disk.go
Normal file → Executable file
@@ -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)
|
||||
|
||||
|
@@ -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"`
|
||||
|
@@ -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,
|
||||
|
@@ -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 \
|
||||
|
15
tests/cmdline_test.go
Executable file
15
tests/cmdline_test.go
Executable file
@@ -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")
|
||||
}
|
Reference in New Issue
Block a user