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

Stablize Ignition spec 3.5 #1922

Merged
merged 8 commits into from
Oct 21, 2024
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
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package config

import (
exp "github.com/coreos/ignition/v2/config/v3_5_experimental"
types_exp "github.com/coreos/ignition/v2/config/v3_5_experimental/types"
exp "github.com/coreos/ignition/v2/config/v3_6_experimental"
types_exp "github.com/coreos/ignition/v2/config/v3_6_experimental/types"

"github.com/coreos/vcontext/report"
)
Expand Down
4 changes: 3 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (
v3_2 "github.com/coreos/ignition/v2/config/v3_2/types"
v3_3 "github.com/coreos/ignition/v2/config/v3_3/types"
v3_4 "github.com/coreos/ignition/v2/config/v3_4/types"
v3_5 "github.com/coreos/ignition/v2/config/v3_5_experimental/types"
v3_5 "github.com/coreos/ignition/v2/config/v3_5/types"
v3_6 "github.com/coreos/ignition/v2/config/v3_6_experimental/types"
)

type typeSet map[reflect.Type]struct{}
Expand Down Expand Up @@ -274,6 +275,7 @@ func TestConfigStructure(t *testing.T) {
reflect.TypeOf(v3_3.Config{}),
reflect.TypeOf(v3_4.Config{}),
reflect.TypeOf(v3_5.Config{}),
reflect.TypeOf(v3_6.Config{}),
}

for _, configType := range configs {
Expand Down
2 changes: 1 addition & 1 deletion config/merge/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/coreos/ignition/v2/config/util"
v3_2 "github.com/coreos/ignition/v2/config/v3_2/types"
"github.com/coreos/ignition/v2/config/v3_5_experimental/types"
"github.com/coreos/ignition/v2/config/v3_6_experimental/types"

"github.com/coreos/vcontext/path"
"github.com/stretchr/testify/assert"
Expand Down
78 changes: 78 additions & 0 deletions config/v3_5/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// 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
prestist marked this conversation as resolved.
Show resolved Hide resolved
// 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 v3_5

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"
"github.com/coreos/ignition/v2/config/validate"

"github.com/coreos/go-semver/semver"
"github.com/coreos/vcontext/report"
)

func Merge(parent, child types.Config) types.Config {
res, _ := merge.MergeStructTranscribe(parent, child)
return res.(types.Config)
}

// Parse parses the raw config into a types.Config struct and generates a report of any
// errors, warnings, info, and deprecations it encountered
func Parse(rawConfig []byte) (types.Config, report.Report, error) {
if len(rawConfig) == 0 {
return types.Config{}, report.Report{}, errors.ErrEmpty
}

var config types.Config
if rpt, err := util.HandleParseErrors(rawConfig, &config); err != nil {
return types.Config{}, rpt, err
}

version, err := semver.NewVersion(config.Ignition.Version)

if err != nil || *version != types.MaxVersion {
return types.Config{}, report.Report{}, errors.ErrUnknownVersion
}

rpt := validate.ValidateWithContext(config, rawConfig)
if rpt.IsFatal() {
return types.Config{}, rpt, errors.ErrInvalid
}

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,
// warnings, info, and deprecations it encountered
func ParseCompatibleVersion(raw []byte) (types.Config, report.Report, error) {
version, rpt, err := util.GetConfigVersion(raw)
if err != nil {
return types.Config{}, rpt, err
}

if version == types.MaxVersion {
return Parse(raw)
}
prevCfg, r, err := prev.ParseCompatibleVersion(raw)
if err != nil {
return types.Config{}, r, err
}
return translate.Translate(prevCfg), r, nil
}
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_experimental
package v3_5

import (
"testing"

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

Expand Down Expand Up @@ -83,6 +83,10 @@ func TestParse(t *testing.T) {
in: in{config: []byte(`{"ignition": {"version": "3.4.0"}}`)},
out: out{err: errors.ErrUnknownVersion},
},
{
in: in{config: []byte(`{"ignition": {"version": "3.5.0"}}`)},
out: out{config: types.Config{Ignition: types.Ignition{Version: types.MaxVersion.String()}}},
},
{
in: in{config: []byte(`{"ignition": {"version": "2.0.0-experimental"}}`)},
out: out{err: errors.ErrUnknownVersion},
Expand Down Expand Up @@ -129,7 +133,7 @@ func TestParse(t *testing.T) {
},
{
in: in{config: []byte(`{"ignition": {"version": "3.5.0-experimental"}}`)},
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"},}`)},
Expand All @@ -148,7 +152,7 @@ func TestParse(t *testing.T) {
out: out{err: errors.ErrEmpty},
},
{
in: in{config: []byte(`{"ignition": {"version": "3.5.0-experimental"}, "storage": {"filesystems": [{"format": "ext4", "label": "zzzzzzzzzzzzzzzzzzzzzzzzzzz"}]}}`)},
in: in{config: []byte(`{"ignition": {"version": "3.5.0"}, "storage": {"filesystems": [{"format": "ext4", "label": "zzzzzzzzzzzzzzzzzzzzzzzzzzz"}]}}`)},
out: out{err: errors.ErrInvalid},
},
}
Expand Down Expand Up @@ -178,15 +182,15 @@ func TestParse(t *testing.T) {
out: out{config: types.Config{Ignition: types.Ignition{Version: types.MaxVersion.String()}}},
},
{
in: in{config: []byte(`{"ignition": {"version": "3.5.0-experimental"}}`)},
in: in{config: []byte(`{"ignition": {"version": "3.5.0"}}`)},
out: out{config: types.Config{Ignition: types.Ignition{Version: types.MaxVersion.String()}}},
},
{
in: in{config: []byte(`{"ignition": {"version": "3.5.0"}}`)},
in: in{config: []byte(`{"ignition": {"version": "3.6.0-experimental"}}`)},
out: out{err: errors.ErrUnknownVersion},
},
{
in: in{config: []byte(`{"ignition": {"version": "3.6.0"}}`)},
in: in{config: []byte(`{"ignition": {"version": "3.7.0"}}`)},
out: out{err: errors.ErrUnknownVersion},
},
{
Expand All @@ -198,7 +202,7 @@ func TestParse(t *testing.T) {
out: out{err: errors.ErrInvalid},
},
{
in: in{config: []byte(`{"ignition": {"version": "3.5.0-experimental"}, "storage": {"filesystems": [{"format": "ext4", "label": "zzzzzzzzzzzzzzzzzzzzzzzzzzz"}]}}`)},
in: in{config: []byte(`{"ignition": {"version": "3.5.0"}, "storage": {"filesystems": [{"format": "ext4", "label": "zzzzzzzzzzzzzzzzzzzzzzzzzzz"}]}}`)},
out: out{err: errors.ErrInvalid},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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_experimental/types"
"github.com/coreos/ignition/v2/config/v3_5/types"
)

func translateIgnition(old old_types.Ignition) (ret types.Ignition) {
Expand Down
File renamed without changes.
File renamed without changes.
64 changes: 64 additions & 0 deletions config/v3_5/types/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// 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 types

import (
"github.com/coreos/ignition/v2/config/shared/errors"
"github.com/coreos/ignition/v2/config/util"

"github.com/coreos/go-semver/semver"
"github.com/coreos/vcontext/path"
"github.com/coreos/vcontext/report"
)

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

func (cfg Config) Validate(c path.ContextPath) (r report.Report) {
systemdPath := "/etc/systemd/system/"
unitPaths := map[string]struct{}{}
for _, unit := range cfg.Systemd.Units {
if !util.NilOrEmpty(unit.Contents) {
pathString := systemdPath + unit.Name
unitPaths[pathString] = struct{}{}
}
for _, dropin := range unit.Dropins {
if !util.NilOrEmpty(dropin.Contents) {
pathString := systemdPath + unit.Name + ".d/" + dropin.Name
unitPaths[pathString] = struct{}{}
}
}
}
for i, f := range cfg.Storage.Files {
if _, exists := unitPaths[f.Path]; exists {
r.AddOnError(c.Append("storage", "files", i, "path"), errors.ErrPathConflictsSystemd)
}
}
for i, d := range cfg.Storage.Directories {
if _, exists := unitPaths[d.Path]; exists {
r.AddOnError(c.Append("storage", "directories", i, "path"), errors.ErrPathConflictsSystemd)
}
}
for i, l := range cfg.Storage.Links {
if _, exists := unitPaths[l.Path]; exists {
r.AddOnError(c.Append("storage", "links", i, "path"), errors.ErrPathConflictsSystemd)
}
}
return
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading