Skip to content

Commit

Permalink
Add new fiot variant for fedora-iot
Browse files Browse the repository at this point in the history
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
say-paul committed Dec 4, 2023
1 parent 23c4958 commit fed77f6
Show file tree
Hide file tree
Showing 12 changed files with 830 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
fcos1_4 "github.com/coreos/butane/config/fcos/v1_4"
fcos1_5 "github.com/coreos/butane/config/fcos/v1_5"
fcos1_6_exp "github.com/coreos/butane/config/fcos/v1_6_exp"
fiot1_0 "github.com/coreos/butane/config/fiot/v1_0"
fiot1_1_exp "github.com/coreos/butane/config/fiot/v1_1_exp"
flatcar1_0 "github.com/coreos/butane/config/flatcar/v1_0"
flatcar1_1 "github.com/coreos/butane/config/flatcar/v1_1"
flatcar1_2_exp "github.com/coreos/butane/config/flatcar/v1_2_exp"
Expand Down Expand Up @@ -77,6 +79,8 @@ func init() {
RegisterTranslator("r4e", "1.0.0", r4e1_0.ToIgn3_3Bytes)
RegisterTranslator("r4e", "1.1.0", r4e1_1.ToIgn3_4Bytes)
RegisterTranslator("r4e", "1.2.0-experimental", r4e1_2_exp.ToIgn3_5Bytes)
RegisterTranslator("fiot", "1.0.0", fiot1_0.ToIgn3_4Bytes)
RegisterTranslator("fiot", "1.1.0-experimental", fiot1_1_exp.ToIgn3_5Bytes)
RegisterTranslator("rhcos", "0.1.0", unsupportedRhcosVariant)
}

Expand Down
23 changes: 23 additions & 0 deletions config/fiot/v1_0/schema.go
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"`
}
54 changes: 54 additions & 0 deletions config/fiot/v1_0/translate.go
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)
}
180 changes: 180 additions & 0 deletions config/fiot/v1_0/translate_test.go
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")
})
}
}
23 changes: 23 additions & 0 deletions config/fiot/v1_1_exp/schema.go
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"`
}
54 changes: 54 additions & 0 deletions config/fiot/v1_1_exp/translate.go
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)
}
Loading

0 comments on commit fed77f6

Please sign in to comment.