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
  • Loading branch information
jmarrero committed Jan 20, 2022
1 parent 82a49c5 commit c052917
Show file tree
Hide file tree
Showing 2 changed files with 61 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
58 changes: 58 additions & 0 deletions config/fcos/v1_5_exp/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ package v1_5_exp

import (
"fmt"
"path/filepath"

baseutil "github.com/coreos/butane/base/util"
"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 +80,14 @@ func (c Config) ToIgn3_4Unvalidated(options common.TranslateOptions) (types.Conf
}
}
}

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

ret.Storage.Files = append(ret.Storage.Files, retp.Storage.Files...)

ts.Merge(tsp)
r.Merge(rp)

return ret, ts, r
}

Expand Down Expand Up @@ -292,3 +302,51 @@ 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", "inline")
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 := filepath.Join("/etc", "rpm-ostree-layer.yaml")

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

src, gzipped, err := baseutil.MakeDataURL([]byte(marshalledYAML), nil, options.NoResourceAutoCompression)
if err != nil || gzipped { //TODO: check for gziped somewhere else.
r.AddOnError(yamlPath, err)
return ret, r, ts
}
file.Contents.Source = util.StrToPtr(src)
mode := 0644
file.Mode = &mode

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

return ret, r, ts
}

0 comments on commit c052917

Please sign in to comment.