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 {
|
||||
err := f.primary.HasSupport(gvk)
|
||||
// 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".
|
||||
if err != nil && !IsParamUnsupportedError(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())
|
||||
if err == nil {
|
||||
// Even if there is no error returned fetching OpenAPI V3 document,
|
||||
// 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)
|
||||
return supportsQueryParamV3(gvSpec, gvk, v.queryParam)
|
||||
}
|
||||
if _, isErr := err.(*openapi3.GroupVersionNotFoundError); !isErr {
|
||||
return err
|
||||
@ -85,9 +77,7 @@ func (v *queryParamVerifierV3) HasSupport(gvk schema.GroupVersionKind) error {
|
||||
// If error retrieving Namespace spec, propagate error.
|
||||
return err
|
||||
}
|
||||
if supports := supportsQueryParamV3(namespaceSpec, namespaceGVK, v.queryParam); supports {
|
||||
return nil
|
||||
}
|
||||
return supportsQueryParamV3(namespaceSpec, namespaceGVK, 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
|
||||
// specific group-version-kind supports the specific query parameter for
|
||||
// the PATCH end-point. Returns true if the query param is supported by the
|
||||
// spec for the passed GVK; false otherwise.
|
||||
func supportsQueryParamV3(doc *spec3.OpenAPI, gvk schema.GroupVersionKind, queryParam VerifiableQueryParam) bool {
|
||||
// the PATCH end-point. Returns nil if the passed GVK supports the passed
|
||||
// query parameter; otherwise, a "paramUnsupportedError" is returned (except
|
||||
// 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 {
|
||||
// If operation is not PATCH, then continue.
|
||||
op := path.PathProps.Patch
|
||||
@ -127,10 +122,10 @@ func supportsQueryParamV3(doc *spec3.OpenAPI, gvk schema.GroupVersionKind, query
|
||||
// for the PATCH operation.
|
||||
for _, param := range op.OperationProps.Parameters {
|
||||
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