mirror of
https://github.com/rancher/os.git
synced 2025-09-01 23:04:41 +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
|
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 {
|
func CloudConfigDirFiles(dirPrefix string) []string {
|
||||||
cloudConfigDir := path.Join(dirPrefix, CloudConfigDir)
|
cloudConfigDir := path.Join(dirPrefix, CloudConfigDir)
|
||||||
|
|
||||||
|
@@ -40,6 +40,7 @@ const (
|
|||||||
OsConfigFile = "/usr/share/ros/os-config.yml"
|
OsConfigFile = "/usr/share/ros/os-config.yml"
|
||||||
VarRancherDir = "/var/lib/rancher"
|
VarRancherDir = "/var/lib/rancher"
|
||||||
CloudConfigDir = "/var/lib/rancher/conf/cloud-config.d"
|
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"
|
CloudConfigBootFile = "/var/lib/rancher/conf/cloud-config.d/boot.yml"
|
||||||
CloudConfigNetworkFile = "/var/lib/rancher/conf/cloud-config.d/network.yml"
|
CloudConfigNetworkFile = "/var/lib/rancher/conf/cloud-config.d/network.yml"
|
||||||
CloudConfigScriptFile = "/var/lib/rancher/conf/cloud-config-script"
|
CloudConfigScriptFile = "/var/lib/rancher/conf/cloud-config-script"
|
||||||
@@ -85,9 +86,9 @@ type Repository struct {
|
|||||||
type Repositories map[string]Repository
|
type Repositories map[string]Repository
|
||||||
|
|
||||||
type CloudConfig struct {
|
type CloudConfig struct {
|
||||||
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
|
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys,omitempty"`
|
||||||
WriteFiles []File `yaml:"write_files"`
|
WriteFiles []File `yaml:"write_files,omitempty"`
|
||||||
Hostname string `yaml:"hostname"`
|
Hostname string `yaml:"hostname,omitempty"`
|
||||||
Mounts [][]string `yaml:"mounts,omitempty"`
|
Mounts [][]string `yaml:"mounts,omitempty"`
|
||||||
Rancher RancherConfig `yaml:"rancher,omitempty"`
|
Rancher RancherConfig `yaml:"rancher,omitempty"`
|
||||||
Runcmd []yaml.StringandSlice `yaml:"runcmd,omitempty"`
|
Runcmd []yaml.StringandSlice `yaml:"runcmd,omitempty"`
|
||||||
|
@@ -227,6 +227,13 @@ func RunInit() error {
|
|||||||
func(c *config.CloudConfig) (*config.CloudConfig, error) {
|
func(c *config.CloudConfig) (*config.CloudConfig, error) {
|
||||||
return c, dfs.PrepareFs(&mountConfig)
|
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,
|
mountOem,
|
||||||
func(_ *config.CloudConfig) (*config.CloudConfig, error) {
|
func(_ *config.CloudConfig) (*config.CloudConfig, error) {
|
||||||
cfg := config.LoadConfig()
|
cfg := config.LoadConfig()
|
||||||
@@ -303,6 +310,7 @@ func RunInit() error {
|
|||||||
},
|
},
|
||||||
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
||||||
filesToCopy := []string{
|
filesToCopy := []string{
|
||||||
|
config.CloudConfigInitFile,
|
||||||
config.CloudConfigBootFile,
|
config.CloudConfigBootFile,
|
||||||
config.CloudConfigNetworkFile,
|
config.CloudConfigNetworkFile,
|
||||||
config.MetaDataFile,
|
config.MetaDataFile,
|
||||||
|
@@ -29,6 +29,10 @@ while [ "$#" -gt 0 ]; do
|
|||||||
shift 1
|
shift 1
|
||||||
QEMU_APPEND="${QEMU_APPEND} $1"
|
QEMU_APPEND="${QEMU_APPEND} $1"
|
||||||
;;
|
;;
|
||||||
|
--append-init)
|
||||||
|
shift 1
|
||||||
|
APPEND_INIT="${APPEND_INIT} $1"
|
||||||
|
;;
|
||||||
--memory)
|
--memory)
|
||||||
shift 1
|
shift 1
|
||||||
MEMORY="$1"
|
MEMORY="$1"
|
||||||
@@ -125,6 +129,9 @@ fi
|
|||||||
if [ "$RM_USR" == "1" ]; then
|
if [ "$RM_USR" == "1" ]; then
|
||||||
KERNEL_ARGS="${KERNEL_ARGS} rancher.rm_usr"
|
KERNEL_ARGS="${KERNEL_ARGS} rancher.rm_usr"
|
||||||
fi
|
fi
|
||||||
|
if [ "$APPEND_INIT" != "" ]; then
|
||||||
|
KERNEL_ARGS="${KERNEL_ARGS} -- ${APPEND_INIT}"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$BOOT_PXE" == "1" ]; then
|
if [ "$BOOT_PXE" == "1" ]; then
|
||||||
sudo pixiecore boot \
|
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