forked from kubernetes/client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fetching into discovery client for OpenAPI v3
reflect latest struct changes use correct discovery openapi test data layout make the OpenAPIv3 interface less blue field grouping add copyrights implement cached discovery client add cached discovery tests address review feedback Kubernetes-commit: 075866b3e3ea029c243d82d8d6eb99e96d9c49d3
- Loading branch information
1 parent
92adc4d
commit 018cf8a
Showing
18 changed files
with
680 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,14 +39,16 @@ import ( | |
utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
"k8s.io/apimachinery/pkg/version" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
"k8s.io/client-go/openapi" | ||
restclient "k8s.io/client-go/rest" | ||
) | ||
|
||
const ( | ||
// defaultRetries is the number of times a resource discovery is repeated if an api group disappears on the fly (e.g. CustomResourceDefinitions). | ||
defaultRetries = 2 | ||
// protobuf mime type | ||
mimePb = "application/[email protected]+protobuf" | ||
openAPIV2mimePb = "application/[email protected]+protobuf" | ||
|
||
// defaultTimeout is the maximum amount of time per request when no timeout has been set on a RESTClient. | ||
// Defaults to 32s in order to have a distinguishable length of time, relative to other timeouts that exist. | ||
defaultTimeout = 32 * time.Second | ||
|
@@ -60,6 +62,7 @@ type DiscoveryInterface interface { | |
ServerResourcesInterface | ||
ServerVersionInterface | ||
OpenAPISchemaInterface | ||
OpenAPIV3SchemaInterface | ||
} | ||
|
||
// CachedDiscoveryInterface is a DiscoveryInterface with cache invalidation and freshness. | ||
|
@@ -121,6 +124,10 @@ type OpenAPISchemaInterface interface { | |
OpenAPISchema() (*openapi_v2.Document, error) | ||
} | ||
|
||
type OpenAPIV3SchemaInterface interface { | ||
OpenAPIV3() openapi.Client | ||
} | ||
|
||
// DiscoveryClient implements the functions that discover server-supported API groups, | ||
// versions and resources. | ||
type DiscoveryClient struct { | ||
|
@@ -399,9 +406,9 @@ func (d *DiscoveryClient) ServerVersion() (*version.Info, error) { | |
return &info, nil | ||
} | ||
|
||
// OpenAPISchema fetches the open api schema using a rest client and parses the proto. | ||
// OpenAPISchema fetches the open api v2 schema using a rest client and parses the proto. | ||
func (d *DiscoveryClient) OpenAPISchema() (*openapi_v2.Document, error) { | ||
data, err := d.restClient.Get().AbsPath("/openapi/v2").SetHeader("Accept", mimePb).Do(context.TODO()).Raw() | ||
data, err := d.restClient.Get().AbsPath("/openapi/v2").SetHeader("Accept", openAPIV2mimePb).Do(context.TODO()).Raw() | ||
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 | ||
|
@@ -422,6 +429,10 @@ func (d *DiscoveryClient) OpenAPISchema() (*openapi_v2.Document, error) { | |
return document, nil | ||
} | ||
|
||
func (d *DiscoveryClient) OpenAPIV3() openapi.Client { | ||
return openapi.NewClient(d.restClient) | ||
} | ||
|
||
// 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.APIGroup, []*metav1.APIResourceList, error)) ([]*metav1.APIGroup, []*metav1.APIResourceList, error) { | ||
var result []*metav1.APIResourceList | ||
|
Oops, something went wrong.