Skip to content
Merged
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
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
module github.com/coreos/ign-converter

go 1.18
go 1.24.0

replace github.com/coreos/ign-converter/translate/v34tov35 => ./translate/v35tov34

require (
github.com/clarketm/json v1.17.1
github.com/coreos/ignition v0.35.0
github.com/coreos/ignition/v2 v2.20.0
github.com/stretchr/testify v1.9.0
github.com/coreos/ignition/v2 v2.26.0
github.com/stretchr/testify v1.11.1
)

require (
github.com/ajeddeloh/go-json v0.0.0-20200220154158-5ae607161559 // indirect
github.com/aws/aws-sdk-go v1.55.5 // indirect
github.com/aws/aws-sdk-go-v2 v1.41.1 // indirect
github.com/coreos/go-json v0.0.0-20230131223807-18775e0fb4fb // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/coreos/go-systemd/v22 v22.6.0 // indirect
github.com/coreos/vcontext v0.0.0-20230201181013-d72178a18687 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/vincent-petithory/dataurl v1.0.0 // indirect
go4.org v0.0.0-20200104003542-c7e774b10ea0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
25 changes: 12 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/ajeddeloh/go-json v0.0.0-20200220154158-5ae607161559 h1:4SPQljF/GJ8Q+QlCWMWxRBepub4DresnOm4eI2ebFGc=
github.com/ajeddeloh/go-json v0.0.0-20200220154158-5ae607161559/go.mod h1:otnto4/Icqn88WCcM4bhIJNSgsh9VLBuspyyCfvof9c=
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/aws/aws-sdk-go-v2 v1.41.1 h1:ABlyEARCDLN034NhxlRUSZr4l71mh+T5KAeGh6cerhU=
github.com/aws/aws-sdk-go-v2 v1.41.1/go.mod h1:MayyLB8y+buD9hZqkCW3kX1AKq07Y5pXxtgB+rRFhz0=
github.com/clarketm/json v1.17.1 h1:U1IxjqJkJ7bRK4L6dyphmoO840P6bdhPdbbLySourqI=
github.com/clarketm/json v1.17.1/go.mod h1:ynr2LRfb0fQU34l07csRNBTcivjySLLiY1YzQqKVfdo=
github.com/coreos/go-json v0.0.0-20230131223807-18775e0fb4fb h1:rmqyI19j3Z/74bIRhuC59RB442rXUazKNueVpfJPxg4=
Expand All @@ -10,21 +10,20 @@ github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142 h1:3jFq2xL4ZajGK4aZY8jz+DAF0FHjI51BXjjSwCzS1Dk=
github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/coreos/go-systemd/v22 v22.6.0 h1:aGVa/v8B7hpb0TKl0MWoAavPDmHvobFe5R5zn0bCJWo=
github.com/coreos/go-systemd/v22 v22.6.0/go.mod h1:iG+pp635Fo7ZmV/j14KUcmEyWF+0X7Lua8rrTWzYgWU=
github.com/coreos/ignition v0.35.0 h1:UFodoYq1mOPrbEjtxIsZbThcDyQwAI1owczRDqWmKkQ=
github.com/coreos/ignition v0.35.0/go.mod h1:WJQapxzEn9DE0ryxsGvm8QnBajm/XsS/PkrDqSpz+bA=
github.com/coreos/ignition/v2 v2.20.0 h1:xQjrxhCbcSKpqrN2hOQavAc1rx0GOf6qh2QCauScwPU=
github.com/coreos/ignition/v2 v2.20.0/go.mod h1:l7EpXNWA7jBXmjUMvnVBlrrj+LX2wA/PAyD9kstwFDQ=
github.com/coreos/ignition/v2 v2.26.0 h1:Db4IO5ydZOMnJYINgbPuXlwAH1ul0/V71h20iKyBi6k=
github.com/coreos/ignition/v2 v2.26.0/go.mod h1:2f48nEXqnh1BU69Yq3lIWDvaYFSFQVZoFB7rB7wz7DY=
github.com/coreos/vcontext v0.0.0-20230201181013-d72178a18687 h1:uSmlDgJGbUB0bwQBcZomBTottKwEDF5fF8UjSwKSzWM=
github.com/coreos/vcontext v0.0.0-20230201181013-d72178a18687/go.mod h1:Salmysdw7DAVuobBW/LwsKKgpyCPHUhjyJoMJD+ZJiI=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/vincent-petithory/dataurl v1.0.0 h1:cXw+kPto8NLuJtlMsI152irrVw9fRDX8AbShPRpg2CI=
github.com/vincent-petithory/dataurl v1.0.0/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U=
go4.org v0.0.0-20200104003542-c7e774b10ea0 h1:M6XsnQeLwG+rHQ+/rrGh3puBI3WZEy9TBWmf2H+enQA=
Expand Down
12 changes: 0 additions & 12 deletions translate/v34tov33/v34tov33.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,6 @@ func checkValue(v reflect.Value) error {
if len(luks.OpenOptions) > 0 {
return fmt.Errorf("invalid input config: luks openOptions is not supported in spec v3.3")
}
case reflect.TypeOf(old_types.FileEmbedded1{}):
f := v.Interface().(old_types.FileEmbedded1)
// 3.3 does not support special mode bits in files
if f.Mode != nil && (*f.Mode&07000) != 0 {
return fmt.Errorf("invalid input config: special mode bits are not supported in spec v3.3")
}
case reflect.TypeOf(old_types.DirectoryEmbedded1{}):
d := v.Interface().(old_types.DirectoryEmbedded1)
// 3.3 does not support special mode bits in directories
if d.Mode != nil && (*d.Mode&07000) != 0 {
return fmt.Errorf("invalid input config: special mode bits are not supported in spec v3.3")
}
case reflect.TypeOf(old_types.Resource{}):
resource := v.Interface().(old_types.Resource)
// 3.3 does not support arn: scheme for s3
Expand Down
32 changes: 30 additions & 2 deletions translate/v35tov34/v35tov34.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import (
"reflect"

"github.com/coreos/ignition/v2/config/translate"
"github.com/coreos/ignition/v2/config/util"
"github.com/coreos/ignition/v2/config/v3_4/types"

old_types "github.com/coreos/ignition/v2/config/v3_5/types"
"github.com/coreos/ignition/v2/config/validate"
)

// Copy of github.com/coreos/ignition/v2/config/v3_5/translate/translate.go
// with the types & old_types imports reversed (the referenced file translates
// from 3.5 -> 3.4 but as a result only touches fields that are understood by
// from 3.4 -> 3.5 but as a result only touches fields that are understood by
// the 3.4 spec).
func translateIgnition(old old_types.Ignition) (ret types.Ignition) {
// use a new translator so we don't recurse infinitely
Expand Down Expand Up @@ -93,5 +93,33 @@ func checkValue(v reflect.Value) error {
return fmt.Errorf("invalid input config: 'Cex' type is not supported in spec v3.4")
}

return descend(v)
}

func descend(v reflect.Value) error {
k := v.Type().Kind()
switch {
case util.IsPrimitive(k):
return nil
case k == reflect.Struct:
for i := 0; i < v.NumField(); i += 1 {
err := checkValue(v.Field(i))
if err != nil {
return err
}
}
case k == reflect.Slice:
for i := 0; i < v.Len(); i += 1 {
err := checkValue(v.Index(i))
if err != nil {
return err
}
}
case k == reflect.Ptr:
v = v.Elem()
if v.IsValid() {
return checkValue(v)
}
}
return nil
}
126 changes: 126 additions & 0 deletions translate/v36tov35/v36tov35.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Copyright 2020 Red Hat, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v36tov35

import (
"fmt"
"reflect"

"github.com/coreos/ignition/v2/config/translate"
"github.com/coreos/ignition/v2/config/util"
"github.com/coreos/ignition/v2/config/v3_5/types"
old_types "github.com/coreos/ignition/v2/config/v3_6/types"
"github.com/coreos/ignition/v2/config/validate"
)

// Copy of github.com/coreos/ignition/v2/config/v3_5/translate/translate.go
// with the types & old_types imports reversed (the referenced file translates
// from 3.5 -> 3.6 but as a result only touches fields that are understood by
// the 3.5 spec).
func translateIgnition(old old_types.Ignition) (ret types.Ignition) {
// use a new translator so we don't recurse infinitely
translate.NewTranslator().Translate(&old, &ret)
ret.Version = types.MaxVersion.String()
return
}

func translateConfig(old old_types.Config) (ret types.Config) {
tr := translate.NewTranslator()
tr.AddCustomTranslator(translateIgnition)
tr.Translate(&old, &ret)
return
}

// end copied Ignition v3_6/translate block

// Translate translates Ignition spec config v3.6 to spec v3.5
func Translate(cfg old_types.Config) (types.Config, error) {
rpt := validate.ValidateWithContext(cfg, nil)
if rpt.IsFatal() {
return types.Config{}, fmt.Errorf("invalid input config:\n%s", rpt.String())
}

err := checkValue(reflect.ValueOf(cfg))
if err != nil {
return types.Config{}, err
}

res := translateConfig(cfg)

// Sanity check the returned config
oldrpt := validate.ValidateWithContext(res, nil)
if oldrpt.IsFatal() {
return types.Config{}, fmt.Errorf("converted spec has unexpected fatal error:\n%s", oldrpt.String())
}
return res, nil
}

func checkValue(v reflect.Value) error {
// v3.6 introduced arbitrary custom clevis pin support
if v.Type() == reflect.TypeOf(old_types.ClevisCustom{}) {
// Check if Pin field is set
pinField := v.FieldByName("Pin")
if pinField.IsValid() && !pinField.IsNil() {
pinValue := pinField.Elem().String()
// v3.5 only supports tpm2, tang, and sss
if pinValue != "tpm2" && pinValue != "tang" && pinValue != "sss" {
return fmt.Errorf("invalid input config: arbitrary custom clevis pin '%s' is not supported in spec v3.5", pinValue)
}
}
}
// v3.6 supports special mode bits, but v3.5 and earlier have broken support.
// Fail translation to avoid silently breaking working functionality.
if v.Type() == reflect.TypeOf(old_types.FileEmbedded1{}) {
f := v.Interface().(old_types.FileEmbedded1)
if f.Mode != nil && (*f.Mode&07000) != 0 {
return fmt.Errorf("invalid input config: special mode bits are not supported in spec v3.5")
}
}
if v.Type() == reflect.TypeOf(old_types.DirectoryEmbedded1{}) {
d := v.Interface().(old_types.DirectoryEmbedded1)
if d.Mode != nil && (*d.Mode&07000) != 0 {
return fmt.Errorf("invalid input config: special mode bits are not supported in spec v3.5")
}
}

return descend(v)
}

func descend(v reflect.Value) error {
k := v.Type().Kind()
switch {
case util.IsPrimitive(k):
return nil
case k == reflect.Struct:
for i := 0; i < v.NumField(); i += 1 {
err := checkValue(v.Field(i))
if err != nil {
return err
}
}
case k == reflect.Slice:
for i := 0; i < v.Len(); i += 1 {
err := checkValue(v.Index(i))
if err != nil {
return err
}
}
case k == reflect.Ptr:
v = v.Elem()
if v.IsValid() {
return checkValue(v)
}
}
return nil
}
Loading
Loading