-
Notifications
You must be signed in to change notification settings - Fork 702
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
KEP-2170: Strictly verify the CRD marker validation and defaulting in the integration testings #2304
Merged
google-oss-prow
merged 1 commit into
kubeflow:master
from
tenzen-y:v2-refactor-webhook-integration-test
Oct 24, 2024
+248
−83
Merged
KEP-2170: Strictly verify the CRD marker validation and defaulting in the integration testings #2304
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
Copyright 2024 The Kubeflow 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 testing | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/onsi/gomega/format" | ||
"github.com/onsi/gomega/types" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
) | ||
|
||
func BeNotFoundError() types.GomegaMatcher { | ||
return BeAPIError(NotFoundError) | ||
} | ||
|
||
func BeForbiddenError() types.GomegaMatcher { | ||
return BeAPIError(ForbiddenError) | ||
} | ||
|
||
func BeInvalidError() types.GomegaMatcher { | ||
return BeAPIError(InvalidError) | ||
} | ||
|
||
type errorMatcher int | ||
|
||
const ( | ||
NotFoundError errorMatcher = iota | ||
ForbiddenError | ||
InvalidError | ||
) | ||
|
||
func (em errorMatcher) String() string { | ||
return []string{"NotFoundError", "ForbiddenError", "InvalidError"}[em] | ||
} | ||
|
||
type apiError func(error) bool | ||
|
||
func (em errorMatcher) isAPIError(err error) bool { | ||
return []apiError{apierrors.IsNotFound, apierrors.IsForbidden, apierrors.IsInvalid}[em](err) | ||
} | ||
|
||
type isErrorMatch struct { | ||
name errorMatcher | ||
} | ||
|
||
func BeAPIError(name errorMatcher) types.GomegaMatcher { | ||
return &isErrorMatch{ | ||
name: name, | ||
} | ||
} | ||
|
||
func (matcher *isErrorMatch) Match(actual interface{}) (success bool, err error) { | ||
err, ok := actual.(error) | ||
if !ok { | ||
return false, fmt.Errorf("%s expects an error", matcher.name.String()) | ||
} | ||
|
||
return err != nil && matcher.name.isAPIError(err), nil | ||
} | ||
|
||
func (matcher *isErrorMatch) FailureMessage(actual interface{}) (message string) { | ||
return format.Message(actual, "to be a %s", matcher.name.String()) | ||
} | ||
|
||
func (matcher *isErrorMatch) NegatedFailureMessage(actual interface{}) (message string) { | ||
return format.Message(actual, "not to be %s", matcher.name.String()) | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
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.
When we could return this error ?
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.
We will use this in webhook impl similar to
training-operator/pkg/webhooks/pytorch/pytorchjob_webhook.go
Line 102 in ab6938c