Skip to content

Commit fa3e48d

Browse files
[artifacts] Allow unknown fields in the artifact manifest (#1486)
Summary: Allow unknown fields in the artifact manifest. This is in preparation for changes to the manifest format, which will add a field. This PR ensures that clouds that are unaware of the new changes to the format, won't error when trying to decode the manifest.json. Type of change: /kind cleanup Test Plan: Added a test that ensures that the new manifest field can be in the manifest, and it can still be successfully decoded. Signed-off-by: James Bartlett <jamesbartlett@pixielabs.ai>
1 parent ae50966 commit fa3e48d

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/shared/artifacts/manifest/json.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ func (a *ArtifactManifest) MarshalJSON() ([]byte, error) {
5656

5757
func (as *sortedArtifactSet) UnmarshalJSON(b []byte) error {
5858
pb := &versionspb.ArtifactSet{}
59-
if err := jsonpb.Unmarshal(bytes.NewReader(b), pb); err != nil {
59+
u := &jsonpb.Unmarshaler{
60+
AllowUnknownFields: true,
61+
}
62+
if err := u.Unmarshal(bytes.NewReader(b), pb); err != nil {
6063
return err
6164
}
6265
as.name = pb.Name

src/shared/artifacts/manifest/manifest_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,56 @@ func TestManifest_JSONDecode(t *testing.T) {
203203
},
204204
},
205205
},
206+
{
207+
name: "single artifact set with artifact mirrors",
208+
json: fmt.Sprintf(`
209+
[
210+
{"name": "vizier", "artifact": [{
211+
"timestamp": "%s",
212+
"commitHash": "1234",
213+
"versionStr": "0.12.17",
214+
"availableArtifacts": [
215+
"AT_CONTAINER_SET_LINUX_AMD64",
216+
"AT_CONTAINER_SET_YAMLS",
217+
"AT_CONTAINER_SET_TEMPLATE_YAMLS"
218+
],
219+
"availableArtifactMirrors": [
220+
{
221+
"artifactType": "AT_CONTAINER_SET_YAMLS",
222+
"urls": [
223+
"https://artifacts.px.dev/testing"
224+
]
225+
},
226+
{
227+
"artifactType": "AT_CONTAINER_SET_TEMPLATE_YAMLS",
228+
"urls": [
229+
"https://artifacts.px.dev/testing_template"
230+
]
231+
}
232+
],
233+
"changelog": "changelog1"
234+
}]}
235+
]
236+
`, time1Str),
237+
expectedArtifactSets: []*versionspb.ArtifactSet{
238+
{
239+
Name: "vizier",
240+
Artifact: []*versionspb.Artifact{
241+
{
242+
Timestamp: time1Proto,
243+
CommitHash: "1234",
244+
VersionStr: "0.12.17",
245+
AvailableArtifacts: []versionspb.ArtifactType{
246+
versionspb.AT_CONTAINER_SET_LINUX_AMD64,
247+
versionspb.AT_CONTAINER_SET_YAMLS,
248+
versionspb.AT_CONTAINER_SET_TEMPLATE_YAMLS,
249+
},
250+
Changelog: "changelog1",
251+
},
252+
},
253+
},
254+
},
255+
},
206256
}
207257

208258
for _, tc := range testCases {

0 commit comments

Comments
 (0)