Skip to content

Commit 0d294cf

Browse files
Merge pull request #9136 from xphyr/issue9143
NO-ISSUE: imagebasedinstaller: support json files in extramanifests directory
2 parents 88723fd + b13a27b commit 0d294cf

File tree

3 files changed

+103
-11
lines changed

3 files changed

+103
-11
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Verify that the extra-manifests directory populates with the appropriate files
2+
3+
exec openshift-install image-based create config-image --dir $WORK
4+
5+
exists $WORK/imagebasedconfig.iso
6+
7+
isoContains imagebasedconfig.iso /extra-manifests/test.yaml
8+
isoContains imagebasedconfig.iso /extra-manifests/test.yml
9+
isoContains imagebasedconfig.iso /extra-manifests/test.json
10+
11+
-- install-config.yaml --
12+
apiVersion: v1
13+
baseDomain: test.metalkube.org
14+
controlPlane:
15+
name: master
16+
replicas: 1
17+
compute:
18+
- name: worker
19+
replicas: 0
20+
metadata:
21+
name: ostest
22+
networking:
23+
clusterNetwork:
24+
- cidr: 10.128.0.0/14
25+
hostPrefix: 23
26+
networkType: OVNKubernetes
27+
machineNetwork:
28+
- cidr: 192.168.111.0/24
29+
serviceNetwork:
30+
- 172.30.0.0/16
31+
platform:
32+
none: {}
33+
sshKey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDK6UTEydcEKzuNdPaofn8Z2DwgHqdcionLZBiPf/zIRNco++etLsat7Avv7yt04DINQd5zjxIFgG8jblaUB5E5C9ClUcMwb52GO0ay2Y9v1uBv1a4WhI3peKktAzYNk0EBMQlJtXPjRMrC9ylBPh+DsBHMu+KmDnfk7PIwyN4efC8k5kSRuPWoNdme1rz2+umU8FSmaWTHIajrbspf4GQbsntA5kuKEtDbfoNCU97o2KrRnUbeg3a8hwSjfh3u6MhlnGcg5K2Ij+zivEsWGCLKYUtE1ErqwfIzwWmJ6jnV66XCQGHf4Q1iIxqF7s2a1q24cgG2Z/iDXfqXrCIfy4P7b/Ztak3bdT9jfAdVZtdO5/r7I+O5hYhF86ayFlDWzZWP/ByiSb+q4CQbfVgK3BMmiAv2MqLHdhesmD/SmIcoOWUF6rFmRKZVFFpKpt5ATNTgUJ3JRowoXrrDruVXClUGRiCS6Zabd1rZ3VmTchaPJwtzQMdfIWISXj+Ig+C4UK0=
34+
pullSecret: '{"auths": {"quay.io": {"auth": "c3VwZXItc2VjcmV0Cg=="}}}'
35+
36+
-- image-based-config.yaml --
37+
apiVersion: v1beta1
38+
kind: ImageBasedConfig
39+
metadata:
40+
name: ostest
41+
namespace: cluster0
42+
hostname: ostest
43+
44+
-- extra-manifests/test.yaml --
45+
apiVersion: v1beta1
46+
kind: DummyData
47+
metadata:
48+
name: test.yaml
49+
50+
-- extra-manifests/test.yml --
51+
apiVersion: v1beta1
52+
kind: DummyData
53+
metadata:
54+
name: test.yml
55+
56+
-- extra-manifests/test.json --
57+
{
58+
"apiVersion": "v1beta1",
59+
"kind": "DummyData",
60+
"metadata": {
61+
"name": "test.json"
62+
}
63+
}

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: 35 additions & 11 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,23 @@ 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

91+
yamlPattern := "extra-manifests/*.yaml"
92+
ymlPattern := "extra-manifests/*.yml"
93+
jsonPattern := "extra-manifests/*.json"
94+
7595
for _, tc := range cases {
7696
t.Run(tc.name, func(t *testing.T) {
7797
yamlFiles := []*asset.File{}
7898
ymlFiles := []*asset.File{}
99+
jsonFiles := []*asset.File{}
79100
for _, f := range tc.files {
80101
assetFile := &asset.File{
81102
Filename: f,
@@ -87,6 +108,8 @@ func TestExtraManifests_Load(t *testing.T) {
87108
yamlFiles = append(yamlFiles, assetFile)
88109
case ".yml":
89110
ymlFiles = append(ymlFiles, assetFile)
111+
case ".json":
112+
jsonFiles = append(jsonFiles, assetFile)
90113
default:
91114
t.Error("invalid extension")
92115
}
@@ -96,21 +119,22 @@ func TestExtraManifests_Load(t *testing.T) {
96119
defer mockCtrl.Finish()
97120

98121
fileFetcher := mock.NewMockFileFetcher(mockCtrl)
122+
99123
if tc.yamlFetchError != nil {
100-
fileFetcher.EXPECT().FetchByPattern("extra-manifests/*.yaml").Return(
101-
[]*asset.File{},
102-
tc.yamlFetchError,
103-
)
124+
fileFetcher.EXPECT().FetchByPattern(yamlPattern).Return([]*asset.File{}, tc.yamlFetchError)
104125
} else {
105-
fileFetcher.EXPECT().FetchByPattern("extra-manifests/*.yaml").Return(yamlFiles, nil)
126+
fileFetcher.EXPECT().FetchByPattern(yamlPattern).Return(yamlFiles, nil)
106127

107128
if tc.ymlFetchError != nil {
108-
fileFetcher.EXPECT().FetchByPattern("extra-manifests/*.yml").Return(
109-
[]*asset.File{},
110-
tc.ymlFetchError,
111-
)
129+
fileFetcher.EXPECT().FetchByPattern(ymlPattern).Return([]*asset.File{}, tc.ymlFetchError)
112130
} else {
113-
fileFetcher.EXPECT().FetchByPattern("extra-manifests/*.yml").Return(ymlFiles, nil)
131+
fileFetcher.EXPECT().FetchByPattern(ymlPattern).Return(ymlFiles, nil)
132+
133+
if tc.jsonFetchError != nil {
134+
fileFetcher.EXPECT().FetchByPattern(jsonPattern).Return([]*asset.File{}, tc.jsonFetchError)
135+
} else {
136+
fileFetcher.EXPECT().FetchByPattern(jsonPattern).Return(jsonFiles, nil)
137+
}
114138
}
115139
}
116140

0 commit comments

Comments
 (0)