mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-05-10 09:24:47 +00:00
Expand DeployImage to be more flexible (#635)
Usually we create the system dirs in images by default, but that means that we cannot reuse the DeployImage for deploying random non-system images. This fixes it by adding an extra param to create the dir structure in the created image Signed-off-by: Itxaka <itxaka@kairos.io>
This commit is contained in:
parent
92ca5a6d53
commit
a5a55c636d
pkg
@ -308,7 +308,23 @@ func (e Elemental) CreateFileSystemImage(img *v1.Image) error {
|
||||
|
||||
// DeployImage will deploy the given image into the target. This method
|
||||
// creates the filesystem image file, mounts it and unmounts it as needed.
|
||||
// Creates the default system dirs by default (/sys,/proc,/dev, etc...)
|
||||
func (e *Elemental) DeployImage(img *v1.Image, leaveMounted bool) (info interface{}, err error) {
|
||||
return e.deployImage(img, leaveMounted, true)
|
||||
}
|
||||
|
||||
// DeployImageNodirs will deploy the given image into the target. This method
|
||||
// creates the filesystem image file, mounts it and unmounts it as needed.
|
||||
// Does not create the default system dirs so it can be used to create generic images from any source
|
||||
func (e *Elemental) DeployImageNodirs(img *v1.Image, leaveMounted bool) (info interface{}, err error) {
|
||||
return e.deployImage(img, leaveMounted, false)
|
||||
}
|
||||
|
||||
// deployImage is the real function that does the actual work
|
||||
// Set leaveMounted to leave the image mounted, otherwise it unmounts before returning
|
||||
// Set createDirStructure to create the directory structure in the target, which creates the expected dirs
|
||||
// for a running system. This is so we can reuse this method for creating random images, not only system ones
|
||||
func (e *Elemental) deployImage(img *v1.Image, leaveMounted, createDirStructure bool) (info interface{}, err error) {
|
||||
target := img.MountPoint
|
||||
if !img.Source.IsFile() {
|
||||
if img.FS != cnst.SquashFs {
|
||||
@ -338,9 +354,11 @@ func (e *Elemental) DeployImage(img *v1.Image, leaveMounted bool) (info interfac
|
||||
return nil, err
|
||||
}
|
||||
if !img.Source.IsFile() {
|
||||
err = utils.CreateDirStructure(e.config.Fs, target)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if createDirStructure {
|
||||
err = utils.CreateDirStructure(e.config.Fs, target)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if img.FS == cnst.SquashFs {
|
||||
squashOptions := append(cnst.GetDefaultSquashfsOptions(), e.config.SquashFsCompressionConfig...)
|
||||
|
@ -46,6 +46,9 @@ func NewGrub(config *agentConfig.Config) *Grub {
|
||||
}
|
||||
|
||||
// Install installs grub into the device, copy the config file and add any extra TTY to grub
|
||||
// TODO: Make it more generic to be able to call it from other places
|
||||
// i.e.: filepath.Join(cnst.ActiveDir, "etc/kairos-release") seraches for the file in the active dir, we should be looking into the rootdir?
|
||||
// filepath.Join(cnst.EfiDir, "EFI/boot/grub.cfg") we also write into the efi dir directly, this should be the a var maybe?
|
||||
func (g Grub) Install(target, rootDir, bootDir, grubConf, tty string, efi bool, stateLabel string) (err error) { // nolint:gocyclo
|
||||
var grubargs []string
|
||||
var grubdir, finalContent string
|
||||
|
Loading…
Reference in New Issue
Block a user