-
Notifications
You must be signed in to change notification settings - Fork 566
NO-JIRA: test(e2e-v2): add ginkgo-based v2 test suite #7152
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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,93 @@ | ||
| package util | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
|
|
||
| crclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
| ) | ||
|
|
||
| // HasFieldInCRDSchema checks if a field path exists in the CRD schema by recursively traversing | ||
| // the JSONSchemaProps. The fieldPath should be dot-separated (e.g., "spec.platform.gcp"). | ||
| func HasFieldInCRDSchema(ctx context.Context, client crclient.Client, crdName, fieldPath string) (bool, error) { | ||
| crd := &apiextensionsv1.CustomResourceDefinition{} | ||
| if err := client.Get(ctx, crclient.ObjectKey{Name: crdName}, crd); err != nil { | ||
| return false, fmt.Errorf("failed to get CRD %s: %w", crdName, err) | ||
| } | ||
|
|
||
| // Find the served version (prefer v1beta1 if available, otherwise use the first served version) | ||
| var version *apiextensionsv1.CustomResourceDefinitionVersion | ||
| for i := range crd.Spec.Versions { | ||
| if crd.Spec.Versions[i].Served { | ||
| version = &crd.Spec.Versions[i] | ||
| if version.Name == "v1beta1" { | ||
| break | ||
| } | ||
| } | ||
| } | ||
| if version == nil || version.Schema == nil || version.Schema.OpenAPIV3Schema == nil { | ||
| return false, fmt.Errorf("no valid schema found for CRD %s", crdName) | ||
| } | ||
|
|
||
| // Split the field path into parts | ||
| pathParts := strings.Split(fieldPath, ".") | ||
| return hasFieldInSchema(version.Schema.OpenAPIV3Schema, pathParts, 0), nil | ||
| } | ||
|
|
||
| // hasFieldInSchema recursively checks if a field path exists in the JSONSchemaProps | ||
| func hasFieldInSchema(schema *apiextensionsv1.JSONSchemaProps, pathParts []string, index int) bool { | ||
| if schema == nil || index >= len(pathParts) { | ||
| return index == len(pathParts) | ||
| } | ||
|
|
||
| currentPart := pathParts[index] | ||
|
|
||
| // Check properties first | ||
| if schema.Properties != nil { | ||
| if prop, exists := schema.Properties[currentPart]; exists { | ||
| if index == len(pathParts)-1 { | ||
| // This is the last part, field exists | ||
| return true | ||
| } | ||
| // Recurse into the property | ||
| return hasFieldInSchema(&prop, pathParts, index+1) | ||
| } | ||
| } | ||
|
|
||
| // Bridge into array items before falling back to the combinators. | ||
| if schema.Items != nil { | ||
| if schema.Items.Schema != nil && hasFieldInSchema(schema.Items.Schema, pathParts, index) { | ||
| return true | ||
| } | ||
| for i := range schema.Items.JSONSchemas { | ||
| if hasFieldInSchema(&schema.Items.JSONSchemas[i], pathParts, index) { | ||
| return true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Check AllOf, AnyOf, OneOf - these can contain the field | ||
| for i := range schema.AllOf { | ||
| if hasFieldInSchema(&schema.AllOf[i], pathParts, index) { | ||
| return true | ||
| } | ||
| } | ||
| for i := range schema.AnyOf { | ||
| if hasFieldInSchema(&schema.AnyOf[i], pathParts, index) { | ||
| return true | ||
| } | ||
| } | ||
| for i := range schema.OneOf { | ||
| if hasFieldInSchema(&schema.OneOf[i], pathParts, index) { | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| // Check if there's a $ref that we need to follow | ||
| // Note: In CRDs, $ref typically points to definitions within the same schema | ||
| // For simplicity, we check properties which is the most common case | ||
| return false | ||
| } | ||
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.
Handle array members when traversing schemas. Today any path that dives into an array (for example
status.conditions.type) is reported missing because we never followschema.Items. That causes false negatives in the new helpers and will break tests that rely on legitimate CRD fields living inside arrays. Please descend intoItemswithout advancing the path index, e.g.:📝 Committable suggestion
🤖 Prompt for AI Agents