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 365d663
Show file tree
Hide file tree
Showing 2 changed files with 58 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
55 changes: 55 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.v2"

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

ret1, _, _ := c.processPackages(options)

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

return ret, ts, r
}

Expand Down Expand Up @@ -292,3 +299,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 365d663

Please sign in to comment.