Skip to content

Commit

Permalink
wire ignition bp customization to simplified-installer and raw image
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Murdaca <[email protected]>
  • Loading branch information
runcom committed Jan 13, 2023
1 parent 4485a14 commit bc83ce2
Show file tree
Hide file tree
Showing 7 changed files with 323 additions and 82 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
21 changes: 13 additions & 8 deletions internal/distro/rhel9/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ func edgeCommitImage(workload workload.Workload,

img.Platform = t.platform
img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], options, containers, customizations)
if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || !common.VersionLessThan(t.arch.distro.osVersion, "9-stream") {
img.OSCustomizations.EnabledServices = append(img.OSCustomizations.EnabledServices, "ignition-firstboot-complete.service", "coreos-ignition-write-issues", "coreos-ignition-write-issues")
if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || t.arch.distro.osVersion == "9-stream" {
img.OSCustomizations.EnabledServices = append(img.OSCustomizations.EnabledServices, "ignition-firstboot-complete.service", "coreos-ignition-write-issues.service")
}
img.Environment = t.environment
img.Workload = workload
Expand Down Expand Up @@ -247,8 +247,8 @@ func edgeContainerImage(workload workload.Workload,

img.Platform = t.platform
img.OSCustomizations = osCustomizations(t, packageSets[osPkgsKey], options, containers, customizations)
if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || !common.VersionLessThan(t.arch.distro.osVersion, "9-stream") {
img.OSCustomizations.EnabledServices = append(img.OSCustomizations.EnabledServices, "ignition-firstboot-complete.service", "coreos-ignition-write-issues", "coreos-ignition-write-issues")
if !common.VersionLessThan(t.arch.distro.osVersion, "9.2") || t.arch.distro.osVersion == "9-stream" {
img.OSCustomizations.EnabledServices = append(img.OSCustomizations.EnabledServices, "ignition-firstboot-complete.service", "coreos-ignition-write-issues.service")
}
img.ContainerLanguage = img.OSCustomizations.Language
img.Environment = t.environment
Expand Down Expand Up @@ -421,6 +421,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 && kopts.Append != "" {
rawImg.KernelOptionsAppend = append(rawImg.KernelOptionsAppend, kopts.Append)
Expand All @@ -436,11 +440,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 bc83ce2

Please sign in to comment.