[VOL-1866] Changed module dependency to v12.0.0 of k8s client-go and v1.15.4 of k8s api/apimachinery in sync with other voltha components
Had to use pseudo-version corresponding to v12.0.0 of k8s client-go
because golang proxy is no longer serving the modules not complying
to Semantic Import Versioning rules including client-go v12.0.0.
Refer to https://github.com/kubernetes/client-go/issues/631 and
https://github.com/golang/go/issues/33558
Change-Id: I2e558bab7f0702f230761319eb5392a7d0532ea3
diff --git a/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go b/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go
index afd97f7..f4201eb 100644
--- a/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go
+++ b/vendor/k8s.io/apimachinery/pkg/api/errors/errors.go
@@ -394,7 +394,11 @@
case http.StatusNotAcceptable:
reason = metav1.StatusReasonNotAcceptable
// the server message has details about what types are acceptable
- message = serverMessage
+ if len(serverMessage) == 0 || serverMessage == "unknown" {
+ message = "the server was unable to respond with a content type that the client supports"
+ } else {
+ message = serverMessage
+ }
case http.StatusUnsupportedMediaType:
reason = metav1.StatusReasonUnsupportedMediaType
// the server message has details about what types are acceptable
@@ -617,3 +621,46 @@
}
return metav1.StatusReasonUnknown
}
+
+// ErrorReporter converts generic errors into runtime.Object errors without
+// requiring the caller to take a dependency on meta/v1 (where Status lives).
+// This prevents circular dependencies in core watch code.
+type ErrorReporter struct {
+ code int
+ verb string
+ reason string
+}
+
+// NewClientErrorReporter will respond with valid v1.Status objects that report
+// unexpected server responses. Primarily used by watch to report errors when
+// we attempt to decode a response from the server and it is not in the form
+// we expect. Because watch is a dependency of the core api, we can't return
+// meta/v1.Status in that package and so much inject this interface to convert a
+// generic error as appropriate. The reason is passed as a unique status cause
+// on the returned status, otherwise the generic "ClientError" is returned.
+func NewClientErrorReporter(code int, verb string, reason string) *ErrorReporter {
+ return &ErrorReporter{
+ code: code,
+ verb: verb,
+ reason: reason,
+ }
+}
+
+// AsObject returns a valid error runtime.Object (a v1.Status) for the given
+// error, using the code and verb of the reporter type. The error is set to
+// indicate that this was an unexpected server response.
+func (r *ErrorReporter) AsObject(err error) runtime.Object {
+ status := NewGenericServerResponse(r.code, r.verb, schema.GroupResource{}, "", err.Error(), 0, true)
+ if status.ErrStatus.Details == nil {
+ status.ErrStatus.Details = &metav1.StatusDetails{}
+ }
+ reason := r.reason
+ if len(reason) == 0 {
+ reason = "ClientError"
+ }
+ status.ErrStatus.Details.Causes = append(status.ErrStatus.Details.Causes, metav1.StatusCause{
+ Type: metav1.CauseType(reason),
+ Message: err.Error(),
+ })
+ return &status.ErrStatus
+}
diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/help.go b/vendor/k8s.io/apimachinery/pkg/api/meta/help.go
index 3425055..50468b5 100644
--- a/vendor/k8s.io/apimachinery/pkg/api/meta/help.go
+++ b/vendor/k8s.io/apimachinery/pkg/api/meta/help.go
@@ -17,30 +17,76 @@
package meta
import (
+ "errors"
"fmt"
"reflect"
+ "sync"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/apimachinery/pkg/runtime"
)
-// IsListType returns true if the provided Object has a slice called Items
+var (
+ // isListCache maintains a cache of types that are checked for lists
+ // which is used by IsListType.
+ // TODO: remove and replace with an interface check
+ isListCache = struct {
+ lock sync.RWMutex
+ byType map[reflect.Type]bool
+ }{
+ byType: make(map[reflect.Type]bool, 1024),
+ }
+)
+
+// IsListType returns true if the provided Object has a slice called Items.
+// TODO: Replace the code in this check with an interface comparison by
+// creating and enforcing that lists implement a list accessor.
func IsListType(obj runtime.Object) bool {
- // if we're a runtime.Unstructured, check whether this is a list.
- // TODO: refactor GetItemsPtr to use an interface that returns []runtime.Object
- if unstructured, ok := obj.(runtime.Unstructured); ok {
- return unstructured.IsList()
+ switch t := obj.(type) {
+ case runtime.Unstructured:
+ return t.IsList()
+ }
+ t := reflect.TypeOf(obj)
+
+ isListCache.lock.RLock()
+ ok, exists := isListCache.byType[t]
+ isListCache.lock.RUnlock()
+
+ if !exists {
+ _, err := getItemsPtr(obj)
+ ok = err == nil
+
+ // cache only the first 1024 types
+ isListCache.lock.Lock()
+ if len(isListCache.byType) < 1024 {
+ isListCache.byType[t] = ok
+ }
+ isListCache.lock.Unlock()
}
- _, err := GetItemsPtr(obj)
- return err == nil
+ return ok
}
+var (
+ errExpectFieldItems = errors.New("no Items field in this object")
+ errExpectSliceItems = errors.New("Items field must be a slice of objects")
+)
+
// GetItemsPtr returns a pointer to the list object's Items member.
// If 'list' doesn't have an Items member, it's not really a list type
// and an error will be returned.
// This function will either return a pointer to a slice, or an error, but not both.
+// TODO: this will be replaced with an interface in the future
func GetItemsPtr(list runtime.Object) (interface{}, error) {
+ obj, err := getItemsPtr(list)
+ if err != nil {
+ return nil, fmt.Errorf("%T is not a list: %v", list, err)
+ }
+ return obj, nil
+}
+
+// getItemsPtr returns a pointer to the list object's Items member or an error.
+func getItemsPtr(list runtime.Object) (interface{}, error) {
v, err := conversion.EnforcePtr(list)
if err != nil {
return nil, err
@@ -48,19 +94,19 @@
items := v.FieldByName("Items")
if !items.IsValid() {
- return nil, fmt.Errorf("no Items field in %#v", list)
+ return nil, errExpectFieldItems
}
switch items.Kind() {
case reflect.Interface, reflect.Ptr:
target := reflect.TypeOf(items.Interface()).Elem()
if target.Kind() != reflect.Slice {
- return nil, fmt.Errorf("items: Expected slice, got %s", target.Kind())
+ return nil, errExpectSliceItems
}
return items.Interface(), nil
case reflect.Slice:
return items.Addr().Interface(), nil
default:
- return nil, fmt.Errorf("items: Expected slice, got %s", items.Kind())
+ return nil, errExpectSliceItems
}
}
diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go b/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go
index b50337e..086bce0 100644
--- a/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go
+++ b/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go
@@ -21,7 +21,6 @@
"reflect"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
- metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -114,12 +113,12 @@
// AsPartialObjectMetadata takes the metav1 interface and returns a partial object.
// TODO: consider making this solely a conversion action.
-func AsPartialObjectMetadata(m metav1.Object) *metav1beta1.PartialObjectMetadata {
+func AsPartialObjectMetadata(m metav1.Object) *metav1.PartialObjectMetadata {
switch t := m.(type) {
case *metav1.ObjectMeta:
- return &metav1beta1.PartialObjectMetadata{ObjectMeta: *t}
+ return &metav1.PartialObjectMetadata{ObjectMeta: *t}
default:
- return &metav1beta1.PartialObjectMetadata{
+ return &metav1.PartialObjectMetadata{
ObjectMeta: metav1.ObjectMeta{
Name: m.GetName(),
GenerateName: m.GetGenerateName(),
diff --git a/vendor/k8s.io/apimachinery/pkg/api/resource/math.go b/vendor/k8s.io/apimachinery/pkg/api/resource/math.go
index 72d3880..7f63175 100644
--- a/vendor/k8s.io/apimachinery/pkg/api/resource/math.go
+++ b/vendor/k8s.io/apimachinery/pkg/api/resource/math.go
@@ -194,9 +194,9 @@
}
if fraction {
if base > 0 {
- value += 1
+ value++
} else {
- value += -1
+ value--
}
}
return value, !fraction
diff --git a/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go b/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
index 54fda58..93a6c0c 100644
--- a/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
+++ b/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
@@ -584,6 +584,12 @@
q.d.Dec.Neg(q.d.Dec)
}
+// Equal checks equality of two Quantities. This is useful for testing with
+// cmp.Equal.
+func (q Quantity) Equal(v Quantity) bool {
+ return q.Cmp(v) == 0
+}
+
// int64QuantityExpectedBytes is the expected width in bytes of the canonical string representation
// of most Quantity values.
const int64QuantityExpectedBytes = 18