Report StatusConflict on Pod opt partial failures

- When one or more containers in the Pod reports an error on an operation
report StatusConflict and report the error(s)

- jsoniter type encoding used to marshal error as string using error.Error()

- Update test framework to allow setting any flag when creating pods

- Fix test_resize() result check

Fixes #8865

Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
Jhon Honce
2021-01-19 09:16:01 -07:00
parent d66a18cb11
commit 7e4d696d94
23 changed files with 352 additions and 199 deletions

View File

@ -1,16 +1,17 @@
package utils
import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"os"
"strings"
"unsafe"
"github.com/blang/semver"
"github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@ -144,6 +145,50 @@ func WriteResponse(w http.ResponseWriter, code int, value interface{}) {
}
}
func init() {
jsoniter.RegisterTypeEncoderFunc("error", MarshalErrorJSON, MarshalErrorJSONIsEmpty)
jsoniter.RegisterTypeEncoderFunc("[]error", MarshalErrorSliceJSON, MarshalErrorSliceJSONIsEmpty)
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// MarshalErrorJSON writes error to stream as string
func MarshalErrorJSON(ptr unsafe.Pointer, stream *jsoniter.Stream) {
p := *((*error)(ptr))
if p == nil {
stream.WriteNil()
} else {
stream.WriteString(p.Error())
}
}
// MarshalErrorSliceJSON writes []error to stream as []string JSON blob
func MarshalErrorSliceJSON(ptr unsafe.Pointer, stream *jsoniter.Stream) {
a := *((*[]error)(ptr))
switch {
case len(a) == 0:
stream.WriteNil()
default:
stream.WriteArrayStart()
for i, e := range a {
if i > 0 {
stream.WriteMore()
}
stream.WriteString(e.Error())
}
stream.WriteArrayEnd()
}
}
func MarshalErrorJSONIsEmpty(_ unsafe.Pointer) bool {
return false
}
func MarshalErrorSliceJSONIsEmpty(_ unsafe.Pointer) bool {
return false
}
// WriteJSON writes an interface value encoded as JSON to w
func WriteJSON(w http.ResponseWriter, code int, value interface{}) {
// FIXME: we don't need to write the header in all/some circumstances.
w.Header().Set("Content-Type", "application/json")