Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand DeployImage to be more flexible #635

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
jimmykarily marked this conversation as resolved.
Show resolved Hide resolved
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
Loading