Skip to content

Commit

Permalink
wire ignition
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Murdaca <antoniomurdaca@gmail.com>
  • Loading branch information
runcom committed Jan 11, 2023
1 parent 35c93de commit 49f5e5a
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 46 deletions.
4 changes: 2 additions & 2 deletions internal/blueprint/customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type IgnitionCustomization struct {

type EmbeddedIgnitionCustomization struct {
ProvisioningURL string `json:"url,omitempty" toml:"url,omitempty"`
Data64 string `json:"data,omitempty" toml:"data,omitempty"`
Config string `json:"config,omitempty" toml:"config,omitempty"`
}

type FirstBootIgnitionCustomization struct {
Expand Down Expand Up @@ -421,7 +421,7 @@ func (c *EmbeddedIgnitionCustomization) CheckEmbeddedIgnition() error {
if c == nil {
return nil
}
if c.Data64 != "" && c.ProvisioningURL != "" {
if c.Config != "" && c.ProvisioningURL != "" {
t := reflect.TypeOf(*c)
return &CustomizationError{fmt.Sprintf("'%s' and '%s' are not allowed at the same time", t.Field(0).Name, t.Field(1).Name)}
}
Expand Down
13 changes: 9 additions & 4 deletions internal/distro/rhel9/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ func edgeSimplifiedInstallerImage(workload workload.Workload,

rawImg.Filename = t.Filename()

if bpIgnition := customizations.GetIgnition(); bpIgnition != nil && bpIgnition.FirstBoot != nil && bpIgnition.FirstBoot.ProvisioningURL != "" {
rawImg.KernelOptionsAppend = append(rawImg.KernelOptionsAppend, "ignition.config.url="+bpIgnition.FirstBoot.ProvisioningURL)
}

// 92+ only
if kopts := customizations.GetKernel(); kopts != nil {
rawImg.KernelOptionsAppend = append(rawImg.KernelOptionsAppend, kopts.Append)
Expand All @@ -427,11 +431,12 @@ func edgeSimplifiedInstallerImage(workload workload.Workload,
}
// ignition configs from blueprint
if bpIgnition := customizations.GetIgnition(); bpIgnition != nil {
if bpIgnition.FirstBoot != nil {
img.IgnitionFirstBoot = ignition.FirstbootOptionsFromBP(*bpIgnition.FirstBoot)
}
if bpIgnition.Embedded != nil {
img.IgnitionEmbedded = ignition.EmbeddedOptionsFromBP(*bpIgnition.Embedded)
var err error
img.IgnitionEmbedded, err = ignition.EmbeddedOptionsFromBP(*bpIgnition.Embedded)
if err != nil {
return nil, err
}
}
}

Expand Down
21 changes: 16 additions & 5 deletions internal/ignition/ignition.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package ignition

import "github.com/osbuild/osbuild-composer/internal/blueprint"
import (
"encoding/base64"
"errors"

"github.com/osbuild/osbuild-composer/internal/blueprint"
)

type FirstBootOptions struct {
ProvisioningURL string
Expand All @@ -13,10 +18,16 @@ func FirstbootOptionsFromBP(bpIgnitionFirstboot blueprint.FirstBootIgnitionCusto

type EmbeddedOptions struct {
ProvisioningURL string
Data64 string
Config string
}

func EmbeddedOptionsFromBP(bpIgnitionEmbedded blueprint.EmbeddedIgnitionCustomization) *EmbeddedOptions {
ignition := EmbeddedOptions(bpIgnitionEmbedded)
return &ignition
func EmbeddedOptionsFromBP(bpIgnitionEmbedded blueprint.EmbeddedIgnitionCustomization) (*EmbeddedOptions, error) {
decodedConfig, err := base64.StdEncoding.DecodeString(bpIgnitionEmbedded.Config)
if err != nil {
return nil, errors.New("can't decode Ignition config")
}
return &EmbeddedOptions{
ProvisioningURL: bpIgnitionEmbedded.ProvisioningURL,
Config: string(decodedConfig),
}, nil
}
5 changes: 0 additions & 5 deletions internal/image/ostree_simplified_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ func (img *OSTreeSimplifiedInstaller) InstantiateManifest(m *manifest.Manifest,
}
}

// ignition firstboot options
if img.IgnitionFirstBoot != nil {
kernelOpts = append(kernelOpts, "coreos.inst.append ignition.config.url="+img.IgnitionFirstBoot.ProvisioningURL)
}

bootTreePipeline.KernelOpts = kernelOpts

rootfsPartitionTable := &disk.PartitionTable{
Expand Down
4 changes: 2 additions & 2 deletions internal/manifest/coi_iso_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func (p *CoreOSISOTree) serialize() osbuild.Pipeline {
copyInput := ""
// These specific filenames in the root of the ISO are expected by
// coreos-installer-dracut during installation
if p.coiPipeline.Ignition.Data64 != "" {
if p.coiPipeline.Ignition.Config != "" {
filename = "ignition_config"
copyInput = p.coiPipeline.Ignition.Data64
copyInput = p.coiPipeline.Ignition.Config
} else {
filename = "ignition_url"
copyInput = p.coiPipeline.Ignition.ProvisioningURL
Expand Down
4 changes: 2 additions & 2 deletions internal/manifest/coreos_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func (p *CoreOSInstaller) getInline() []string {
}
// inline data for ignition embedded (url or data)
if p.Ignition != nil {
if p.Ignition.Data64 != "" {
inlineData = append(inlineData, p.Ignition.Data64)
if p.Ignition.Config != "" {
inlineData = append(inlineData, p.Ignition.Config)
} else {
inlineData = append(inlineData, p.Ignition.ProvisioningURL)
}
Expand Down
Loading

0 comments on commit 49f5e5a

Please sign in to comment.