Skip to content

Commit d1c334b

Browse files
committed
base/v0_6_exp/validate.go: Added switch statement for Validate Resource
base/v0_6_exp/validate.go: Add mapper function and fix tests
1 parent 0a1b18e commit d1c334b

File tree

16 files changed

+1116
-6
lines changed

16 files changed

+1116
-6
lines changed

base/v0_6_exp/validate.go

+34-1
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,24 @@ import (
1919
"github.com/coreos/butane/config/common"
2020

2121
"github.com/coreos/ignition/v2/config/util"
22+
exp "github.com/coreos/ignition/v2/config/v3_5_experimental"
2223
"github.com/coreos/vcontext/path"
2324
"github.com/coreos/vcontext/report"
2425
)
2526

2627
func (rs Resource) Validate(c path.ContextPath) (r report.Report) {
2728
var field string
2829
sources := 0
30+
var config string
31+
var butaneReport report.Report
2932
if rs.Local != nil {
3033
sources++
31-
field = "local"
34+
config = *rs.Local
3235
}
3336
if rs.Inline != nil {
3437
sources++
3538
field = "inline"
39+
config = *rs.Inline
3640
}
3741
if rs.Source != nil {
3842
sources++
@@ -41,9 +45,38 @@ func (rs Resource) Validate(c path.ContextPath) (r report.Report) {
4145
if sources > 1 {
4246
r.AddOnError(c.Append(field), common.ErrTooManyResourceSources)
4347
}
48+
if field == "local" || field == "inline" {
49+
// check if it's an ignition config, will fix error on fcos
50+
if len(config) > 0 && config[0] == '{' {
51+
_, report, err := exp.Parse([]byte(config))
52+
if len(report.Entries) > 0 {
53+
butaneReport = MapIgnitionReportToButane(report)
54+
// convert report into butane specific report then merge it
55+
r.Merge(butaneReport)
56+
}
57+
if err != nil {
58+
r.AddOnError(c.Append(field), common.ErrNoFilesDir)
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

+8-5
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"),
@@ -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"),
@@ -103,7 +103,7 @@ func TestValidateResource(t *testing.T) {
103103
{
104104
Resource{
105105
Inline: util.StrToPtr("hello"),
106-
Local: util.StrToPtr("hello"),
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"),
@@ -139,6 +139,9 @@ func TestValidateResource(t *testing.T) {
139139
}
140140
}
141141

142+
func TestMapperFunction(t *testing.T) {
143+
144+
}
142145
func TestValidateTree(t *testing.T) {
143146
tests := []struct {
144147
in Tree

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)