-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config/r4e/: add new experimental spec
- Loading branch information
Showing
7 changed files
with
429 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2022 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 v1_2_exp | ||
|
||
import ( | ||
base "github.com/coreos/butane/base/v0_6_exp" | ||
) | ||
|
||
type Config struct { | ||
base.Config `yaml:",inline"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2022 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 v1_2_exp | ||
|
||
import ( | ||
"github.com/coreos/butane/config/common" | ||
cutil "github.com/coreos/butane/config/util" | ||
"github.com/coreos/butane/translate" | ||
"github.com/coreos/ignition/v2/config/v3_5_experimental/types" | ||
"github.com/coreos/vcontext/path" | ||
"github.com/coreos/vcontext/report" | ||
) | ||
|
||
// ToIgn3_5Unvalidated translates the config to an Ignition config. It also | ||
// returns the set of translations it did so paths in the resultant config | ||
// can be tracked back to their source in the source config. No config | ||
// validation is performed on input or output. | ||
func (c Config) ToIgn3_5Unvalidated(options common.TranslateOptions) (types.Config, translate.TranslationSet, report.Report) { | ||
ret, ts, r := c.Config.ToIgn3_5Unvalidated(options) | ||
if r.IsFatal() { | ||
return types.Config{}, translate.TranslationSet{}, r | ||
} | ||
|
||
checkForForbiddenFields(ret, &r) | ||
|
||
return ret, ts, r | ||
} | ||
|
||
// Checks and adds the appropiate errors when unsupported fields on r4e are | ||
// provided | ||
func checkForForbiddenFields(t types.Config, r *report.Report) { | ||
for i := range t.KernelArguments.ShouldExist { | ||
r.AddOnError(path.New("path", "json", "kernel_arguments", "should_exist", i), common.ErrGeneralKernelArgumentSupport) | ||
} | ||
for i := range t.KernelArguments.ShouldNotExist { | ||
r.AddOnError(path.New("path", "json", "kernel_arguments", "should_not_exist", i), common.ErrGeneralKernelArgumentSupport) | ||
} | ||
for i := range t.Storage.Disks { | ||
r.AddOnError(path.New("path", "json", "storage", "disks", i), common.ErrDiskSupport) | ||
} | ||
for i := range t.Storage.Filesystems { | ||
r.AddOnError(path.New("path", "json", "storage", "filesystems", i), common.ErrFilesystemSupport) | ||
} | ||
for i := range t.Storage.Luks { | ||
r.AddOnError(path.New("path", "json", "storage", "luks", i), common.ErrLuksSupport) | ||
} | ||
for i := range t.Storage.Raid { | ||
r.AddOnError(path.New("path", "json", "storage", "raid", i), common.ErrRaidSupport) | ||
} | ||
} | ||
|
||
// ToIgn3_5 translates the config to an Ignition config. It returns a | ||
// report of any errors or warnings in the source and resultant config. If | ||
// the report has fatal errors or it encounters other problems translating, | ||
// an error is returned. | ||
func (c Config) ToIgn3_5(options common.TranslateOptions) (types.Config, report.Report, error) { | ||
cfg, r, err := cutil.Translate(c, "ToIgn3_5Unvalidated", options) | ||
return cfg.(types.Config), r, err | ||
} | ||
|
||
// ToIgn3_5Bytes translates from a v1.1 Butane config to a v3.4.0 Ignition config. It returns a report of any errors or | ||
// warnings in the source and resultant config. If the report has fatal errors or it encounters other problems | ||
// translating, an error is returned. | ||
func ToIgn3_5Bytes(input []byte, options common.TranslateBytesOptions) ([]byte, report.Report, error) { | ||
return cutil.TranslateBytes(input, &Config{}, "ToIgn3_5", options) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
// Copyright 2022 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 v1_2_exp | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
base "github.com/coreos/butane/base/v0_6_exp" | ||
"github.com/coreos/butane/config/common" | ||
"github.com/coreos/ignition/v2/config/util" | ||
"github.com/coreos/vcontext/path" | ||
"github.com/coreos/vcontext/report" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Test that we error on unsupported fields for r4e | ||
func TestTranslateInvalid(t *testing.T) { | ||
type InvalidEntry struct { | ||
Kind report.EntryKind | ||
Err error | ||
Path path.ContextPath | ||
} | ||
tests := []struct { | ||
In Config | ||
Entries []InvalidEntry | ||
}{ | ||
// we don't support setting kernel arguments | ||
{ | ||
Config{ | ||
Config: base.Config{ | ||
KernelArguments: base.KernelArguments{ | ||
ShouldExist: []base.KernelArgument{ | ||
"test", | ||
}, | ||
}, | ||
}, | ||
}, | ||
[]InvalidEntry{ | ||
{ | ||
report.Error, | ||
common.ErrGeneralKernelArgumentSupport, | ||
path.New("path", "json", "kernel_arguments", "should_exist", 0), | ||
}, | ||
}, | ||
}, | ||
// we don't support unsetting kernel arguments either | ||
{ | ||
Config{ | ||
Config: base.Config{ | ||
KernelArguments: base.KernelArguments{ | ||
ShouldNotExist: []base.KernelArgument{ | ||
"another-test", | ||
}, | ||
}, | ||
}, | ||
}, | ||
[]InvalidEntry{ | ||
{ | ||
report.Error, | ||
common.ErrGeneralKernelArgumentSupport, | ||
path.New("path", "json", "kernel_arguments", "should_not_exist", 0), | ||
}, | ||
}, | ||
}, | ||
// disk customizations are made in Image Builder, r4e doesn't support this via ignition | ||
{ | ||
Config{ | ||
Config: base.Config{ | ||
Storage: base.Storage{ | ||
Disks: []base.Disk{ | ||
{ | ||
Device: "some-device", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
[]InvalidEntry{ | ||
{ | ||
report.Error, | ||
common.ErrDiskSupport, | ||
path.New("path", "json", "storage", "disks", 0), | ||
}, | ||
}, | ||
}, | ||
// filesystem customizations are made in Image Builder, r4e doesn't support this via ignition | ||
{ | ||
Config{ | ||
Config: base.Config{ | ||
Storage: base.Storage{ | ||
Filesystems: []base.Filesystem{ | ||
{ | ||
Device: "/dev/disk/by-label/TEST", | ||
Path: util.StrToPtr("/var"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
[]InvalidEntry{ | ||
{ | ||
report.Error, | ||
common.ErrFilesystemSupport, | ||
path.New("path", "json", "storage", "filesystems", 0), | ||
}, | ||
}, | ||
}, | ||
// default luks configuration is made in Image Builder for r4e, we don't support this via ignition | ||
{ | ||
Config{ | ||
Config: base.Config{ | ||
Storage: base.Storage{ | ||
Luks: []base.Luks{ | ||
{ | ||
Label: util.StrToPtr("some-label"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
[]InvalidEntry{ | ||
{ | ||
report.Error, | ||
common.ErrLuksSupport, | ||
path.New("path", "json", "storage", "luks", 0), | ||
}, | ||
}, | ||
}, | ||
// we don't support configuring raid via ignition | ||
{ | ||
Config{ | ||
Config: base.Config{ | ||
Storage: base.Storage{ | ||
Raid: []base.Raid{ | ||
{ | ||
Name: "some-name", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
[]InvalidEntry{ | ||
{ | ||
report.Error, | ||
common.ErrRaidSupport, | ||
path.New("path", "json", "storage", "raid", 0), | ||
}, | ||
}, | ||
}, | ||
} | ||
for i, test := range tests { | ||
t.Run(fmt.Sprintf("translate %d", i), func(t *testing.T) { | ||
var expectedReport report.Report | ||
for _, entry := range test.Entries { | ||
expectedReport.AddOnError(entry.Path, entry.Err) | ||
} | ||
actual, translations, r := test.In.ToIgn3_5Unvalidated(common.TranslateOptions{}) | ||
assert.Equal(t, expectedReport, r, "report mismatch") | ||
assert.NoError(t, translations.DebugVerifyCoverage(actual), "incomplete TranslationSet coverage") | ||
}) | ||
} | ||
} |
Oops, something went wrong.