-
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.
v1_0 is compatible with ignition 3.4.0 v1_1_exp is experimental version compatible with ignition 3.5.0 docs added for fiot Signed-off-by: Sayan Paul <[email protected]>
- Loading branch information
Showing
12 changed files
with
830 additions
and
0 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
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_0 | ||
|
||
import ( | ||
base "github.com/coreos/butane/base/v0_5" | ||
) | ||
|
||
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,54 @@ | ||
// 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_0 | ||
|
||
import ( | ||
"github.com/coreos/butane/config/common" | ||
cutil "github.com/coreos/butane/config/util" | ||
|
||
"github.com/coreos/ignition/v2/config/v3_4/types" | ||
"github.com/coreos/vcontext/report" | ||
) | ||
|
||
var ( | ||
fieldFilters = cutil.NewFilters(types.Config{}, cutil.FilterMap{ | ||
"kernelArguments": common.ErrGeneralKernelArgumentSupport, | ||
"storage.disks": common.ErrDiskSupport, | ||
"storage.filesystems": common.ErrFilesystemSupport, | ||
"storage.luks": common.ErrLuksSupport, | ||
"storage.raid": common.ErrRaidSupport, | ||
}) | ||
) | ||
|
||
// Return FieldFilters for this spec. | ||
func (c Config) FieldFilters() *cutil.FieldFilters { | ||
return &fieldFilters | ||
} | ||
|
||
// ToIgn3_4 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_4(options common.TranslateOptions) (types.Config, report.Report, error) { | ||
cfg, r, err := cutil.Translate(c, "ToIgn3_4Unvalidated", options) | ||
return cfg.(types.Config), r, err | ||
} | ||
|
||
// ToIgn3_4Bytes 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_4Bytes(input []byte, options common.TranslateBytesOptions) ([]byte, report.Report, error) { | ||
return cutil.TranslateBytes(input, &Config{}, "ToIgn3_4", 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,180 @@ | ||
// 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_0 | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
baseutil "github.com/coreos/butane/base/util" | ||
base "github.com/coreos/butane/base/v0_5" | ||
"github.com/coreos/butane/config/common" | ||
confutil "github.com/coreos/butane/config/util" | ||
"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 fiot | ||
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("yaml", "kernel_arguments"), | ||
}, | ||
}, | ||
}, | ||
// 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("yaml", "kernel_arguments"), | ||
}, | ||
}, | ||
}, | ||
// disk customizations are made in Image Builder, fiot 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("yaml", "storage", "disks"), | ||
}, | ||
}, | ||
}, | ||
// filesystem customizations are made in Image Builder, fiot 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("yaml", "storage", "filesystems"), | ||
}, | ||
}, | ||
}, | ||
// default luks configuration is made in Image Builder for fiot, 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("yaml", "storage", "luks"), | ||
}, | ||
}, | ||
}, | ||
// 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("yaml", "storage", "raid"), | ||
}, | ||
}, | ||
}, | ||
} | ||
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_4Unvalidated(common.TranslateOptions{}) | ||
r.Merge(fieldFilters.Verify(actual)) | ||
r = confutil.TranslateReportPaths(r, translations) | ||
baseutil.VerifyReport(t, test.In, r) | ||
assert.Equal(t, expectedReport, r, "report mismatch") | ||
assert.NoError(t, translations.DebugVerifyCoverage(actual), "incomplete TranslationSet coverage") | ||
}) | ||
} | ||
} |
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_1_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,54 @@ | ||
// 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_1_exp | ||
|
||
import ( | ||
"github.com/coreos/butane/config/common" | ||
cutil "github.com/coreos/butane/config/util" | ||
|
||
"github.com/coreos/ignition/v2/config/v3_5_experimental/types" | ||
"github.com/coreos/vcontext/report" | ||
) | ||
|
||
var ( | ||
fieldFilters = cutil.NewFilters(types.Config{}, cutil.FilterMap{ | ||
"kernelArguments": common.ErrGeneralKernelArgumentSupport, | ||
"storage.disks": common.ErrDiskSupport, | ||
"storage.filesystems": common.ErrFilesystemSupport, | ||
"storage.luks": common.ErrLuksSupport, | ||
"storage.raid": common.ErrRaidSupport, | ||
}) | ||
) | ||
|
||
// Return FieldFilters for this spec. | ||
func (c Config) FieldFilters() *cutil.FieldFilters { | ||
return &fieldFilters | ||
} | ||
|
||
// 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.2 Butane config to a v3.5.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) | ||
} |
Oops, something went wrong.