Skip to content

Commit

Permalink
Expand DeployImage to be more flexible (#635)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Itxaka authored Dec 17, 2024
1 parent 92ca5a6 commit a5a55c6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
24 changes: 21 additions & 3 deletions pkg/elemental/elemental.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)
Expand Down
3 changes: 3 additions & 0 deletions pkg/utils/grub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a5a55c6

Please sign in to comment.