Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,43 @@ tests:
versions:
- v1alpha1

- name: Should not be able to create CompatibilityRequirement with excluded fields with duplicate paths
initial: |
apiVersion: apiextensions.openshift.io/v1alpha1
kind: CompatibilityRequirement
metadata:
name: test-requirement
spec:
compatibilitySchema:
customResourceDefinition:
type: YAML
data: |
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: testrequirements.example.com
spec:
group: example.com
names:
kind: TestRequirement
plural: testrequirements
scope: Namespaced
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
requiredVersions:
defaultSelection: StorageOnly
excludedFields:
- path: spec.fieldToExclude
- path: spec.fieldToExclude
versions:
- v1alpha1
expectedError: "spec.compatibilitySchema.excludedFields: Invalid value: \"array\": each path in the list must be unique."

- name: Should not be able to create CompatibilityRequirement with invalid excluded field path
initial: |
apiVersion: apiextensions.openshift.io/v1alpha1
Expand Down
2 changes: 2 additions & 0 deletions apiextensions/v1alpha1/types_compatibilityrequirement.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ type CompatibilitySchema struct {
// excludedFields is a set of fields in the schema which will not be validated by
// crdSchemaValidation or objectSchemaValidation.
// The list may contain at most 64 fields.
// Each path in the list must be unique.
// When not specified, all fields in the schema will be validated.
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=64
// +kubebuilder:validation:XValidation:rule="self.all(x, self.exists_one(y, y.path == x.path))",message="each path in the list must be unique."
// +listType=atomic
Comment on lines +192 to 193
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason why this needs to be an atomic list instead of converting this to +listType=map with a key of path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had this discussion on the initial PR, we explicitly expect the writer to this API to write this list as an atomic unit. We aren't expecting multiple writers for this list ever. So atomic makes more sense based on the expected use case

// +optional
ExcludedFields []APIExcludedField `json:"excludedFields,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ spec:
excludedFields is a set of fields in the schema which will not be validated by
crdSchemaValidation or objectSchemaValidation.
The list may contain at most 64 fields.
Each path in the list must be unique.
When not specified, all fields in the schema will be validated.
items:
description: |-
Expand Down Expand Up @@ -142,6 +143,9 @@ spec:
minItems: 1
type: array
x-kubernetes-list-type: atomic
x-kubernetes-validations:
- message: each path in the list must be unique.
rule: self.all(x, self.exists_one(y, y.path == x.path))
requiredVersions:
description: |-
requiredVersions specifies a subset of the CRD's API versions which will be asserted for compatibility.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ spec:
excludedFields is a set of fields in the schema which will not be validated by
crdSchemaValidation or objectSchemaValidation.
The list may contain at most 64 fields.
Each path in the list must be unique.
When not specified, all fields in the schema will be validated.
items:
description: |-
Expand Down Expand Up @@ -143,6 +144,9 @@ spec:
minItems: 1
type: array
x-kubernetes-list-type: atomic
x-kubernetes-validations:
- message: each path in the list must be unique.
rule: self.all(x, self.exists_one(y, y.path == x.path))
requiredVersions:
description: |-
requiredVersions specifies a subset of the CRD's API versions which will be asserted for compatibility.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion openapi/generated_openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ spec:
excludedFields is a set of fields in the schema which will not be validated by
crdSchemaValidation or objectSchemaValidation.
The list may contain at most 64 fields.
Each path in the list must be unique.
When not specified, all fields in the schema will be validated.
items:
description: |-
Expand Down Expand Up @@ -142,6 +143,9 @@ spec:
minItems: 1
type: array
x-kubernetes-list-type: atomic
x-kubernetes-validations:
- message: each path in the list must be unique.
rule: self.all(x, self.exists_one(y, y.path == x.path))
requiredVersions:
description: |-
requiredVersions specifies a subset of the CRD's API versions which will be asserted for compatibility.
Expand Down