mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-17 15:27:58 +00:00
Allow creating dirs in rootfs via cc (#109)
This commit is contained in:
@@ -18,7 +18,10 @@ package action
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
config "github.com/kairos-io/kairos-agent/v2/pkg/config"
|
config "github.com/kairos-io/kairos-agent/v2/pkg/config"
|
||||||
|
cnst "github.com/kairos-io/kairos-agent/v2/pkg/constants"
|
||||||
"github.com/kairos-io/kairos-agent/v2/pkg/utils"
|
"github.com/kairos-io/kairos-agent/v2/pkg/utils"
|
||||||
|
fsutils "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs"
|
||||||
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Hook is RunStage wrapper that only adds logic to ignore errors
|
// Hook is RunStage wrapper that only adds logic to ignore errors
|
||||||
@@ -39,3 +42,15 @@ func ChrootHook(config *config.Config, hook string, chrootDir string, bindMounts
|
|||||||
}
|
}
|
||||||
return utils.ChrootedCallback(config, chrootDir, bindMounts, callback)
|
return utils.ChrootedCallback(config, chrootDir, bindMounts, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createExtraDirsInRootfs(cfg *config.Config, extradirs []string, target string) {
|
||||||
|
for _, d := range extradirs {
|
||||||
|
if exists, _ := fsutils.Exists(cfg.Fs, filepath.Join(target, d)); !exists {
|
||||||
|
cfg.Logger.Debugf("Creating extra dir %s under %s", d, target)
|
||||||
|
err := cfg.Fs.Mkdir(filepath.Join(target, d), cnst.DirPerm)
|
||||||
|
if err != nil {
|
||||||
|
cfg.Logger.Warnf("Failure creating extra dir %s in rootfs at %s", d, target)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -177,6 +177,9 @@ func (i InstallAction) Run() (err error) {
|
|||||||
}
|
}
|
||||||
cleanup.Push(func() error { return e.UnmountImage(&i.spec.Active) })
|
cleanup.Push(func() error { return e.UnmountImage(&i.spec.Active) })
|
||||||
|
|
||||||
|
// Create extra dirs in rootfs as afterwards this will be impossible due to RO system
|
||||||
|
createExtraDirsInRootfs(i.cfg, i.spec.ExtraDirsRootfs, i.spec.Active.MountPoint)
|
||||||
|
|
||||||
// Copy cloud-init if any
|
// Copy cloud-init if any
|
||||||
err = e.CopyCloudConfig(i.spec.CloudInit)
|
err = e.CopyCloudConfig(i.spec.CloudInit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -168,6 +168,9 @@ func (r ResetAction) Run() (err error) {
|
|||||||
}
|
}
|
||||||
cleanup.Push(func() error { return e.UnmountImage(&r.spec.Active) })
|
cleanup.Push(func() error { return e.UnmountImage(&r.spec.Active) })
|
||||||
|
|
||||||
|
// Create extra dirs in rootfs as afterwards this will be impossible due to RO system
|
||||||
|
createExtraDirsInRootfs(r.cfg, r.spec.ExtraDirsRootfs, r.spec.Active.MountPoint)
|
||||||
|
|
||||||
// install grub
|
// install grub
|
||||||
grub := utils.NewGrub(r.cfg)
|
grub := utils.NewGrub(r.cfg)
|
||||||
err = grub.Install(
|
err = grub.Install(
|
||||||
|
@@ -181,6 +181,9 @@ func (u *UpgradeAction) Run() (err error) {
|
|||||||
}
|
}
|
||||||
cleanup.Push(func() error { return e.UnmountImage(&upgradeImg) })
|
cleanup.Push(func() error { return e.UnmountImage(&upgradeImg) })
|
||||||
|
|
||||||
|
// Create extra dirs in rootfs as afterwards this will be impossible due to RO system
|
||||||
|
createExtraDirsInRootfs(u.config, u.spec.ExtraDirsRootfs, upgradeImg.MountPoint)
|
||||||
|
|
||||||
// Selinux relabel
|
// Selinux relabel
|
||||||
// Doesn't make sense to relabel a readonly filesystem
|
// Doesn't make sense to relabel a readonly filesystem
|
||||||
if upgradeImg.FS != constants.SquashFs {
|
if upgradeImg.FS != constants.SquashFs {
|
||||||
|
@@ -56,6 +56,7 @@ type InstallSpec struct {
|
|||||||
Tty string `yaml:"tty,omitempty" mapstructure:"tty"`
|
Tty string `yaml:"tty,omitempty" mapstructure:"tty"`
|
||||||
Reboot bool `yaml:"reboot,omitempty" mapstructure:"reboot"`
|
Reboot bool `yaml:"reboot,omitempty" mapstructure:"reboot"`
|
||||||
PowerOff bool `yaml:"poweroff,omitempty" mapstructure:"poweroff"`
|
PowerOff bool `yaml:"poweroff,omitempty" mapstructure:"poweroff"`
|
||||||
|
ExtraDirsRootfs []string `yaml:"extra-dirs-rootfs,omitempty" mapstructure:"extra-dirs-rootfs"`
|
||||||
Active Image `yaml:"system,omitempty" mapstructure:"system"`
|
Active Image `yaml:"system,omitempty" mapstructure:"system"`
|
||||||
Recovery Image `yaml:"recovery-system,omitempty" mapstructure:"recovery-system"`
|
Recovery Image `yaml:"recovery-system,omitempty" mapstructure:"recovery-system"`
|
||||||
Passive Image
|
Passive Image
|
||||||
@@ -109,9 +110,9 @@ type ResetSpec struct {
|
|||||||
FormatOEM bool `yaml:"reset-oem,omitempty" mapstructure:"reset-oem"`
|
FormatOEM bool `yaml:"reset-oem,omitempty" mapstructure:"reset-oem"`
|
||||||
Reboot bool `yaml:"reboot,omitempty" mapstructure:"reboot"`
|
Reboot bool `yaml:"reboot,omitempty" mapstructure:"reboot"`
|
||||||
PowerOff bool `yaml:"poweroff,omitempty" mapstructure:"poweroff"`
|
PowerOff bool `yaml:"poweroff,omitempty" mapstructure:"poweroff"`
|
||||||
|
|
||||||
GrubDefEntry string `yaml:"grub-entry-name,omitempty" mapstructure:"grub-entry-name"`
|
GrubDefEntry string `yaml:"grub-entry-name,omitempty" mapstructure:"grub-entry-name"`
|
||||||
Tty string `yaml:"tty,omitempty" mapstructure:"tty"`
|
Tty string `yaml:"tty,omitempty" mapstructure:"tty"`
|
||||||
|
ExtraDirsRootfs []string `yaml:"extra-dirs-rootfs,omitempty" mapstructure:"extra-dirs-rootfs"`
|
||||||
Active Image `yaml:"system,omitempty" mapstructure:"system"`
|
Active Image `yaml:"system,omitempty" mapstructure:"system"`
|
||||||
Passive Image
|
Passive Image
|
||||||
Partitions ElementalPartitions
|
Partitions ElementalPartitions
|
||||||
@@ -143,6 +144,7 @@ type UpgradeSpec struct {
|
|||||||
GrubDefEntry string `yaml:"grub-entry-name,omitempty" mapstructure:"grub-entry-name"`
|
GrubDefEntry string `yaml:"grub-entry-name,omitempty" mapstructure:"grub-entry-name"`
|
||||||
Reboot bool `yaml:"reboot,omitempty" mapstructure:"reboot"`
|
Reboot bool `yaml:"reboot,omitempty" mapstructure:"reboot"`
|
||||||
PowerOff bool `yaml:"poweroff,omitempty" mapstructure:"poweroff"`
|
PowerOff bool `yaml:"poweroff,omitempty" mapstructure:"poweroff"`
|
||||||
|
ExtraDirsRootfs []string `yaml:"extra-dirs-rootfs,omitempty" mapstructure:"extra-dirs-rootfs"`
|
||||||
Passive Image
|
Passive Image
|
||||||
Partitions ElementalPartitions
|
Partitions ElementalPartitions
|
||||||
State *InstallState
|
State *InstallState
|
||||||
|
Reference in New Issue
Block a user