-
Notifications
You must be signed in to change notification settings - Fork 72
base/v0_6_exp: add parent directory sugar #508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,9 +83,7 @@ func (c Config) ToIgn3_5Unvalidated(options common.TranslateOptions) (types.Conf | |
|
||
tr := translate.NewTranslator("yaml", "json", options) | ||
tr.AddCustomTranslator(translateIgnition) | ||
tr.AddCustomTranslator(translateFile) | ||
tr.AddCustomTranslator(translateDirectory) | ||
tr.AddCustomTranslator(translateLink) | ||
tr.AddCustomTranslator(translateStorage) | ||
tr.AddCustomTranslator(translateResource) | ||
tr.AddCustomTranslator(translatePasswdUser) | ||
tr.AddCustomTranslator(translateUnit) | ||
|
@@ -99,7 +97,6 @@ func (c Config) ToIgn3_5Unvalidated(options common.TranslateOptions) (types.Conf | |
translate.MergeP(tr, tm, &r, "systemd", &c.Systemd, &ret.Systemd) | ||
|
||
c.addMountUnits(&ret, &tm) | ||
|
||
tm2, r2 := c.processTrees(&ret, options) | ||
tm.Merge(tm2) | ||
r.Merge(r2) | ||
|
@@ -121,6 +118,65 @@ func translateIgnition(from Ignition, options common.TranslateOptions) (to types | |
return | ||
} | ||
|
||
func translateStorage(from Storage, options common.TranslateOptions) (to types.Storage, tm translate.TranslationSet, r report.Report) { | ||
tr := translate.NewTranslator("yaml", "json", options) | ||
tr.AddCustomTranslator(translateFile) | ||
tr.AddCustomTranslator(translateDirectory) | ||
tr.AddCustomTranslator(translateLink) | ||
tr.AddCustomTranslator(translateLuks) | ||
tm, r = translate.Prefixed(tr, "directories", &from.Directories, &to.Directories) | ||
translate.MergeP(tr, tm, &r, "disks", &from.Disks, &to.Disks) | ||
translate.MergeP(tr, tm, &r, "files", &from.Files, &to.Files) | ||
translate.MergeP(tr, tm, &r, "filesystems", &from.Filesystems, &to.Filesystems) | ||
translate.MergeP(tr, tm, &r, "links", &from.Links, &to.Links) | ||
translate.MergeP(tr, tm, &r, "luks", &from.Luks, &to.Luks) | ||
translate.MergeP(tr, tm, &r, "raid", &from.Raid, &to.Raid) | ||
Comment on lines
+128
to
+133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there precedence for other sugar we have in Butane which ends up having to relist every other section at the level it's operating at? |
||
for i, file := range from.Files { | ||
if util.NotEmpty(file.Parent.Path) { | ||
var dir string | ||
|
||
yamlPath := path.New("yaml", "files", i, "parent") | ||
|
||
if !strings.Contains(file.Path, *file.Parent.Path) { | ||
r.AddOnError(yamlPath, common.ErrInvalidParent) | ||
continue | ||
} | ||
|
||
dir = filepath.Dir(file.Path) | ||
dir = filepath.ToSlash(dir) | ||
|
||
fmt.Println("Final Directory:", dir) | ||
|
||
for dir != "" { | ||
renderedDir := types.Directory{ | ||
Node: types.Node{ | ||
Path: dir, | ||
Group: types.NodeGroup{ID: file.Group.ID, Name: file.Group.Name}, | ||
User: types.NodeUser{ID: file.User.ID, Name: file.User.Name}, | ||
}, | ||
DirectoryEmbedded1: types.DirectoryEmbedded1{ | ||
Mode: file.Parent.Mode, | ||
}, | ||
} | ||
to.Directories = append(to.Directories, renderedDir) | ||
nextDir, _ := filepath.Split(dir) | ||
// make sure to clean the path to avoid consistency issues | ||
|
||
if dir == *file.Parent.Path || nextDir == dir { | ||
// we have reached the parent directory or the end of the path | ||
break | ||
} | ||
// Remove trailing / for consistency on matching directories | ||
dir = strings.TrimSuffix(nextDir, "/") | ||
dir = filepath.ToSlash(dir) | ||
} | ||
tm.AddFromCommonSource(yamlPath, path.New("json", "directories"), to.Directories) | ||
} | ||
|
||
} | ||
return | ||
} | ||
|
||
func translateFile(from File, options common.TranslateOptions) (to types.File, tm translate.TranslationSet, r report.Report) { | ||
tr := translate.NewTranslator("yaml", "json", options) | ||
tr.AddCustomTranslator(translateResource) | ||
|
@@ -134,6 +190,22 @@ func translateFile(from File, options common.TranslateOptions) (to types.File, t | |
return | ||
} | ||
|
||
func translateLuks(from Luks, options common.TranslateOptions) (to types.Luks, tm translate.TranslationSet, r report.Report) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels weird to me that we need to rewrite this since IIUC nothing in what we do is related to LUKS (right?). |
||
tr := translate.NewTranslator("yaml", "json", options) | ||
tr.AddCustomTranslator(translateResource) | ||
tm, r = translate.Prefixed(tr, "clevis", &from.Clevis, &to.Clevis) | ||
translate.MergeP(tr, tm, &r, "device", &from.Device, &to.Device) | ||
translate.MergeP(tr, tm, &r, "discard", &from.Discard, &to.Discard) | ||
translate.MergeP2(tr, tm, &r, "key_file", &from.KeyFile, "keyFile", &to.KeyFile) | ||
translate.MergeP(tr, tm, &r, "label", &from.Label, &to.Label) | ||
translate.MergeP(tr, tm, &r, "name", &from.Name, &to.Name) | ||
translate.MergeP2(tr, tm, &r, "open_options", &from.OpenOptions, "openOptions", &to.OpenOptions) | ||
translate.MergeP(tr, tm, &r, "options", &from.Options, &to.Options) | ||
translate.MergeP(tr, tm, &r, "uuid", &from.UUID, &to.UUID) | ||
translate.MergeP2(tr, tm, &r, "wipe_volume", &from.WipeVolume, "wipeVolume", &to.WipeVolume) | ||
return | ||
} | ||
|
||
func translateResource(from Resource, options common.TranslateOptions) (to types.Resource, tm translate.TranslationSet, r report.Report) { | ||
tr := translate.NewTranslator("yaml", "json", options) | ||
tm, r = translate.Prefixed(tr, "verification", &from.Verification, &to.Verification) | ||
|
@@ -294,7 +366,7 @@ func (c Config) processTrees(ret *types.Config, options common.TranslateOptions) | |
return ts, r | ||
} | ||
t := newNodeTracker(ret) | ||
|
||
ts.AddTranslation(path.New("yaml", "storage"), path.New("json", "storage")) | ||
for i, tree := range c.Storage.Trees { | ||
yamlPath := path.New("yaml", "storage", "trees", i) | ||
if options.FilesDir == "" { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we also need to add this to
Directory
andLink
.