Skip to content

Commit

Permalink
base/v0_6_exp/validate.go: Add Validation when merging local/inline s…
Browse files Browse the repository at this point in the history
…ources

base/v0_6_exp/validate.go: Add mapper function and fix tests
  • Loading branch information
Adam0Brien authored and Adam0Brien committed Sep 19, 2023
1 parent 0a1b18e commit 986194b
Show file tree
Hide file tree
Showing 16 changed files with 1,112 additions and 9 deletions.
33 changes: 31 additions & 2 deletions base/v0_6_exp/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@ package v0_6_exp
import (
baseutil "github.com/coreos/butane/base/util"
"github.com/coreos/butane/config/common"

"github.com/coreos/ignition/v2/config/util"
exp "github.com/coreos/ignition/v2/config/v3_5_experimental"
"github.com/coreos/vcontext/path"
"github.com/coreos/vcontext/report"
)

func (rs Resource) Validate(c path.ContextPath) (r report.Report) {
var field string
sources := 0
var config string
var butaneReport report.Report
if rs.Local != nil {
sources++
field = "local"
config = *rs.Local
}
if rs.Inline != nil {
sources++
field = "inline"
config = *rs.Inline
}
if rs.Source != nil {
sources++
Expand All @@ -41,9 +44,35 @@ func (rs Resource) Validate(c path.ContextPath) (r report.Report) {
if sources > 1 {
r.AddOnError(c.Append(field), common.ErrTooManyResourceSources)
}
if field == "local" || field == "inline" {
// check if it's an ignition config
_, report, err := exp.Parse([]byte(config))
if len(report.Entries) > 0 {
butaneReport = MapIgnitionReportToButane(report)
r.Merge(butaneReport)
}
if err != nil {
r.AddOnWarn(c.Append(field), errors.ErrUnknownVersion)

Check failure on line 55 in base/v0_6_exp/validate.go

View workflow job for this annotation

GitHub Actions / Regenerate

undefined: errors
}
}

return
}

func MapIgnitionReportToButane(ignitionReport report.Report) report.Report {
var butaneRep report.Report
for _, entry := range ignitionReport.Entries {
butaneEntry := report.Entry{
Kind: entry.Kind,
Message: entry.Message,
Context: entry.Context,
Marker: entry.Marker,
}
butaneRep.Entries = append(butaneRep.Entries, butaneEntry)
}
return butaneRep
}

func (fs Filesystem) Validate(c path.ContextPath) (r report.Report) {
if !util.IsTrue(fs.WithMountUnit) {
return
Expand Down
14 changes: 7 additions & 7 deletions base/v0_6_exp/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestValidateResource(t *testing.T) {
// local specified
{
Resource{
Local: util.StrToPtr("hello"),
Local: util.StrToPtr("{\"ignition\": {\"version\": \"3.5.0\"}}"),
Compression: util.StrToPtr("gzip"),
Verification: Verification{
Hash: util.StrToPtr("this isn't validated"),
Expand All @@ -77,7 +77,7 @@ func TestValidateResource(t *testing.T) {
{
Resource{
Source: util.StrToPtr("data:,hello"),
Inline: util.StrToPtr("hello"),
Inline: util.StrToPtr("{\"ignition\": {\"version\": \"3.5.0\"}}"),
Compression: util.StrToPtr("gzip"),
Verification: Verification{
Hash: util.StrToPtr("this isn't validated"),
Expand All @@ -90,7 +90,7 @@ func TestValidateResource(t *testing.T) {
{
Resource{
Source: util.StrToPtr("data:,hello"),
Local: util.StrToPtr("hello"),
Local: util.StrToPtr("{\"ignition\": {\"version\": \"3.5.0\"}}"),
Compression: util.StrToPtr("gzip"),
Verification: Verification{
Hash: util.StrToPtr("this isn't validated"),
Expand All @@ -102,8 +102,8 @@ func TestValidateResource(t *testing.T) {
// inline + local, invalid
{
Resource{
Inline: util.StrToPtr("hello"),
Local: util.StrToPtr("hello"),
Inline: util.StrToPtr("{\"ignition\": {\"version\": \"3.5.0\"}}"),
Local: util.StrToPtr("{\"ignition\": {\"version\": \"3.5.0\"}}"),
Compression: util.StrToPtr("gzip"),
Verification: Verification{
Hash: util.StrToPtr("this isn't validated"),
Expand All @@ -116,8 +116,8 @@ func TestValidateResource(t *testing.T) {
{
Resource{
Source: util.StrToPtr("data:,hello"),
Inline: util.StrToPtr("hello"),
Local: util.StrToPtr("hello"),
Inline: util.StrToPtr("{\"ignition\": {\"version\": \"3.5.0\"}}"),
Local: util.StrToPtr("{\"ignition\": {\"version\": \"3.5.0\"}}"),
Compression: util.StrToPtr("gzip"),
Verification: Verification{
Hash: util.StrToPtr("this isn't validated"),
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ key](https://getfedora.org/security/).
openshift 4.14.0-exp)_
- Require `storage.filesystems.path` to start with `/etc` or `/var` if
`with_mount_unit` is true _(fcos 1.6.0-exp, openshift 4.14.0-exp)_
- Validate merged/replaced ignition configs if they are local/inline _(fcos 1.6.0-exp)_

### Bug fixes

Expand Down
187 changes: 187 additions & 0 deletions vendor/github.com/coreos/ignition/v2/config/translate/translate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions vendor/github.com/coreos/ignition/v2/config/v3_0/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 986194b

Please sign in to comment.