|
| 1 | +From 2c91043cc1181596c363341ee5b974808b6cc44d Mon Sep 17 00:00:00 2001 |
| 2 | +From: Mathieu Tortuyaux <mtortuyaux@microsoft.com> |
| 3 | +Date: Wed, 25 May 2022 10:20:09 +0200 |
| 4 | +Subject: [PATCH 06/22] config/v3_5: convert ignition 2.x to 3.x |
| 5 | + |
| 6 | +if the version of ignition is 2.x we convert it to 3.x using |
| 7 | +ign-converter. |
| 8 | + |
| 9 | +it should support any 2.x version (or at the least the last 2 releases) |
| 10 | + |
| 11 | +Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com> |
| 12 | +--- |
| 13 | + config/v3_6_experimental/config.go | 37 ++++++++++++++++++++++++++++++ |
| 14 | + 1 file changed, 37 insertions(+) |
| 15 | + |
| 16 | +diff --git a/config/v3_6_experimental/config.go b/config/v3_6_experimental/config.go |
| 17 | +index 3be26cae..ea367663 100644 |
| 18 | +--- a/config/v3_6_experimental/config.go |
| 19 | ++++ b/config/v3_6_experimental/config.go |
| 20 | +@@ -15,9 +15,14 @@ |
| 21 | + package v3_6_experimental |
| 22 | + |
| 23 | + import ( |
| 24 | ++ "encoding/json" |
| 25 | ++ "fmt" |
| 26 | ++ |
| 27 | ++ "github.com/flatcar/ignition/config/v2_4" |
| 28 | + "github.com/flatcar/ignition/v2/config/merge" |
| 29 | + "github.com/flatcar/ignition/v2/config/shared/errors" |
| 30 | + "github.com/flatcar/ignition/v2/config/util" |
| 31 | ++ "github.com/flatcar/ignition/v2/config/v24tov31" |
| 32 | + prev "github.com/flatcar/ignition/v2/config/v3_5" |
| 33 | + "github.com/flatcar/ignition/v2/config/v3_6_experimental/translate" |
| 34 | + "github.com/flatcar/ignition/v2/config/v3_6_experimental/types" |
| 35 | +@@ -67,6 +72,38 @@ func ParseCompatibleVersion(raw []byte) (types.Config, report.Report, error) { |
| 36 | + return types.Config{}, rpt, err |
| 37 | + } |
| 38 | + |
| 39 | ++ // if the version is 2.x or 1.x, we |
| 40 | ++ // convert it to 3.1 |
| 41 | ++ if version.Major != 3 { |
| 42 | ++ // Parse should fallback on every 2.x supported version |
| 43 | ++ cfg, _, err := v2_4.Parse(raw) |
| 44 | ++ if err != nil || rpt.IsFatal() { |
| 45 | ++ return types.Config{}, report.Report{}, fmt.Errorf("unable to parse 2.x ignition: %w", err) |
| 46 | ++ } |
| 47 | ++ |
| 48 | ++ /* |
| 49 | ++ map[string]string{} is required by the ign-converter |
| 50 | ++ Ignition Spec 3 will mount filesystems at the mountpoint specified by path when running. |
| 51 | ++ Filesystems no longer have the name field and files, links, and directories no longer specify the filesystem by name. |
| 52 | ++ This means to translate filesystems (with the exception of root), |
| 53 | ++ you must also provide a mapping of filesystem name to absolute path, e.g. |
| 54 | ++ ``` |
| 55 | ++ map[string]string{"var": "/var"} |
| 56 | ++ ``` |
| 57 | ++ */ |
| 58 | ++ newCfg, err := v24tov31.Translate(cfg, map[string]string{}) |
| 59 | ++ if err != nil { |
| 60 | ++ return types.Config{}, report.Report{}, fmt.Errorf("unable to translate 2.x ignition to 3.1: %w", err) |
| 61 | ++ |
| 62 | ++ } |
| 63 | ++ |
| 64 | ++ // update raw in place to continue with the 3.x logic |
| 65 | ++ raw, err = json.Marshal(newCfg) |
| 66 | ++ if err != nil { |
| 67 | ++ return types.Config{}, report.Report{}, fmt.Errorf("unable to render JSON: %w", err) |
| 68 | ++ } |
| 69 | ++ } |
| 70 | ++ |
| 71 | + if version == types.MaxVersion { |
| 72 | + return Parse(raw) |
| 73 | + } |
| 74 | +-- |
| 75 | +2.43.0 |
| 76 | + |
0 commit comments