Skip to content

Commit

Permalink
config/fcos: Add extensions param and generate treefile with packages
Browse files Browse the repository at this point in the history
s
  • Loading branch information
jmarrero committed Jan 20, 2022
1 parent 82a49c5 commit 416b7b3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/fcos/v1_5_exp/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
type Config struct {
base.Config `yaml:",inline"`
BootDevice BootDevice `yaml:"boot_device"`
Extentions Extensions `yaml:"extensions"`
}

type BootDevice struct {
Expand All @@ -38,3 +39,5 @@ type BootDeviceLuks struct {
type BootDeviceMirror struct {
Devices []string `yaml:"devices"`
}

type Extensions []string
62 changes: 62 additions & 0 deletions config/fcos/v1_5_exp/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/coreos/butane/config/common"
cutil "github.com/coreos/butane/config/util"
"github.com/coreos/butane/translate"
"gopkg.in/yaml.v3"

"github.com/coreos/ignition/v2/config/util"
"github.com/coreos/ignition/v2/config/v3_4_experimental/types"
Expand Down Expand Up @@ -78,6 +79,15 @@ func (c Config) ToIgn3_4Unvalidated(options common.TranslateOptions) (types.Conf
}
}
}

retp, rp, tsp := c.processPackages(options)

retConfig, retTranslations := baseutil.MergeTranslatedConfigs(retp, tsp, ret, ts)
ret = retConfig.(types.Config)
ts = retTranslations

r.Merge(rp)

return ret, ts, r
}

Expand Down Expand Up @@ -292,3 +302,55 @@ func translateBootDeviceLuks(from BootDeviceLuks, options common.TranslateOption
tm.AddTranslation(path.New("yaml"), path.New("json"))
return
}

func (c Config) processPackages(options common.TranslateOptions) (types.Config, report.Report, translate.TranslationSet) {
yamlPath := path.New("yaml", "extensions")

ret := types.Config{}
ts := translate.NewTranslationSet("yaml", "json")
var r report.Report

if len(c.Extentions) == 0 {
return ret, r, ts
}

type TreeFile struct {
Packages []string `yaml:"packages"`
}

p := TreeFile{
Packages: c.Extentions,
}

marshalledYAML, err := yaml.Marshal(&p)

if err != nil {
r.AddOnError(yamlPath, err)
return ret, r, ts
}

treeFilePath := "/etc/rpm-ostree-layer.yaml"

file := types.File{
Node: types.Node{
Path: treeFilePath,
},
}

src, gzipped, err := baseutil.MakeDataURL([]byte(marshalledYAML), file.Contents.Compression, !options.NoResourceAutoCompression)
if err != nil {
r.AddOnError(yamlPath, err)
return ret, r, ts
}
if gzipped {
file.Contents.Compression = util.StrToPtr("gzip")
}
file.Contents.Source = util.StrToPtr(src)

file.Mode = util.IntToPtr(0644)

ret.Storage.Files = append(ret.Storage.Files, file)
ts.AddFromCommonSource(yamlPath, path.New("json", "storage", "files", 0), file)

return ret, r, ts
}

0 comments on commit 416b7b3

Please sign in to comment.