mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rebase: update kubernetes to v1.21.2
Updated kubernetes packages to latest release. resizefs package has been included into k8s.io/mount-utils package. updated code to use the same. Updates: #1968 Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
42
vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
generated
vendored
42
vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
generated
vendored
@ -22,13 +22,11 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
jsonutil "k8s.io/apimachinery/pkg/util/json"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@ -215,16 +213,15 @@ type YAMLOrJSONDecoder struct {
|
||||
bufferSize int
|
||||
|
||||
decoder decoder
|
||||
rawData []byte
|
||||
}
|
||||
|
||||
type JSONSyntaxError struct {
|
||||
Line int
|
||||
Err error
|
||||
Offset int64
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e JSONSyntaxError) Error() string {
|
||||
return fmt.Sprintf("json: line %d: %s", e.Line, e.Err.Error())
|
||||
return fmt.Sprintf("json: offset %d: %s", e.Offset, e.Err.Error())
|
||||
}
|
||||
|
||||
type YAMLSyntaxError struct {
|
||||
@ -250,35 +247,18 @@ func NewYAMLOrJSONDecoder(r io.Reader, bufferSize int) *YAMLOrJSONDecoder {
|
||||
// provide object, or returns an error.
|
||||
func (d *YAMLOrJSONDecoder) Decode(into interface{}) error {
|
||||
if d.decoder == nil {
|
||||
buffer, origData, isJSON := GuessJSONStream(d.r, d.bufferSize)
|
||||
buffer, _, isJSON := GuessJSONStream(d.r, d.bufferSize)
|
||||
if isJSON {
|
||||
d.decoder = json.NewDecoder(buffer)
|
||||
d.rawData = origData
|
||||
} else {
|
||||
d.decoder = NewYAMLToJSONDecoder(buffer)
|
||||
}
|
||||
}
|
||||
err := d.decoder.Decode(into)
|
||||
if jsonDecoder, ok := d.decoder.(*json.Decoder); ok {
|
||||
if syntax, ok := err.(*json.SyntaxError); ok {
|
||||
data, readErr := ioutil.ReadAll(jsonDecoder.Buffered())
|
||||
if readErr != nil {
|
||||
klog.V(4).Infof("reading stream failed: %v", readErr)
|
||||
}
|
||||
js := string(data)
|
||||
|
||||
// if contents from io.Reader are not complete,
|
||||
// use the original raw data to prevent panic
|
||||
if int64(len(js)) <= syntax.Offset {
|
||||
js = string(d.rawData)
|
||||
}
|
||||
|
||||
start := strings.LastIndex(js[:syntax.Offset], "\n") + 1
|
||||
line := strings.Count(js[:start], "\n")
|
||||
return JSONSyntaxError{
|
||||
Line: line,
|
||||
Err: fmt.Errorf(syntax.Error()),
|
||||
}
|
||||
if syntax, ok := err.(*json.SyntaxError); ok {
|
||||
return JSONSyntaxError{
|
||||
Offset: syntax.Offset,
|
||||
Err: syntax,
|
||||
}
|
||||
}
|
||||
return err
|
||||
@ -363,6 +343,12 @@ func GuessJSONStream(r io.Reader, size int) (io.Reader, []byte, bool) {
|
||||
return buffer, b, hasJSONPrefix(b)
|
||||
}
|
||||
|
||||
// IsJSONBuffer scans the provided buffer, looking
|
||||
// for an open brace indicating this is JSON.
|
||||
func IsJSONBuffer(buf []byte) bool {
|
||||
return hasJSONPrefix(buf)
|
||||
}
|
||||
|
||||
var jsonPrefix = []byte("{")
|
||||
|
||||
// hasJSONPrefix returns true if the provided buffer appears to start with
|
||||
|
Reference in New Issue
Block a user