mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
update for feedback
This commit is contained in:
parent
6f23c77408
commit
5fdeaa8e42
@ -49,7 +49,7 @@ func NewFallbackQueryParamVerifier(primary Verifier, secondary Verifier) Verifie
|
|||||||
func (f *fallbackQueryParamVerifier) HasSupport(gvk schema.GroupVersionKind) error {
|
func (f *fallbackQueryParamVerifier) HasSupport(gvk schema.GroupVersionKind) error {
|
||||||
err := f.primary.HasSupport(gvk)
|
err := f.primary.HasSupport(gvk)
|
||||||
// If an error was returned from the primary OpenAPI endpoint,
|
// If an error was returned from the primary OpenAPI endpoint,
|
||||||
// we fallback to check the secondary OpenAPI endpoint for an
|
// we fallback to check the secondary OpenAPI endpoint for
|
||||||
// any error *except* "paramUnsupportedError".
|
// any error *except* "paramUnsupportedError".
|
||||||
if err != nil && !IsParamUnsupportedError(err) {
|
if err != nil && !IsParamUnsupportedError(err) {
|
||||||
klog.V(7).Infof("openapi v3 error...falling back to legacy: %s", err)
|
klog.V(7).Infof("openapi v3 error...falling back to legacy: %s", err)
|
||||||
|
@ -64,15 +64,7 @@ func (v *queryParamVerifierV3) HasSupport(gvk schema.GroupVersionKind) error {
|
|||||||
}
|
}
|
||||||
gvSpec, err := v.root.GVSpec(gvk.GroupVersion())
|
gvSpec, err := v.root.GVSpec(gvk.GroupVersion())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Even if there is no error returned fetching OpenAPI V3 document,
|
return supportsQueryParamV3(gvSpec, gvk, v.queryParam)
|
||||||
// check if the returned document is valid before checking support.
|
|
||||||
if gvSpec == nil || gvSpec.Paths == nil {
|
|
||||||
return fmt.Errorf("Invalid OpenAPI V3 document")
|
|
||||||
}
|
|
||||||
if supports := supportsQueryParamV3(gvSpec, gvk, v.queryParam); supports {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return NewParamUnsupportedError(gvk, v.queryParam)
|
|
||||||
}
|
}
|
||||||
if _, isErr := err.(*openapi3.GroupVersionNotFoundError); !isErr {
|
if _, isErr := err.(*openapi3.GroupVersionNotFoundError); !isErr {
|
||||||
return err
|
return err
|
||||||
@ -85,9 +77,7 @@ func (v *queryParamVerifierV3) HasSupport(gvk schema.GroupVersionKind) error {
|
|||||||
// If error retrieving Namespace spec, propagate error.
|
// If error retrieving Namespace spec, propagate error.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if supports := supportsQueryParamV3(namespaceSpec, namespaceGVK, v.queryParam); supports {
|
return supportsQueryParamV3(namespaceSpec, namespaceGVK, v.queryParam)
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return NewParamUnsupportedError(gvk, v.queryParam)
|
return NewParamUnsupportedError(gvk, v.queryParam)
|
||||||
}
|
}
|
||||||
@ -110,9 +100,14 @@ func hasGVKExtensionV3(extensions spec.Extensions, gvk schema.GroupVersionKind)
|
|||||||
|
|
||||||
// supportsQueryParam is a method that let's us look in the OpenAPI if the
|
// supportsQueryParam is a method that let's us look in the OpenAPI if the
|
||||||
// specific group-version-kind supports the specific query parameter for
|
// specific group-version-kind supports the specific query parameter for
|
||||||
// the PATCH end-point. Returns true if the query param is supported by the
|
// the PATCH end-point. Returns nil if the passed GVK supports the passed
|
||||||
// spec for the passed GVK; false otherwise.
|
// query parameter; otherwise, a "paramUnsupportedError" is returned (except
|
||||||
func supportsQueryParamV3(doc *spec3.OpenAPI, gvk schema.GroupVersionKind, queryParam VerifiableQueryParam) bool {
|
// when an invalid document error is returned when an invalid OpenAPI V3
|
||||||
|
// is passed in).
|
||||||
|
func supportsQueryParamV3(doc *spec3.OpenAPI, gvk schema.GroupVersionKind, queryParam VerifiableQueryParam) error {
|
||||||
|
if doc == nil || doc.Paths == nil {
|
||||||
|
return fmt.Errorf("Invalid OpenAPI V3 document")
|
||||||
|
}
|
||||||
for _, path := range doc.Paths.Paths {
|
for _, path := range doc.Paths.Paths {
|
||||||
// If operation is not PATCH, then continue.
|
// If operation is not PATCH, then continue.
|
||||||
op := path.PathProps.Patch
|
op := path.PathProps.Patch
|
||||||
@ -127,10 +122,10 @@ func supportsQueryParamV3(doc *spec3.OpenAPI, gvk schema.GroupVersionKind, query
|
|||||||
// for the PATCH operation.
|
// for the PATCH operation.
|
||||||
for _, param := range op.OperationProps.Parameters {
|
for _, param := range op.OperationProps.Parameters {
|
||||||
if param.ParameterProps.Name == string(queryParam) {
|
if param.ParameterProps.Name == string(queryParam) {
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return NewParamUnsupportedError(gvk, queryParam)
|
||||||
}
|
}
|
||||||
return false
|
return NewParamUnsupportedError(gvk, queryParam)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user