Skip to content

Commit

Permalink
stage(kickstart): rename constructors
Browse files Browse the repository at this point in the history
The constructor is going to grow very unwieldy very quickly. Introduce
constructors for common usecases.
  • Loading branch information
supakeen authored and achilleas-k committed Dec 8, 2023
1 parent 6e3d599 commit 8b3eab7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 23 deletions.
7 changes: 2 additions & 5 deletions pkg/manifest/anaconda_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,11 @@ func (p *AnacondaInstaller) serialize() osbuild.Pipeline {

if p.Type == AnacondaInstallerTypePayload {
if p.InteractiveDefaults != nil {
kickstartOptions, err := osbuild.NewKickstartStageOptions(
kickstartOptions, err := osbuild.NewKickstartStageOptionsWithLiveIMG(
"/usr/share/anaconda/interactive-defaults.ks",
p.InteractiveDefaults.TarPath,
p.Users,
p.Groups,
"",
"",
"",
p.InteractiveDefaults.TarPath,
)

if err != nil {
Expand Down
15 changes: 13 additions & 2 deletions pkg/manifest/anaconda_installer_iso_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,13 @@ func (p *AnacondaInstallerISOTree) serialize() osbuild.Pipeline {
))

// Configure the kickstart file with the payload and any user options
kickstartOptions, err := osbuild.NewKickstartStageOptions(p.KSPath, "", p.Users, p.Groups, makeISORootPath(p.PayloadPath), p.ostreeCommitSpec.Ref, p.OSName)
kickstartOptions, err := osbuild.NewKickstartStageOptionsWithOSTreeCommit(
p.KSPath,
p.Users,
p.Groups,
makeISORootPath(p.PayloadPath),
p.ostreeCommitSpec.Ref,
p.OSName)

if err != nil {
panic("failed to create kickstartstage options")
Expand All @@ -288,7 +294,12 @@ func (p *AnacondaInstallerISOTree) serialize() osbuild.Pipeline {
// If the KSPath is set, we need to add the kickstart stage to this (bootiso-tree) pipeline.
// If it's not specified here, it should have been added to the InteractiveDefaults in the anaconda-tree.
if p.KSPath != "" {
kickstartOptions, err := osbuild.NewKickstartStageOptions(p.KSPath, makeISORootPath(p.PayloadPath), p.Users, p.Groups, "", "", p.OSName)
kickstartOptions, err := osbuild.NewKickstartStageOptionsWithLiveIMG(
p.KSPath,
p.Users,
p.Groups,
makeISORootPath(p.PayloadPath))

if err != nil {
panic("failed to create kickstartstage options")
}
Expand Down
62 changes: 46 additions & 16 deletions pkg/osbuild/kickstart_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ func NewKickstartStage(options *KickstartStageOptions) *Stage {

func NewKickstartStageOptions(
path string,
imageURL string,
userCustomizations []users.User,
groupCustomizations []users.Group,
ostreeURL string,
ostreeRef string,
osName string) (*KickstartStageOptions, error) {
groupCustomizations []users.Group) (*KickstartStageOptions, error) {

var users map[string]UsersStageOptionsUser
if usersOptions, err := NewUsersStageOptions(userCustomizations, false); err != nil {
Expand All @@ -57,27 +53,61 @@ func NewKickstartStageOptions(
groups = groupsOptions.Groups
}

var ostreeCommitOptions *OSTreeCommitOptions
return &KickstartStageOptions{
Path: path,
OSTreeCommit: nil,
LiveIMG: nil,
Users: users,
Groups: groups,
}, nil
}

func NewKickstartStageOptionsWithOSTreeCommit(
path string,
userCustomizations []users.User,
groupCustomizations []users.Group,
ostreeURL string,
ostreeRef string,
osName string) (*KickstartStageOptions, error) {

options, err := NewKickstartStageOptions(path, userCustomizations, groupCustomizations)

if err != nil {
return nil, err
}

if ostreeURL != "" {
ostreeCommitOptions = &OSTreeCommitOptions{
ostreeCommitOptions := &OSTreeCommitOptions{
OSName: osName,
URL: ostreeURL,
Ref: ostreeRef,
GPG: false,
}

options.OSTreeCommit = ostreeCommitOptions
}

return options, nil
}

func NewKickstartStageOptionsWithLiveIMG(
path string,
userCustomizations []users.User,
groupCustomizations []users.Group,
imageURL string) (*KickstartStageOptions, error) {

options, err := NewKickstartStageOptions(path, userCustomizations, groupCustomizations)

if err != nil {
return nil, err
}

var liveImg *LiveIMGOptions
if imageURL != "" {
liveImg = &LiveIMGOptions{
liveImg := &LiveIMGOptions{
URL: imageURL,
}
options.LiveIMG = liveImg
}
return &KickstartStageOptions{
Path: path,
OSTreeCommit: ostreeCommitOptions,
LiveIMG: liveImg,
Users: users,
Groups: groups,
}, nil

return options, nil
}

0 comments on commit 8b3eab7

Please sign in to comment.