Skip to content
Closed
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
8 changes: 8 additions & 0 deletions pkg/asset/ignition/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ func (a *Bootstrap) Generate(dependencies asset.Parents) error {
if err != nil {
return errors.Wrap(err, "failed to Marshal Ignition config")
}

if installConfig.Config.Spec3 == true {
data, err = ignition.ConvertSpec2ToSpec3(data)
if err != nil {
return err
}
}

a.File = &asset.File{
Filename: bootstrapIgnFilename,
Data: data,
Expand Down
9 changes: 9 additions & 0 deletions pkg/asset/ignition/machine/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/ignition"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/tls"
)
Expand Down Expand Up @@ -44,6 +45,14 @@ func (a *Master) Generate(dependencies asset.Parents) error {
if err != nil {
return errors.Wrap(err, "failed to marshal Ignition config")
}

if installConfig.Config.Spec3 == true {
data, err = ignition.ConvertSpec2ToSpec3(data)
if err != nil {
return err
}
}

a.File = &asset.File{
Filename: masterIgnFilename,
Data: data,
Expand Down
9 changes: 9 additions & 0 deletions pkg/asset/ignition/machine/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/ignition"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/tls"
)
Expand Down Expand Up @@ -44,6 +45,14 @@ func (a *Worker) Generate(dependencies asset.Parents) error {
if err != nil {
return errors.Wrap(err, "failed to marshal Ignition config")
}

if installConfig.Config.Spec3 == true {
data, err = ignition.ConvertSpec2ToSpec3(data)
if err != nil {
return err
}
}

a.File = &asset.File{
Filename: workerIgnFilename,
Data: data,
Expand Down
74 changes: 74 additions & 0 deletions pkg/asset/ignition/spec2to3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package ignition

import (
"encoding/json"

"github.com/pkg/errors"
)

// ConvertSpec2ToSpec3 converts Ignition spec2 to ignition spec3
func ConvertSpec2ToSpec3(spec2data []byte) ([]byte, error) {
// Unmarshal
jsonMap := make(map[string]interface{})
err := json.Unmarshal(spec2data, &jsonMap)
if err != nil {
return nil, errors.Wrap(err, "failed to Marshal Ignition config")
}

// Replace ignition.version
ign := jsonMap["ignition"].(map[string]interface{})
ign["version"] = "3.0.0"

// ignition.config.append -> ignition.config.merge
config := ign["config"].(map[string]interface{})
if val, ok := config["append"]; ok {
config["merge"] = val
delete(config, "append")
}
ign["config"] = config
jsonMap["ignition"] = ign

// Delete networkd section
if _, ok := jsonMap["networkd"]; ok {
delete(jsonMap, "networkd")
}

// Modify storage.files
if sval, ok := jsonMap["storage"]; ok {
storage := sval.(map[string]interface{})

if fval, ok := storage["files"]; ok {
files := fval.([]interface{})

updatedFiles := make([]interface{}, 0)

for i := range files {
file := files[i].(map[string]interface{})
// Remove filesystem
if _, ok := file["filesystem"]; ok {
delete(file, "filesystem")
}
// append is no longer a flag
if val, ok := file["append"]; ok {
if val == "true" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be val == true.

Context, had a try to run OKD4 on FCOS today. Had to fix this, but next bump will be "failed to unmarshal bootstrap.ign: json: cannot unmarshal object into Go struct field File.append of type bool" as it tries to reread the config at some point and uses the old v2_2 config as template. There doesn't seem to be easy fix for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the installer would still use v2 ignition when creating new S3 buckets via terraform.

It doesn't look like installer can support both spec2 and spec3

if contentsval, ok := file["contents"]; ok {
file["append"] = contentsval
delete(file, "contents")
}
}
}

updatedFiles = append(updatedFiles, file)
}
storage["files"] = updatedFiles
}
jsonMap["storage"] = storage
}

// Convert to bytes
spec3data, err := json.Marshal(jsonMap)
if err != nil {
return nil, errors.Wrap(err, "failed to Marshal Ignition config")
}
return spec3data, nil
}
4 changes: 4 additions & 0 deletions pkg/types/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ type InstallConfig struct {

// ImageContentSources lists sources/repositories for the release-image content.
ImageContentSources []ImageContentSource `json:"imageContentSources,omitempty"`

// Spec3 is a flag to convert Ignition in spec3
// +optional
Spec3 bool `json:"spec3,omitempty"`
}

// ClusterDomain returns the DNS domain that all records for a cluster must belong to.
Expand Down