mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
build: move e2e dependencies into e2e/go.mod
Several packages are only used while running the e2e suite. These packages are less important to update, as the they can not influence the final executable that is part of the Ceph-CSI container-image. By moving these dependencies out of the main Ceph-CSI go.mod, it is easier to identify if a reported CVE affects Ceph-CSI, or only the testing (like most of the Kubernetes CVEs). Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
committed by
mergify[bot]
parent
15da101b1b
commit
bec6090996
332
vendor/k8s.io/client-go/discovery/cached/memory/memcache.go
generated
vendored
332
vendor/k8s.io/client-go/discovery/cached/memory/memcache.go
generated
vendored
@ -1,332 +0,0 @@
|
||||
/*
|
||||
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 memory
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
openapi_v2 "github.com/google/gnostic-models/openapiv2"
|
||||
|
||||
errorsutil "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/version"
|
||||
"k8s.io/client-go/discovery"
|
||||
"k8s.io/client-go/openapi"
|
||||
cachedopenapi "k8s.io/client-go/openapi/cached"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
type cacheEntry struct {
|
||||
resourceList *metav1.APIResourceList
|
||||
err error
|
||||
}
|
||||
|
||||
// memCacheClient can Invalidate() to stay up-to-date with discovery
|
||||
// information.
|
||||
//
|
||||
// TODO: Switch to a watch interface. Right now it will poll after each
|
||||
// Invalidate() call.
|
||||
type memCacheClient struct {
|
||||
delegate discovery.DiscoveryInterface
|
||||
|
||||
lock sync.RWMutex
|
||||
groupToServerResources map[string]*cacheEntry
|
||||
groupList *metav1.APIGroupList
|
||||
cacheValid bool
|
||||
openapiClient openapi.Client
|
||||
receivedAggregatedDiscovery bool
|
||||
}
|
||||
|
||||
// Error Constants
|
||||
var (
|
||||
ErrCacheNotFound = errors.New("not found")
|
||||
)
|
||||
|
||||
// Server returning empty ResourceList for Group/Version.
|
||||
type emptyResponseError struct {
|
||||
gv string
|
||||
}
|
||||
|
||||
func (e *emptyResponseError) Error() string {
|
||||
return fmt.Sprintf("received empty response for: %s", e.gv)
|
||||
}
|
||||
|
||||
var _ discovery.CachedDiscoveryInterface = &memCacheClient{}
|
||||
|
||||
// isTransientConnectionError checks whether given error is "Connection refused" or
|
||||
// "Connection reset" error which usually means that apiserver is temporarily
|
||||
// unavailable.
|
||||
func isTransientConnectionError(err error) bool {
|
||||
var errno syscall.Errno
|
||||
if errors.As(err, &errno) {
|
||||
return errno == syscall.ECONNREFUSED || errno == syscall.ECONNRESET
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isTransientError(err error) bool {
|
||||
if isTransientConnectionError(err) {
|
||||
return true
|
||||
}
|
||||
|
||||
if t, ok := err.(errorsutil.APIStatus); ok && t.Status().Code >= 500 {
|
||||
return true
|
||||
}
|
||||
|
||||
return errorsutil.IsTooManyRequests(err)
|
||||
}
|
||||
|
||||
// ServerResourcesForGroupVersion returns the supported resources for a group and version.
|
||||
func (d *memCacheClient) ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error) {
|
||||
d.lock.Lock()
|
||||
defer d.lock.Unlock()
|
||||
if !d.cacheValid {
|
||||
if err := d.refreshLocked(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
cachedVal, ok := d.groupToServerResources[groupVersion]
|
||||
if !ok {
|
||||
return nil, ErrCacheNotFound
|
||||
}
|
||||
|
||||
if cachedVal.err != nil && isTransientError(cachedVal.err) {
|
||||
r, err := d.serverResourcesForGroupVersion(groupVersion)
|
||||
if err != nil {
|
||||
// Don't log "empty response" as an error; it is a common response for metrics.
|
||||
if _, emptyErr := err.(*emptyResponseError); emptyErr {
|
||||
// Log at same verbosity as disk cache.
|
||||
klog.V(3).Infof("%v", err)
|
||||
} else {
|
||||
utilruntime.HandleError(fmt.Errorf("couldn't get resource list for %v: %v", groupVersion, err))
|
||||
}
|
||||
}
|
||||
cachedVal = &cacheEntry{r, err}
|
||||
d.groupToServerResources[groupVersion] = cachedVal
|
||||
}
|
||||
|
||||
return cachedVal.resourceList, cachedVal.err
|
||||
}
|
||||
|
||||
// ServerGroupsAndResources returns the groups and supported resources for all groups and versions.
|
||||
func (d *memCacheClient) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error) {
|
||||
return discovery.ServerGroupsAndResources(d)
|
||||
}
|
||||
|
||||
// GroupsAndMaybeResources returns the list of APIGroups, and possibly the map of group/version
|
||||
// to resources. The returned groups will never be nil, but the resources map can be nil
|
||||
// if there are no cached resources.
|
||||
func (d *memCacheClient) GroupsAndMaybeResources() (*metav1.APIGroupList, map[schema.GroupVersion]*metav1.APIResourceList, map[schema.GroupVersion]error, error) {
|
||||
d.lock.Lock()
|
||||
defer d.lock.Unlock()
|
||||
|
||||
if !d.cacheValid {
|
||||
if err := d.refreshLocked(); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
}
|
||||
// Build the resourceList from the cache?
|
||||
var resourcesMap map[schema.GroupVersion]*metav1.APIResourceList
|
||||
var failedGVs map[schema.GroupVersion]error
|
||||
if d.receivedAggregatedDiscovery && len(d.groupToServerResources) > 0 {
|
||||
resourcesMap = map[schema.GroupVersion]*metav1.APIResourceList{}
|
||||
failedGVs = map[schema.GroupVersion]error{}
|
||||
for gv, cacheEntry := range d.groupToServerResources {
|
||||
groupVersion, err := schema.ParseGroupVersion(gv)
|
||||
if err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("failed to parse group version (%v): %v", gv, err)
|
||||
}
|
||||
if cacheEntry.err != nil {
|
||||
failedGVs[groupVersion] = cacheEntry.err
|
||||
} else {
|
||||
resourcesMap[groupVersion] = cacheEntry.resourceList
|
||||
}
|
||||
}
|
||||
}
|
||||
return d.groupList, resourcesMap, failedGVs, nil
|
||||
}
|
||||
|
||||
func (d *memCacheClient) ServerGroups() (*metav1.APIGroupList, error) {
|
||||
groups, _, _, err := d.GroupsAndMaybeResources()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
func (d *memCacheClient) RESTClient() restclient.Interface {
|
||||
return d.delegate.RESTClient()
|
||||
}
|
||||
|
||||
func (d *memCacheClient) ServerPreferredResources() ([]*metav1.APIResourceList, error) {
|
||||
return discovery.ServerPreferredResources(d)
|
||||
}
|
||||
|
||||
func (d *memCacheClient) ServerPreferredNamespacedResources() ([]*metav1.APIResourceList, error) {
|
||||
return discovery.ServerPreferredNamespacedResources(d)
|
||||
}
|
||||
|
||||
func (d *memCacheClient) ServerVersion() (*version.Info, error) {
|
||||
return d.delegate.ServerVersion()
|
||||
}
|
||||
|
||||
func (d *memCacheClient) OpenAPISchema() (*openapi_v2.Document, error) {
|
||||
return d.delegate.OpenAPISchema()
|
||||
}
|
||||
|
||||
func (d *memCacheClient) OpenAPIV3() openapi.Client {
|
||||
// Must take lock since Invalidate call may modify openapiClient
|
||||
d.lock.Lock()
|
||||
defer d.lock.Unlock()
|
||||
|
||||
if d.openapiClient == nil {
|
||||
d.openapiClient = cachedopenapi.NewClient(d.delegate.OpenAPIV3())
|
||||
}
|
||||
|
||||
return d.openapiClient
|
||||
}
|
||||
|
||||
func (d *memCacheClient) Fresh() bool {
|
||||
d.lock.RLock()
|
||||
defer d.lock.RUnlock()
|
||||
// Return whether the cache is populated at all. It is still possible that
|
||||
// a single entry is missing due to transient errors and the attempt to read
|
||||
// that entry will trigger retry.
|
||||
return d.cacheValid
|
||||
}
|
||||
|
||||
// Invalidate enforces that no cached data that is older than the current time
|
||||
// is used.
|
||||
func (d *memCacheClient) Invalidate() {
|
||||
d.lock.Lock()
|
||||
defer d.lock.Unlock()
|
||||
d.cacheValid = false
|
||||
d.groupToServerResources = nil
|
||||
d.groupList = nil
|
||||
d.openapiClient = nil
|
||||
d.receivedAggregatedDiscovery = false
|
||||
if ad, ok := d.delegate.(discovery.CachedDiscoveryInterface); ok {
|
||||
ad.Invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
// refreshLocked refreshes the state of cache. The caller must hold d.lock for
|
||||
// writing.
|
||||
func (d *memCacheClient) refreshLocked() error {
|
||||
// TODO: Could this multiplicative set of calls be replaced by a single call
|
||||
// to ServerResources? If it's possible for more than one resulting
|
||||
// APIResourceList to have the same GroupVersion, the lists would need merged.
|
||||
var gl *metav1.APIGroupList
|
||||
var err error
|
||||
|
||||
if ad, ok := d.delegate.(discovery.AggregatedDiscoveryInterface); ok {
|
||||
var resources map[schema.GroupVersion]*metav1.APIResourceList
|
||||
var failedGVs map[schema.GroupVersion]error
|
||||
gl, resources, failedGVs, err = ad.GroupsAndMaybeResources()
|
||||
if resources != nil && err == nil {
|
||||
// Cache the resources.
|
||||
d.groupToServerResources = map[string]*cacheEntry{}
|
||||
d.groupList = gl
|
||||
for gv, resources := range resources {
|
||||
d.groupToServerResources[gv.String()] = &cacheEntry{resources, nil}
|
||||
}
|
||||
// Cache GroupVersion discovery errors
|
||||
for gv, err := range failedGVs {
|
||||
d.groupToServerResources[gv.String()] = &cacheEntry{nil, err}
|
||||
}
|
||||
d.receivedAggregatedDiscovery = true
|
||||
d.cacheValid = true
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
gl, err = d.delegate.ServerGroups()
|
||||
}
|
||||
if err != nil || len(gl.Groups) == 0 {
|
||||
utilruntime.HandleError(fmt.Errorf("couldn't get current server API group list: %v", err))
|
||||
return err
|
||||
}
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
resultLock := &sync.Mutex{}
|
||||
rl := map[string]*cacheEntry{}
|
||||
for _, g := range gl.Groups {
|
||||
for _, v := range g.Versions {
|
||||
gv := v.GroupVersion
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
defer utilruntime.HandleCrash()
|
||||
|
||||
r, err := d.serverResourcesForGroupVersion(gv)
|
||||
if err != nil {
|
||||
// Don't log "empty response" as an error; it is a common response for metrics.
|
||||
if _, emptyErr := err.(*emptyResponseError); emptyErr {
|
||||
// Log at same verbosity as disk cache.
|
||||
klog.V(3).Infof("%v", err)
|
||||
} else {
|
||||
utilruntime.HandleError(fmt.Errorf("couldn't get resource list for %v: %v", gv, err))
|
||||
}
|
||||
}
|
||||
|
||||
resultLock.Lock()
|
||||
defer resultLock.Unlock()
|
||||
rl[gv] = &cacheEntry{r, err}
|
||||
}()
|
||||
}
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
d.groupToServerResources, d.groupList = rl, gl
|
||||
d.cacheValid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *memCacheClient) serverResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error) {
|
||||
r, err := d.delegate.ServerResourcesForGroupVersion(groupVersion)
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
if len(r.APIResources) == 0 {
|
||||
return r, &emptyResponseError{gv: groupVersion}
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// WithLegacy returns current memory-cached discovery client;
|
||||
// current client does not support legacy-only discovery.
|
||||
func (d *memCacheClient) WithLegacy() discovery.DiscoveryInterface {
|
||||
return d
|
||||
}
|
||||
|
||||
// NewMemCacheClient creates a new CachedDiscoveryInterface which caches
|
||||
// discovery information in memory and will stay up-to-date if Invalidate is
|
||||
// called with regularity.
|
||||
//
|
||||
// NOTE: The client will NOT resort to live lookups on cache misses.
|
||||
func NewMemCacheClient(delegate discovery.DiscoveryInterface) discovery.CachedDiscoveryInterface {
|
||||
return &memCacheClient{
|
||||
delegate: delegate,
|
||||
groupToServerResources: map[string]*cacheEntry{},
|
||||
receivedAggregatedDiscovery: false,
|
||||
}
|
||||
}
|
180
vendor/k8s.io/client-go/discovery/fake/discovery.go
generated
vendored
180
vendor/k8s.io/client-go/discovery/fake/discovery.go
generated
vendored
@ -1,180 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 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 fake
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
openapi_v2 "github.com/google/gnostic-models/openapiv2"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/version"
|
||||
"k8s.io/client-go/discovery"
|
||||
"k8s.io/client-go/openapi"
|
||||
kubeversion "k8s.io/client-go/pkg/version"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
// FakeDiscovery implements discovery.DiscoveryInterface and sometimes calls testing.Fake.Invoke with an action,
|
||||
// but doesn't respect the return value if any. There is a way to fake static values like ServerVersion by using the Faked... fields on the struct.
|
||||
type FakeDiscovery struct {
|
||||
*testing.Fake
|
||||
FakedServerVersion *version.Info
|
||||
}
|
||||
|
||||
// ServerResourcesForGroupVersion returns the supported resources for a group
|
||||
// and version.
|
||||
func (c *FakeDiscovery) ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error) {
|
||||
action := testing.ActionImpl{
|
||||
Verb: "get",
|
||||
Resource: schema.GroupVersionResource{Resource: "resource"},
|
||||
}
|
||||
if _, err := c.Invokes(action, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, resourceList := range c.Resources {
|
||||
if resourceList.GroupVersion == groupVersion {
|
||||
return resourceList, nil
|
||||
}
|
||||
}
|
||||
return nil, &errors.StatusError{
|
||||
ErrStatus: metav1.Status{
|
||||
Status: metav1.StatusFailure,
|
||||
Code: http.StatusNotFound,
|
||||
Reason: metav1.StatusReasonNotFound,
|
||||
Message: fmt.Sprintf("the server could not find the requested resource, GroupVersion %q not found", groupVersion),
|
||||
}}
|
||||
}
|
||||
|
||||
// ServerGroupsAndResources returns the supported groups and resources for all groups and versions.
|
||||
func (c *FakeDiscovery) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error) {
|
||||
sgs, err := c.ServerGroups()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
resultGroups := []*metav1.APIGroup{}
|
||||
for i := range sgs.Groups {
|
||||
resultGroups = append(resultGroups, &sgs.Groups[i])
|
||||
}
|
||||
|
||||
action := testing.ActionImpl{
|
||||
Verb: "get",
|
||||
Resource: schema.GroupVersionResource{Resource: "resource"},
|
||||
}
|
||||
if _, err = c.Invokes(action, nil); err != nil {
|
||||
return resultGroups, c.Resources, err
|
||||
}
|
||||
return resultGroups, c.Resources, nil
|
||||
}
|
||||
|
||||
// ServerPreferredResources returns the supported resources with the version
|
||||
// preferred by the server.
|
||||
func (c *FakeDiscovery) ServerPreferredResources() ([]*metav1.APIResourceList, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ServerPreferredNamespacedResources returns the supported namespaced resources
|
||||
// with the version preferred by the server.
|
||||
func (c *FakeDiscovery) ServerPreferredNamespacedResources() ([]*metav1.APIResourceList, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ServerGroups returns the supported groups, with information like supported
|
||||
// versions and the preferred version.
|
||||
func (c *FakeDiscovery) ServerGroups() (*metav1.APIGroupList, error) {
|
||||
action := testing.ActionImpl{
|
||||
Verb: "get",
|
||||
Resource: schema.GroupVersionResource{Resource: "group"},
|
||||
}
|
||||
if _, err := c.Invokes(action, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
groups := map[string]*metav1.APIGroup{}
|
||||
|
||||
for _, res := range c.Resources {
|
||||
gv, err := schema.ParseGroupVersion(res.GroupVersion)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
group := groups[gv.Group]
|
||||
if group == nil {
|
||||
group = &metav1.APIGroup{
|
||||
Name: gv.Group,
|
||||
PreferredVersion: metav1.GroupVersionForDiscovery{
|
||||
GroupVersion: res.GroupVersion,
|
||||
Version: gv.Version,
|
||||
},
|
||||
}
|
||||
groups[gv.Group] = group
|
||||
}
|
||||
|
||||
group.Versions = append(group.Versions, metav1.GroupVersionForDiscovery{
|
||||
GroupVersion: res.GroupVersion,
|
||||
Version: gv.Version,
|
||||
})
|
||||
}
|
||||
|
||||
list := &metav1.APIGroupList{}
|
||||
for _, apiGroup := range groups {
|
||||
list.Groups = append(list.Groups, *apiGroup)
|
||||
}
|
||||
|
||||
return list, nil
|
||||
|
||||
}
|
||||
|
||||
// ServerVersion retrieves and parses the server's version.
|
||||
func (c *FakeDiscovery) ServerVersion() (*version.Info, error) {
|
||||
action := testing.ActionImpl{}
|
||||
action.Verb = "get"
|
||||
action.Resource = schema.GroupVersionResource{Resource: "version"}
|
||||
_, err := c.Invokes(action, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c.FakedServerVersion != nil {
|
||||
return c.FakedServerVersion, nil
|
||||
}
|
||||
|
||||
versionInfo := kubeversion.Get()
|
||||
return &versionInfo, nil
|
||||
}
|
||||
|
||||
// OpenAPISchema retrieves and parses the swagger API schema the server supports.
|
||||
func (c *FakeDiscovery) OpenAPISchema() (*openapi_v2.Document, error) {
|
||||
return &openapi_v2.Document{}, nil
|
||||
}
|
||||
|
||||
func (c *FakeDiscovery) OpenAPIV3() openapi.Client {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// RESTClient returns a RESTClient that is used to communicate with API server
|
||||
// by this client implementation.
|
||||
func (c *FakeDiscovery) RESTClient() restclient.Interface {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *FakeDiscovery) WithLegacy() discovery.DiscoveryInterface {
|
||||
panic("unimplemented")
|
||||
}
|
Reference in New Issue
Block a user