Skip to content

Commit 0b4a65d

Browse files
committed
pkg/asset/imagebased/configimage: added support for json files in extramanifests directory
added additional code to support `.json` files in the extra-manifests directory when creating a config iso. updated test cases as well to test added functionality. Fixes #9134 Signed-off-by: xphyr <[email protected]>
1 parent 8032a54 commit 0b4a65d

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

pkg/asset/imagebased/configimage/extramanifests.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ func (em *ExtraManifests) Load(f asset.FileFetcher) (found bool, err error) {
4848
if err != nil {
4949
return false, fmt.Errorf("failed to load *.yml files: %w", err)
5050
}
51+
jsonFileList, err := f.FetchByPattern(filepath.Join(extraManifestsDir, "*.json"))
52+
if err != nil {
53+
return false, fmt.Errorf("failed to load *.json files: %w", err)
54+
}
5155

5256
em.FileList = append(em.FileList, yamlFileList...)
5357
em.FileList = append(em.FileList, ymlFileList...)
58+
em.FileList = append(em.FileList, jsonFileList...)
5459
asset.SortFiles(em.FileList)
5560

5661
return len(em.FileList) > 0, nil

pkg/asset/imagebased/configimage/extramanifests_test.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func TestExtraManifests_Load(t *testing.T) {
1919
files []string
2020
yamlFetchError error
2121
ymlFetchError error
22+
jsonFetchError error
2223

2324
expectedFound bool
2425
expectedFiles []string
@@ -46,16 +47,25 @@ func TestExtraManifests_Load(t *testing.T) {
4647
expectedFiles: []string{"/extra-manifests/another-test.yml"},
4748
},
4849
{
49-
name: "both",
50+
name: "only-json",
51+
files: []string{"/extra-manifests/test.json"},
52+
53+
expectedFound: true,
54+
expectedFiles: []string{"/extra-manifests/test.json"},
55+
},
56+
{
57+
name: "all",
5058
files: []string{
5159
"/extra-manifests/test.yaml",
5260
"/extra-manifests/another-test.yml",
61+
"/extra-manifests/test.json",
5362
},
5463

5564
expectedFound: true,
5665
expectedFiles: []string{
5766
"/extra-manifests/test.yaml",
5867
"/extra-manifests/another-test.yml",
68+
"/extra-manifests/test.json",
5969
},
6070
},
6171
{
@@ -70,12 +80,19 @@ func TestExtraManifests_Load(t *testing.T) {
7080

7181
expectedError: "failed to load *.yml files: file does not exist",
7282
},
83+
{
84+
name: "error",
85+
jsonFetchError: os.ErrNotExist,
86+
87+
expectedError: "failed to load *.json files: file does not exist",
88+
},
7389
}
7490

7591
for _, tc := range cases {
7692
t.Run(tc.name, func(t *testing.T) {
7793
yamlFiles := []*asset.File{}
7894
ymlFiles := []*asset.File{}
95+
jsonFiles := []*asset.File{}
7996
for _, f := range tc.files {
8097
assetFile := &asset.File{
8198
Filename: f,
@@ -87,6 +104,8 @@ func TestExtraManifests_Load(t *testing.T) {
87104
yamlFiles = append(yamlFiles, assetFile)
88105
case ".yml":
89106
ymlFiles = append(ymlFiles, assetFile)
107+
case ".json":
108+
jsonFiles = append(jsonFiles, assetFile)
90109
default:
91110
t.Error("invalid extension")
92111
}
@@ -101,7 +120,7 @@ func TestExtraManifests_Load(t *testing.T) {
101120
[]*asset.File{},
102121
tc.yamlFetchError,
103122
)
104-
} else {
123+
} else if tc.ymlFetchError != nil {
105124
fileFetcher.EXPECT().FetchByPattern("extra-manifests/*.yaml").Return(yamlFiles, nil)
106125

107126
if tc.ymlFetchError != nil {
@@ -112,6 +131,18 @@ func TestExtraManifests_Load(t *testing.T) {
112131
} else {
113132
fileFetcher.EXPECT().FetchByPattern("extra-manifests/*.yml").Return(ymlFiles, nil)
114133
}
134+
} else {
135+
fileFetcher.EXPECT().FetchByPattern("extra-manifests/*.yaml").Return(yamlFiles, nil)
136+
fileFetcher.EXPECT().FetchByPattern("extra-manifests/*.yml").Return(ymlFiles, nil)
137+
138+
if tc.jsonFetchError != nil {
139+
fileFetcher.EXPECT().FetchByPattern("extra-manifests/*.json").Return(
140+
[]*asset.File{},
141+
tc.jsonFetchError,
142+
)
143+
} else {
144+
fileFetcher.EXPECT().FetchByPattern("extra-manifests/*.json").Return(jsonFiles, nil)
145+
}
115146
}
116147

117148
extraManifestsAsset := &ExtraManifests{}

0 commit comments

Comments
 (0)