-
Notifications
You must be signed in to change notification settings - Fork 38.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automated cherry pick of #117768: QueryParamVerifierV3 resilient to minimal OpenAPI V3 #117796: QueryParamVerifier falls back on invalid v3 document #117918
Merged
k8s-ci-robot
merged 3 commits into
kubernetes:release-1.27
from
seans3:automated-cherry-pick-of-#117768-#117796-origin-release-1.27
May 11, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,14 @@ limitations under the License. | |
package resource | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/client-go/openapi/cached" | ||
"k8s.io/client-go/openapi/openapitest" | ||
"k8s.io/client-go/openapi3" | ||
"k8s.io/kube-openapi/pkg/spec3" | ||
) | ||
|
||
func TestV3SupportsQueryParamBatchV1(t *testing.T) { | ||
|
@@ -135,3 +137,64 @@ func TestV3SupportsQueryParamBatchV1(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestInvalidOpenAPIV3Document(t *testing.T) { | ||
tests := map[string]struct { | ||
spec *spec3.OpenAPI | ||
}{ | ||
"nil document returns error": { | ||
spec: nil, | ||
}, | ||
"empty document returns error": { | ||
spec: &spec3.OpenAPI{}, | ||
}, | ||
"minimal document returns error": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the follow-up in master, include more minimal/stub documents we could encounter that should fall back to v2:
|
||
spec: &spec3.OpenAPI{ | ||
Version: "openapi 3.0.0", | ||
Paths: nil, | ||
}, | ||
}, | ||
} | ||
|
||
gvk := schema.GroupVersionKind{ | ||
Group: "batch", | ||
Version: "v1", | ||
Kind: "Job", | ||
} | ||
for tn, tc := range tests { | ||
t.Run(tn, func(t *testing.T) { | ||
|
||
verifier := &queryParamVerifierV3{ | ||
finder: NewCRDFinder(func() ([]schema.GroupKind, error) { | ||
return []schema.GroupKind{}, nil | ||
}), | ||
root: &fakeRoot{tc.spec}, | ||
queryParam: QueryParamFieldValidation, | ||
} | ||
err := verifier.HasSupport(gvk) | ||
if !strings.Contains(err.Error(), "Invalid OpenAPI V3 document") { | ||
t.Errorf("Expected invalid document error, but none received.") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// fakeRoot implements Root interface; manually specifies the returned OpenAPI V3 document. | ||
type fakeRoot struct { | ||
spec *spec3.OpenAPI | ||
} | ||
|
||
func (f *fakeRoot) GroupVersions() ([]schema.GroupVersion, error) { | ||
// Unused | ||
return nil, nil | ||
} | ||
|
||
// GVSpec returns hard-coded OpenAPI V3 document. | ||
func (f *fakeRoot) GVSpec(gv schema.GroupVersion) (*spec3.OpenAPI, error) { | ||
return f.spec, nil | ||
} | ||
|
||
func (f *fakeRoot) GVSpecAsMap(gv schema.GroupVersion) (map[string]interface{}, error) { | ||
// Unused | ||
return nil, nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is an improvement over the current state of release-1.27, so merging it seems fine, but I'd like to see a follow-up in master: if we don't find the path we want in the openapi v3 doc (if we fall through to line 130 here), we should return an error about the path not being found, not at definite NewParamUnsupportedError answer, right?
Otherwise, a stub openapi v3 doc like
paths:{}
, orpaths:{"/version":{"get":...}}
wouldn't fall back to v2