Skip to content

Commit 8ee89ab

Browse files
coreosbotAdam0Brien
authored andcommitted
base/v0_6_exp/validate.go: Add Validation when merging local/inline sources
base/v0_6_exp/validate.go: Add mapper function and fix tests
1 parent 0a1b18e commit 8ee89ab

File tree

17 files changed

+1111
-10
lines changed

17 files changed

+1111
-10
lines changed

base/v0_6_exp/validate.go

+29-2
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@ package v0_6_exp
1717
import (
1818
baseutil "github.com/coreos/butane/base/util"
1919
"github.com/coreos/butane/config/common"
20-
2120
"github.com/coreos/ignition/v2/config/util"
21+
exp "github.com/coreos/ignition/v2/config/v3_5_experimental"
2222
"github.com/coreos/vcontext/path"
2323
"github.com/coreos/vcontext/report"
2424
)
2525

2626
func (rs Resource) Validate(c path.ContextPath) (r report.Report) {
2727
var field string
2828
sources := 0
29+
var config string
30+
var butaneReport report.Report
2931
if rs.Local != nil {
3032
sources++
31-
field = "local"
33+
config = *rs.Local
3234
}
3335
if rs.Inline != nil {
3436
sources++
3537
field = "inline"
38+
config = *rs.Inline
3639
}
3740
if rs.Source != nil {
3841
sources++
@@ -41,9 +44,33 @@ func (rs Resource) Validate(c path.ContextPath) (r report.Report) {
4144
if sources > 1 {
4245
r.AddOnError(c.Append(field), common.ErrTooManyResourceSources)
4346
}
47+
if field == "local" || field == "inline" {
48+
_, report, err := exp.Parse([]byte(config))
49+
if len(report.Entries) > 0 {
50+
butaneReport = MapIgnitionReportToButane(report)
51+
r.Merge(butaneReport)
52+
}
53+
if err != nil {
54+
r.AddOnWarn(c.Append(field), common.ErrUnknownVersion)
55+
}
56+
}
4457
return
4558
}
4659

60+
func MapIgnitionReportToButane(ignitionReport report.Report) report.Report {
61+
var butaneRep report.Report
62+
for _, entry := range ignitionReport.Entries {
63+
butaneEntry := report.Entry{
64+
Kind: entry.Kind,
65+
Message: entry.Message,
66+
Context: entry.Context,
67+
Marker: entry.Marker,
68+
}
69+
butaneRep.Entries = append(butaneRep.Entries, butaneEntry)
70+
}
71+
return butaneRep
72+
}
73+
4774
func (fs Filesystem) Validate(c path.ContextPath) (r report.Report) {
4875
if !util.IsTrue(fs.WithMountUnit) {
4976
return

base/v0_6_exp/validate_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestValidateResource(t *testing.T) {
6464
// local specified
6565
{
6666
Resource{
67-
Local: util.StrToPtr("hello"),
67+
Local: util.StrToPtr("{\"ignition\": {\"version\": \"3.5.0\"}}"),
6868
Compression: util.StrToPtr("gzip"),
6969
Verification: Verification{
7070
Hash: util.StrToPtr("this isn't validated"),
@@ -77,7 +77,7 @@ func TestValidateResource(t *testing.T) {
7777
{
7878
Resource{
7979
Source: util.StrToPtr("data:,hello"),
80-
Inline: util.StrToPtr("hello"),
80+
Inline: util.StrToPtr("{\"ignition\": {\"version\": \"3.5.0\"}}"),
8181
Compression: util.StrToPtr("gzip"),
8282
Verification: Verification{
8383
Hash: util.StrToPtr("this isn't validated"),
@@ -90,7 +90,7 @@ func TestValidateResource(t *testing.T) {
9090
{
9191
Resource{
9292
Source: util.StrToPtr("data:,hello"),
93-
Local: util.StrToPtr("hello"),
93+
Local: util.StrToPtr("{\"ignition\": {\"version\": \"3.5.0\"}}"),
9494
Compression: util.StrToPtr("gzip"),
9595
Verification: Verification{
9696
Hash: util.StrToPtr("this isn't validated"),
@@ -102,8 +102,8 @@ func TestValidateResource(t *testing.T) {
102102
// inline + local, invalid
103103
{
104104
Resource{
105-
Inline: util.StrToPtr("hello"),
106-
Local: util.StrToPtr("hello"),
105+
Inline: util.StrToPtr("{\"ignition\": {\"version\": \"3.5.0\"}}"),
106+
Local: util.StrToPtr("{\"ignition\": {\"version\": \"3.5.0\"}}"),
107107
Compression: util.StrToPtr("gzip"),
108108
Verification: Verification{
109109
Hash: util.StrToPtr("this isn't validated"),
@@ -116,8 +116,8 @@ func TestValidateResource(t *testing.T) {
116116
{
117117
Resource{
118118
Source: util.StrToPtr("data:,hello"),
119-
Inline: util.StrToPtr("hello"),
120-
Local: util.StrToPtr("hello"),
119+
Inline: util.StrToPtr("{\"ignition\": {\"version\": \"3.5.0\"}}"),
120+
Local: util.StrToPtr("{\"ignition\": {\"version\": \"3.5.0\"}}"),
121121
Compression: util.StrToPtr("gzip"),
122122
Verification: Verification{
123123
Hash: util.StrToPtr("this isn't validated"),

docs/_config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ kramdown:
1414
ndash: "--"
1515
mdash: "---"
1616

17-
remote_theme: just-the-docs/just-the-docs@v0.5.3
17+
remote_theme: just-the-docs/just-the-docs@v0.6.0
1818
plugins:
1919
- jekyll-remote-theme
2020

docs/release-notes.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ key](https://getfedora.org/security/).
2121
openshift 4.14.0-exp)_
2222
- Require `storage.filesystems.path` to start with `/etc` or `/var` if
2323
`with_mount_unit` is true _(fcos 1.6.0-exp, openshift 4.14.0-exp)_
24+
- Validate merged/replaced ignition configs if they are local/inline _(fcos 1.6.0-exp)_
2425

2526
### Bug fixes
2627

vendor/github.com/coreos/ignition/v2/config/translate/translate.go

+187
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/coreos/ignition/v2/config/v3_0/config.go

+73
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)