Skip to content

Commit c6358d1

Browse files
committed
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 drop this
1 parent 0a1b18e commit c6358d1

File tree

16 files changed

+1116
-9
lines changed

16 files changed

+1116
-9
lines changed

base/v0_6_exp/validate.go

+35-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,39 @@ 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+
// check if it's an ignition config
49+
if len(config) > 0 && config[0] == '{' {
50+
_, report, err := exp.Parse([]byte(config))
51+
if len(report.Entries) > 0 {
52+
butaneReport = MapIgnitionReportToButane(report)
53+
r.Merge(butaneReport)
54+
}
55+
if err != nil {
56+
if err == common.ErrNoFilesDir {
57+
r.AddOnError(c.Append(field), common.ErrNoFilesDir)
58+
}
59+
}
60+
}
61+
}
62+
4463
return
4564
}
4665

66+
func MapIgnitionReportToButane(ignitionReport report.Report) report.Report {
67+
var butaneRep report.Report
68+
for _, entry := range ignitionReport.Entries {
69+
butaneEntry := report.Entry{
70+
Kind: entry.Kind,
71+
Message: entry.Message,
72+
Context: entry.Context,
73+
Marker: entry.Marker,
74+
}
75+
butaneRep.Entries = append(butaneRep.Entries, butaneEntry)
76+
}
77+
return butaneRep
78+
}
79+
4780
func (fs Filesystem) Validate(c path.ContextPath) (r report.Report) {
4881
if !util.IsTrue(fs.WithMountUnit) {
4982
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/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)