Skip to content
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

translate: support deprecated create filesystem object #28

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 24 additions & 2 deletions translate/v23tov30/v23tov30.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func Check2_3(cfg old.Config, fsMap map[string]string) error {
if _, ok := fsMap[fs.Name]; !ok {
return util.NoFilesystemError(fs.Name)
}

if fs.Mount.Create != nil && !fs.Mount.Create.Force {
return fmt.Errorf("Config must force filesystem creation in case `mount.create` object is defined.")
}
}

// check that there are no duplicates with files, links, or directories
Expand Down Expand Up @@ -347,13 +351,31 @@ func translateFilesystems(fss []old.Filesystem, m map[string]string) (ret []type
if f.Mount == nil {
f.Mount = &old.Mount{}
}

wipe := util.BoolP(f.Mount.WipeFilesystem)
options := translateFilesystemOptions(f.Mount.Options)

// If we have a `"create": {...}` section, we try
// to convert it.
if f.Mount.Create != nil {
// `wipe` should always be set to `true` - there is a config check
// in the beginning of the translation to ensure that we don't try to
// use this `create` section without forcing the exising filesystem to be
// wiped.
wipe = util.BoolP(f.Mount.Create.Force)
Copy link
Contributor

Choose a reason for hiding this comment

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

If Force is true, it's safe to set WipeFilesystem true. But if Mount.Create is non-nil and Force is false, I think we should fail the translation. In that situation, the config is asking for the FS to be created if it doesn't exist, and for Ignition to fail otherwise. For the case where the filesystem exists and matches the specified parameters (format etc.), Ignition 2.x can't deliver those semantics: provisioning would succeed instead.

Copy link
Author

Choose a reason for hiding this comment

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

I get your point - and this is something I'd like to talk with you; maybe in a dedicated issue. Currently ign-converter expects a fsMap to map file systems with path, what if we could generate this value on the fly, with something like:

 @@ -49,7 +50,13 @@ func Check2_4(cfg old.Config, fsMap map[string]string) error {
        fsMap["root"] = "/"
        for _, fs := range cfg.Storage.Filesystems {
                if _, ok := fsMap[fs.Name]; !ok {
-                       return util.NoFilesystemError(fs.Name)
+                       // generate a random path
+                       p, err := ioutil.TempDir("", fs.Name)
+                       if err != nil {
+                               return fmt.Errorf("creating tmp fs directory: %w", err)
+                       }
+
+                       fsMap[fs.Name] = p
                }

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's discuss that change in a separate issue. I don't think it's relevant here, though? The problem here isn't the mountpoint, but what to do if the specified Device already has a filesystem superblock on it.

Copy link
Author

@tormath1 tormath1 Nov 16, 2021

Choose a reason for hiding this comment

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

Ok, the issue is created in here: #30

The problem here isn't the mountpoint, but what to do if the specified Device already has a filesystem superblock on it.

Got it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, cool. So let's add an error return in Check2_* if f.Mount.Create != nil && !f.Mount.Create.Force, and a comment here referring to that.


for _, opt := range f.Mount.Create.Options {
options = append(options, types.FilesystemOption(opt))
}
}

ret = append(ret, types.Filesystem{
Device: f.Mount.Device,
Format: util.StrP(f.Mount.Format),
WipeFilesystem: util.BoolP(f.Mount.WipeFilesystem),
WipeFilesystem: wipe,
Label: f.Mount.Label,
UUID: f.Mount.UUID,
Options: translateFilesystemOptions(f.Mount.Options),
Options: options,
Path: util.StrP(m[f.Name]),
})
}
Expand Down
26 changes: 24 additions & 2 deletions translate/v24tov31/v24tov31.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func Check2_4(cfg old.Config, fsMap map[string]string) error {
if _, ok := fsMap[fs.Name]; !ok {
return util.NoFilesystemError(fs.Name)
}

if fs.Mount.Create != nil && !fs.Mount.Create.Force {
return fmt.Errorf("Config must force filesystem creation in case `mount.create` object is defined.")
}
}

// check that there are no duplicates with files, links, or directories
Expand Down Expand Up @@ -372,13 +376,31 @@ func translateFilesystems(fss []old.Filesystem, m map[string]string) (ret []type
if f.Mount == nil {
f.Mount = &old.Mount{}
}

wipe := util.BoolP(f.Mount.WipeFilesystem)
options := translateFilesystemOptions(f.Mount.Options)

// If we have a `"create": {...}` section, we try
// to convert it.
if f.Mount.Create != nil {
// `wipe` should always be set to `true` - there is a config check
// in the beginning of the translation to ensure that we don't try to
// use this `create` section without forcing the exising filesystem to be
// wiped.
wipe = util.BoolP(f.Mount.Create.Force)

for _, opt := range f.Mount.Create.Options {
options = append(options, types.FilesystemOption(opt))
}
}

ret = append(ret, types.Filesystem{
Device: f.Mount.Device,
Format: util.StrP(f.Mount.Format),
WipeFilesystem: util.BoolP(f.Mount.WipeFilesystem),
WipeFilesystem: wipe,
Label: f.Mount.Label,
UUID: f.Mount.UUID,
Options: translateFilesystemOptions(f.Mount.Options),
Options: options,
Path: util.StrP(m[f.Name]),
})
}
Expand Down
Loading