Skip to content

Commit

Permalink
config/v3_6_experimental: adapt for new experimental spec
Browse files Browse the repository at this point in the history
  • Loading branch information
travier committed Oct 14, 2024
1 parent 68efbc1 commit 87e2d0c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 41 deletions.
12 changes: 6 additions & 6 deletions config/v3_6_experimental/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package v3_5
package v3_6_experimental

import (
"github.com/coreos/ignition/v2/config/merge"
"github.com/coreos/ignition/v2/config/shared/errors"
"github.com/coreos/ignition/v2/config/util"
prev "github.com/coreos/ignition/v2/config/v3_4"
"github.com/coreos/ignition/v2/config/v3_5/translate"
"github.com/coreos/ignition/v2/config/v3_5/types"
prev "github.com/coreos/ignition/v2/config/v3_5"
"github.com/coreos/ignition/v2/config/v3_6_experimental/translate"
"github.com/coreos/ignition/v2/config/v3_6_experimental/types"
"github.com/coreos/ignition/v2/config/validate"

"github.com/coreos/go-semver/semver"
Expand Down Expand Up @@ -58,8 +58,8 @@ func Parse(rawConfig []byte) (types.Config, report.Report, error) {
return config, rpt, nil
}

// ParseCompatibleVersion parses the raw config of version 3.5.0 or
// lesser into a 3.5 types.Config struct and generates a report of any errors,
// ParseCompatibleVersion parses the raw config of version 3.5.0-experimental or
// lesser into a 3.5-exp types.Config struct and generates a report of any errors,
// warnings, info, and deprecations it encountered
func ParseCompatibleVersion(raw []byte) (types.Config, report.Report, error) {
version, rpt, err := util.GetConfigVersion(raw)
Expand Down
18 changes: 13 additions & 5 deletions config/v3_6_experimental/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package v3_5
package v3_6_experimental

import (
"testing"

"github.com/coreos/ignition/v2/config/shared/errors"
"github.com/coreos/ignition/v2/config/v3_5/types"
"github.com/coreos/ignition/v2/config/v3_6_experimental/types"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -85,7 +85,7 @@ func TestParse(t *testing.T) {
},
{
in: in{config: []byte(`{"ignition": {"version": "3.5.0"}}`)},
out: out{config: types.Config{Ignition: types.Ignition{Version: types.MaxVersion.String()}}},
out: out{err: errors.ErrUnknownVersion},
},
{
in: in{config: []byte(`{"ignition": {"version": "2.0.0-experimental"}}`)},
Expand Down Expand Up @@ -135,6 +135,10 @@ func TestParse(t *testing.T) {
in: in{config: []byte(`{"ignition": {"version": "3.5.0-experimental"}}`)},
out: out{err: errors.ErrUnknownVersion},
},
{
in: in{config: []byte(`{"ignition": {"version": "3.6.0-experimental"}}`)},
out: out{config: types.Config{Ignition: types.Ignition{Version: types.MaxVersion.String()}}},
},
{
in: in{config: []byte(`{"ignition": {"version": "2.0.0"},}`)},
out: out{err: errors.ErrInvalid},
Expand All @@ -152,7 +156,7 @@ func TestParse(t *testing.T) {
out: out{err: errors.ErrEmpty},
},
{
in: in{config: []byte(`{"ignition": {"version": "3.5.0"}, "storage": {"filesystems": [{"format": "ext4", "label": "zzzzzzzzzzzzzzzzzzzzzzzzzzz"}]}}`)},
in: in{config: []byte(`{"ignition": {"version": "3.6.0-experimental"}, "storage": {"filesystems": [{"format": "ext4", "label": "zzzzzzzzzzzzzzzzzzzzzzzzzzz"}]}}`)},
out: out{err: errors.ErrInvalid},
},
}
Expand Down Expand Up @@ -187,6 +191,10 @@ func TestParse(t *testing.T) {
},
{
in: in{config: []byte(`{"ignition": {"version": "3.6.0-experimental"}}`)},
out: out{config: types.Config{Ignition: types.Ignition{Version: types.MaxVersion.String()}}},
},
{
in: in{config: []byte(`{"ignition": {"version": "3.6.0"}}`)},
out: out{err: errors.ErrUnknownVersion},
},
{
Expand All @@ -202,7 +210,7 @@ func TestParse(t *testing.T) {
out: out{err: errors.ErrInvalid},
},
{
in: in{config: []byte(`{"ignition": {"version": "3.5.0"}, "storage": {"filesystems": [{"format": "ext4", "label": "zzzzzzzzzzzzzzzzzzzzzzzzzzz"}]}}`)},
in: in{config: []byte(`{"ignition": {"version": "3.6.0-experimental"}, "storage": {"filesystems": [{"format": "ext4", "label": "zzzzzzzzzzzzzzzzzzzzzzzzzzz"}]}}`)},
out: out{err: errors.ErrInvalid},
},
}
Expand Down
28 changes: 2 additions & 26 deletions config/v3_6_experimental/translate/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package translate

import (
"github.com/coreos/ignition/v2/config/translate"
old_types "github.com/coreos/ignition/v2/config/v3_4/types"
"github.com/coreos/ignition/v2/config/v3_5/types"
old_types "github.com/coreos/ignition/v2/config/v3_5/types"
"github.com/coreos/ignition/v2/config/v3_6_experimental/types"
)

func translateIgnition(old old_types.Ignition) (ret types.Ignition) {
Expand All @@ -27,33 +27,9 @@ func translateIgnition(old old_types.Ignition) (ret types.Ignition) {
return
}

func translateLuks(old old_types.Luks) (ret types.Luks) {
tr := translate.NewTranslator()
tr.AddCustomTranslator(translateTang)
tr.Translate(&old.Clevis, &ret.Clevis)
tr.Translate(&old.Device, &ret.Device)
tr.Translate(&old.KeyFile, &ret.KeyFile)
tr.Translate(&old.Label, &ret.Label)
tr.Translate(&old.Name, &ret.Name)
tr.Translate(&old.OpenOptions, &ret.OpenOptions)
tr.Translate(&old.Options, &ret.Options)
tr.Translate(&old.Discard, &ret.Discard)
tr.Translate(&old.UUID, &ret.UUID)
tr.Translate(&old.WipeVolume, &ret.WipeVolume)
return
}

func translateTang(old old_types.Tang) (ret types.Tang) {
tr := translate.NewTranslator()
tr.Translate(&old.Thumbprint, &ret.Thumbprint)
tr.Translate(&old.URL, &ret.URL)
return
}

func Translate(old old_types.Config) (ret types.Config) {
tr := translate.NewTranslator()
tr.AddCustomTranslator(translateIgnition)
tr.AddCustomTranslator(translateLuks)
tr.Translate(&old, &ret)
return
}
2 changes: 1 addition & 1 deletion config/v3_6_experimental/translate/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"testing"

"github.com/coreos/ignition/v2/config/util"
old "github.com/coreos/ignition/v2/config/v3_4/types"
old "github.com/coreos/ignition/v2/config/v3_5/types"
)

// Check that we have valid translators for the complete config struct
Expand Down
5 changes: 3 additions & 2 deletions config/v3_6_experimental/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import (

var (
MaxVersion = semver.Version{
Major: 3,
Minor: 5,
Major: 3,
Minor: 6,
PreRelease: "experimental",
}
)

Expand Down
2 changes: 1 addition & 1 deletion config/v3_6_experimental/types/schema.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package types

// generated by "schematyper --package=types config/v3_5/schema/ignition.json -o config/v3_5/types/schema.go --root-type=Config" -- DO NOT EDIT
// generated by "schematyper --package=types config/v3_6_experimental/schema/ignition.json -o config/v3_6_experimental/types/schema.go --root-type=Config" -- DO NOT EDIT

type Cex struct {
Enabled *bool `json:"enabled,omitempty"`
Expand Down

0 comments on commit 87e2d0c

Please sign in to comment.