Allow creating dirs in rootfs via cc (#109)

This commit is contained in:
Itxaka
2023-08-02 19:11:25 +02:00
committed by GitHub
parent a28acbf63a
commit f5f3d3f221
5 changed files with 46 additions and 20 deletions

View File

@@ -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)
}
}
}
}

View File

@@ -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 {

View File

@@ -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(

View File

@@ -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 {

View File

@@ -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
@@ -105,20 +106,20 @@ func (i *InstallSpec) ShouldShutdown() bool { return i.PowerOff }
// ResetSpec struct represents all the reset action details // ResetSpec struct represents all the reset action details
type ResetSpec struct { type ResetSpec struct {
FormatPersistent bool `yaml:"reset-persistent,omitempty" mapstructure:"reset-persistent"` FormatPersistent bool `yaml:"reset-persistent,omitempty" mapstructure:"reset-persistent"`
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
Target string Target string
Efi bool Efi bool
GrubConf string GrubConf string
State *InstallState State *InstallState
} }
// Sanitize checks the consistency of the struct, returns error // Sanitize checks the consistency of the struct, returns error
@@ -137,12 +138,13 @@ func (r *ResetSpec) ShouldReboot() bool { return r.Reboot }
func (r *ResetSpec) ShouldShutdown() bool { return r.PowerOff } func (r *ResetSpec) ShouldShutdown() bool { return r.PowerOff }
type UpgradeSpec struct { type UpgradeSpec struct {
RecoveryUpgrade bool `yaml:"recovery,omitempty" mapstructure:"recovery"` RecoveryUpgrade bool `yaml:"recovery,omitempty" mapstructure:"recovery"`
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"`
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