mirror of
https://github.com/outbackdingo/matchbox.git
synced 2026-01-27 10:19:35 +00:00
bootcfg/http/ignition: Just warn for raw Ignition errors
* When raw Ignition (.ign/.ignition) content is provided, Parse the contents with ignition, but return the contents as JSON regardless of the result to respect user pass-through expectations * Warn on parse errors which can occur if a newer Ignition format is used than the version of Ignition that bootcfg was compiled with
This commit is contained in:
@@ -39,13 +39,11 @@ func ignitionHandler(srv server.Server) ContextHandler {
|
||||
|
||||
// Skip rendering if raw Ignition JSON is provided
|
||||
if isIgnition(profile.IgnitionId) {
|
||||
cfg, err := ignition.Parse([]byte(contents))
|
||||
_, err := ignition.Parse([]byte(contents))
|
||||
if err != nil {
|
||||
log.Errorf("error parsing Ignition JSON: %v", err)
|
||||
http.NotFound(w, req)
|
||||
return
|
||||
log.Warningf("warning parsing Ignition JSON: %v", err)
|
||||
}
|
||||
renderJSON(w, cfg)
|
||||
writeJSON(w, []byte(contents))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ var (
|
||||
)
|
||||
|
||||
func TestIgnitionHandler_V2JSON(t *testing.T) {
|
||||
content := `{"ignition":{"version":"2.0.0","config":{}},"systemd":{"units":[{"name":"etcd2.service","enable":true},{"name":"a1b2c3d4.service","enable":true}]}}`
|
||||
content := `{"ignition":{"version":"2.0.0","config":{}},"storage":{},"systemd":{"units":[{"name":"etcd2.service","enable":true},{"name":"a1b2c3d4.service","enable":true}]},"networkd":{},"passwd":{}}`
|
||||
profile := &storagepb.Profile{
|
||||
Id: fake.Group.Profile,
|
||||
IgnitionId: "file.ign",
|
||||
|
||||
@@ -21,9 +21,13 @@ func renderJSON(w http.ResponseWriter, v interface{}) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
writeJSON(w, js)
|
||||
}
|
||||
|
||||
// writeJSON writes the given bytes with a JSON Content-Type.
|
||||
func writeJSON(w http.ResponseWriter, data []byte) {
|
||||
w.Header().Set(contentType, jsonContentType)
|
||||
_, err = w.Write(js)
|
||||
_, err := w.Write(data)
|
||||
if err != nil {
|
||||
log.Errorf("error writing to response: %v", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user