mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-10-21 14:38:46 +00:00
Merge branch 'master' into keymutex
This commit is contained in:
1
vendor/BUILD
vendored
1
vendor/BUILD
vendored
@@ -474,6 +474,7 @@ filegroup(
|
||||
"//vendor/k8s.io/utils/io:all-srcs",
|
||||
"//vendor/k8s.io/utils/keymutex:all-srcs",
|
||||
"//vendor/k8s.io/utils/nsenter:all-srcs",
|
||||
"//vendor/k8s.io/utils/path:all-srcs",
|
||||
"//vendor/k8s.io/utils/pointer:all-srcs",
|
||||
"//vendor/k8s.io/utils/strings:all-srcs",
|
||||
"//vendor/k8s.io/utils/trace:all-srcs",
|
||||
|
17
vendor/github.com/evanphx/json-patch/README.md
generated
vendored
17
vendor/github.com/evanphx/json-patch/README.md
generated
vendored
@@ -25,6 +25,23 @@ go get -u github.com/evanphx/json-patch
|
||||
* [Comparing JSON documents](#comparing-json-documents)
|
||||
* [Combine merge patches](#combine-merge-patches)
|
||||
|
||||
|
||||
# Configuration
|
||||
|
||||
* There is a global configuration variable `jsonpatch.SupportNegativeIndices`.
|
||||
This defaults to `true` and enables the non-standard practice of allowing
|
||||
negative indices to mean indices starting at the end of an array. This
|
||||
functionality can be disabled by setting `jsonpatch.SupportNegativeIndices =
|
||||
false`.
|
||||
|
||||
* There is a global configuration variable `jsonpatch.ArraySizeLimit`, which
|
||||
limits the length of any array the patched object can have. It defaults to 0,
|
||||
which means there is no limit.
|
||||
|
||||
* There is a global configuration variable `jsonpatch.ArraySizeAdditionLimit`,
|
||||
which limits the increase of array length caused by each operation. It
|
||||
defaults to 0, which means there is no limit.
|
||||
|
||||
## Create and apply a merge patch
|
||||
Given both an original JSON document and a modified JSON document, you can create
|
||||
a [Merge Patch](https://tools.ietf.org/html/rfc7396) document.
|
||||
|
68
vendor/github.com/evanphx/json-patch/patch.go
generated
vendored
68
vendor/github.com/evanphx/json-patch/patch.go
generated
vendored
@@ -14,6 +14,10 @@ const (
|
||||
eAry
|
||||
)
|
||||
|
||||
var SupportNegativeIndices bool = true
|
||||
var ArraySizeLimit int = 0
|
||||
var ArraySizeAdditionLimit int = 0
|
||||
|
||||
type lazyNode struct {
|
||||
raw *json.RawMessage
|
||||
doc partialDoc
|
||||
@@ -61,6 +65,19 @@ func (n *lazyNode) UnmarshalJSON(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy(src *lazyNode) (*lazyNode, error) {
|
||||
if src == nil {
|
||||
return nil, nil
|
||||
}
|
||||
a, err := src.MarshalJSON()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ra := make(json.RawMessage, len(a))
|
||||
copy(ra, a)
|
||||
return newLazyNode(&ra), nil
|
||||
}
|
||||
|
||||
func (n *lazyNode) intoDoc() (*partialDoc, error) {
|
||||
if n.which == eDoc {
|
||||
return &n.doc, nil
|
||||
@@ -354,10 +371,19 @@ func (d *partialArray) set(key string, val *lazyNode) error {
|
||||
}
|
||||
|
||||
sz := len(*d)
|
||||
|
||||
if diff := idx + 1 - sz; ArraySizeAdditionLimit > 0 && diff > ArraySizeAdditionLimit {
|
||||
return fmt.Errorf("Unable to increase the array size by %d, the limit is %d", diff, ArraySizeAdditionLimit)
|
||||
}
|
||||
|
||||
if idx+1 > sz {
|
||||
sz = idx + 1
|
||||
}
|
||||
|
||||
if ArraySizeLimit > 0 && sz > ArraySizeLimit {
|
||||
return fmt.Errorf("Unable to create array of size %d, limit is %d", sz, ArraySizeLimit)
|
||||
}
|
||||
|
||||
ary := make([]*lazyNode, sz)
|
||||
|
||||
cur := *d
|
||||
@@ -385,17 +411,29 @@ func (d *partialArray) add(key string, val *lazyNode) error {
|
||||
return err
|
||||
}
|
||||
|
||||
ary := make([]*lazyNode, len(*d)+1)
|
||||
sz := len(*d) + 1
|
||||
if ArraySizeLimit > 0 && sz > ArraySizeLimit {
|
||||
return fmt.Errorf("Unable to create array of size %d, limit is %d", sz, ArraySizeLimit)
|
||||
}
|
||||
|
||||
ary := make([]*lazyNode, sz)
|
||||
|
||||
cur := *d
|
||||
|
||||
if idx < -len(ary) || idx >= len(ary) {
|
||||
if idx >= len(ary) {
|
||||
return fmt.Errorf("Unable to access invalid index: %d", idx)
|
||||
}
|
||||
|
||||
if idx < 0 {
|
||||
idx += len(ary)
|
||||
if SupportNegativeIndices {
|
||||
if idx < -len(ary) {
|
||||
return fmt.Errorf("Unable to access invalid index: %d", idx)
|
||||
}
|
||||
|
||||
if idx < 0 {
|
||||
idx += len(ary)
|
||||
}
|
||||
}
|
||||
|
||||
copy(ary[0:idx], cur[0:idx])
|
||||
ary[idx] = val
|
||||
copy(ary[idx+1:], cur[idx:])
|
||||
@@ -426,11 +464,18 @@ func (d *partialArray) remove(key string) error {
|
||||
|
||||
cur := *d
|
||||
|
||||
if idx < -len(cur) || idx >= len(cur) {
|
||||
return fmt.Errorf("Unable to remove invalid index: %d", idx)
|
||||
if idx >= len(cur) {
|
||||
return fmt.Errorf("Unable to access invalid index: %d", idx)
|
||||
}
|
||||
if idx < 0 {
|
||||
idx += len(cur)
|
||||
|
||||
if SupportNegativeIndices {
|
||||
if idx < -len(cur) {
|
||||
return fmt.Errorf("Unable to access invalid index: %d", idx)
|
||||
}
|
||||
|
||||
if idx < 0 {
|
||||
idx += len(cur)
|
||||
}
|
||||
}
|
||||
|
||||
ary := make([]*lazyNode, len(cur)-1)
|
||||
@@ -567,7 +612,12 @@ func (p Patch) copy(doc *container, op operation) error {
|
||||
return fmt.Errorf("jsonpatch copy operation does not apply: doc is missing destination path: %s", path)
|
||||
}
|
||||
|
||||
return con.set(key, val)
|
||||
valCopy, err := deepCopy(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return con.add(key, valCopy)
|
||||
}
|
||||
|
||||
// Equal indicates if 2 JSON documents have the same structural equality.
|
||||
|
23
vendor/k8s.io/utils/path/BUILD
generated
vendored
Normal file
23
vendor/k8s.io/utils/path/BUILD
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["file.go"],
|
||||
importmap = "k8s.io/kubernetes/vendor/k8s.io/utils/path",
|
||||
importpath = "k8s.io/utils/path",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
78
vendor/k8s.io/utils/path/file.go
generated
vendored
Normal file
78
vendor/k8s.io/utils/path/file.go
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package path
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
// LinkTreatment is the base type for constants used by Exists that indicate
|
||||
// how symlinks are treated for existence checks.
|
||||
type LinkTreatment int
|
||||
|
||||
const (
|
||||
// CheckFollowSymlink follows the symlink and verifies that the target of
|
||||
// the symlink exists.
|
||||
CheckFollowSymlink LinkTreatment = iota
|
||||
|
||||
// CheckSymlinkOnly does not follow the symlink and verfies only that they
|
||||
// symlink itself exists.
|
||||
CheckSymlinkOnly
|
||||
)
|
||||
|
||||
// ErrInvalidLinkTreatment indicates that the link treatment behavior requested
|
||||
// is not a valid behavior.
|
||||
var ErrInvalidLinkTreatment = errors.New("unknown link behavior")
|
||||
|
||||
// Exists checks if specified file, directory, or symlink exists. The behavior
|
||||
// of the test depends on the linkBehaviour argument. See LinkTreatment for
|
||||
// more details.
|
||||
func Exists(linkBehavior LinkTreatment, filename string) (bool, error) {
|
||||
var err error
|
||||
|
||||
if linkBehavior == CheckFollowSymlink {
|
||||
_, err = os.Stat(filename)
|
||||
} else if linkBehavior == CheckSymlinkOnly {
|
||||
_, err = os.Lstat(filename)
|
||||
} else {
|
||||
return false, ErrInvalidLinkTreatment
|
||||
}
|
||||
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
} else if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// ReadDirNoStat returns a string of files/directories contained
|
||||
// in dirname without calling lstat on them.
|
||||
func ReadDirNoStat(dirname string) ([]string, error) {
|
||||
if dirname == "" {
|
||||
dirname = "."
|
||||
}
|
||||
|
||||
f, err := os.Open(dirname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
return f.Readdirnames(-1)
|
||||
}
|
Reference in New Issue
Block a user