[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/client-go/discovery/discovery_client.go b/vendor/k8s.io/client-go/discovery/discovery_client.go
index 17b39de..61b9c44 100644
--- a/vendor/k8s.io/client-go/discovery/discovery_client.go
+++ b/vendor/k8s.io/client-go/discovery/discovery_client.go
@@ -26,7 +26,7 @@
"time"
"github.com/golang/protobuf/proto"
- "github.com/googleapis/gnostic/OpenAPIv2"
+ openapi_v2 "github.com/googleapis/gnostic/OpenAPIv2"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -60,6 +60,9 @@
}
// CachedDiscoveryInterface is a DiscoveryInterface with cache invalidation and freshness.
+// Note that If the ServerResourcesForGroupVersion method returns a cache miss
+// error, the user needs to explicitly call Invalidate to clear the cache,
+// otherwise the same cache miss error will be returned next time.
type CachedDiscoveryInterface interface {
DiscoveryInterface
// Fresh is supposed to tell the caller whether or not to retry if the cache
@@ -68,7 +71,8 @@
// TODO: this needs to be revisited, this interface can't be locked properly
// and doesn't make a lot of sense.
Fresh() bool
- // Invalidate enforces that no cached data is used in the future that is older than the current time.
+ // Invalidate enforces that no cached data that is older than the current time
+ // is used.
Invalidate()
}
@@ -84,12 +88,28 @@
// ServerResourcesForGroupVersion returns the supported resources for a group and version.
ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error)
// ServerResources returns the supported resources for all groups and versions.
+ //
+ // The returned resource list might be non-nil with partial results even in the case of
+ // non-nil error.
+ //
+ // Deprecated: use ServerGroupsAndResources instead.
ServerResources() ([]*metav1.APIResourceList, error)
+ // ServerResources returns the supported groups and resources for all groups and versions.
+ //
+ // The returned group and resource lists might be non-nil with partial results even in the
+ // case of non-nil error.
+ ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error)
// ServerPreferredResources returns the supported resources with the version preferred by the
// server.
+ //
+ // The returned group and resource lists might be non-nil with partial results even in the
+ // case of non-nil error.
ServerPreferredResources() ([]*metav1.APIResourceList, error)
// ServerPreferredNamespacedResources returns the supported namespaced resources with the
// version preferred by the server.
+ //
+ // The returned resource list might be non-nil with partial results even in the case of
+ // non-nil error.
ServerPreferredNamespacedResources() ([]*metav1.APIResourceList, error)
}
@@ -187,14 +207,18 @@
return resources, nil
}
-// serverResources returns the supported resources for all groups and versions.
-func (d *DiscoveryClient) serverResources() ([]*metav1.APIResourceList, error) {
- return ServerResources(d)
+// ServerResources returns the supported resources for all groups and versions.
+// Deprecated: use ServerGroupsAndResources instead.
+func (d *DiscoveryClient) ServerResources() ([]*metav1.APIResourceList, error) {
+ _, rs, err := d.ServerGroupsAndResources()
+ return rs, err
}
-// ServerResources returns the supported resources for all groups and versions.
-func (d *DiscoveryClient) ServerResources() ([]*metav1.APIResourceList, error) {
- return withRetries(defaultRetries, d.serverResources)
+// ServerGroupsAndResources returns the supported resources for all groups and versions.
+func (d *DiscoveryClient) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error) {
+ return withRetries(defaultRetries, func() ([]*metav1.APIGroup, []*metav1.APIResourceList, error) {
+ return ServerGroupsAndResources(d)
+ })
}
// ErrGroupDiscoveryFailed is returned if one or more API groups fail to load.
@@ -220,23 +244,28 @@
return err != nil && ok
}
-// serverPreferredResources returns the supported resources with the version preferred by the server.
-func (d *DiscoveryClient) serverPreferredResources() ([]*metav1.APIResourceList, error) {
- return ServerPreferredResources(d)
+// ServerResources uses the provided discovery interface to look up supported resources for all groups and versions.
+// Deprecated: use ServerGroupsAndResources instead.
+func ServerResources(d DiscoveryInterface) ([]*metav1.APIResourceList, error) {
+ _, rs, err := ServerGroupsAndResources(d)
+ return rs, err
}
-// ServerResources uses the provided discovery interface to look up supported resources for all groups and versions.
-func ServerResources(d DiscoveryInterface) ([]*metav1.APIResourceList, error) {
- apiGroups, err := d.ServerGroups()
- if err != nil {
- return nil, err
+func ServerGroupsAndResources(d DiscoveryInterface) ([]*metav1.APIGroup, []*metav1.APIResourceList, error) {
+ sgs, err := d.ServerGroups()
+ if sgs == nil {
+ return nil, nil, err
+ }
+ resultGroups := []*metav1.APIGroup{}
+ for i := range sgs.Groups {
+ resultGroups = append(resultGroups, &sgs.Groups[i])
}
- groupVersionResources, failedGroups := fetchGroupVersionResources(d, apiGroups)
+ groupVersionResources, failedGroups := fetchGroupVersionResources(d, sgs)
// order results by group/version discovery order
result := []*metav1.APIResourceList{}
- for _, apiGroup := range apiGroups.Groups {
+ for _, apiGroup := range sgs.Groups {
for _, version := range apiGroup.Versions {
gv := schema.GroupVersion{Group: apiGroup.Name, Version: version.Version}
if resources, ok := groupVersionResources[gv]; ok {
@@ -246,10 +275,10 @@
}
if len(failedGroups) == 0 {
- return result, nil
+ return resultGroups, result, nil
}
- return result, &ErrGroupDiscoveryFailed{Groups: failedGroups}
+ return resultGroups, result, &ErrGroupDiscoveryFailed{Groups: failedGroups}
}
// ServerPreferredResources uses the provided discovery interface to look up preferred resources
@@ -313,7 +342,7 @@
return result, &ErrGroupDiscoveryFailed{Groups: failedGroups}
}
-// fetchServerResourcesForGroupVersions uses the discovery client to fetch the resources for the specified groups in parallel
+// fetchServerResourcesForGroupVersions uses the discovery client to fetch the resources for the specified groups in parallel.
func fetchGroupVersionResources(d DiscoveryInterface, apiGroups *metav1.APIGroupList) (map[schema.GroupVersion]*metav1.APIResourceList, map[schema.GroupVersion]error) {
groupVersionResources := make(map[schema.GroupVersion]*metav1.APIResourceList)
failedGroups := make(map[schema.GroupVersion]error)
@@ -337,7 +366,9 @@
if err != nil {
// TODO: maybe restrict this to NotFound errors
failedGroups[groupVersion] = err
- } else {
+ }
+ if apiResourceList != nil {
+ // even in case of error, some fallback might have been returned
groupVersionResources[groupVersion] = apiResourceList
}
}()
@@ -351,7 +382,11 @@
// ServerPreferredResources returns the supported resources with the version preferred by the
// server.
func (d *DiscoveryClient) ServerPreferredResources() ([]*metav1.APIResourceList, error) {
- return withRetries(defaultRetries, d.serverPreferredResources)
+ _, rs, err := withRetries(defaultRetries, func() ([]*metav1.APIGroup, []*metav1.APIResourceList, error) {
+ rs, err := ServerPreferredResources(d)
+ return nil, rs, err
+ })
+ return rs, err
}
// ServerPreferredNamespacedResources returns the supported namespaced resources with the
@@ -377,7 +412,7 @@
var info version.Info
err = json.Unmarshal(body, &info)
if err != nil {
- return nil, fmt.Errorf("got '%s': %v", string(body), err)
+ return nil, fmt.Errorf("unable to parse the server version: %v", err)
}
return &info, nil
}
@@ -388,7 +423,7 @@
if err != nil {
if errors.IsForbidden(err) || errors.IsNotFound(err) || errors.IsNotAcceptable(err) {
// single endpoint not found/registered in old server, try to fetch old endpoint
- // TODO(roycaihw): remove this in 1.11
+ // TODO: remove this when kubectl/client-go don't work with 1.9 server
data, err = d.restClient.Get().AbsPath("/swagger-2.0.0.pb-v1").Do().Raw()
if err != nil {
return nil, err
@@ -406,19 +441,20 @@
}
// withRetries retries the given recovery function in case the groups supported by the server change after ServerGroup() returns.
-func withRetries(maxRetries int, f func() ([]*metav1.APIResourceList, error)) ([]*metav1.APIResourceList, error) {
+func withRetries(maxRetries int, f func() ([]*metav1.APIGroup, []*metav1.APIResourceList, error)) ([]*metav1.APIGroup, []*metav1.APIResourceList, error) {
var result []*metav1.APIResourceList
+ var resultGroups []*metav1.APIGroup
var err error
for i := 0; i < maxRetries; i++ {
- result, err = f()
+ resultGroups, result, err = f()
if err == nil {
- return result, nil
+ return resultGroups, result, nil
}
if _, ok := err.(*ErrGroupDiscoveryFailed); !ok {
- return nil, err
+ return nil, nil, err
}
}
- return result, err
+ return resultGroups, result, err
}
func setDiscoveryDefaults(config *restclient.Config) error {