Skip to content
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

Need a way to insert x-kubernetes-preserve-unknown-fields: true into CRD #489

Open
bcotton opened this issue Nov 19, 2024 · 2 comments
Open
Assignees

Comments

@bcotton
Copy link
Contributor

bcotton commented Nov 19, 2024

Gamma needs the ability to accept complex schemas in a CRD that is beyond cue's capability.

For a CRD I would like the ability to have, similar the Crossplane's XRD

                    schema:
                      properties:
                        openAPIV3Schema:
                          description: OpenAPIV3Schema is the OpenAPI v3 schema to
                            use for validation and pruning.
                          type: object
                          x-kubernetes-preserve-unknown-fields: true
                      type: object

to be emitted from cue.

I'm told that

openAPIV3Schema: {
	[string]: _
}

Might do it, but alas, no, I get

openAPIV3Schema:
  additionalProperties: {}
  type: object
@IfSentient IfSentient self-assigned this Nov 19, 2024
@IfSentient
Copy link
Contributor

@bcotton I can't seemto replicate this when using [string]: _, here's my test:

austin@Abra test % cat kinds/test.cue
package kinds

test: {
	kind: "Test"
	group: "test"
	apiResource: {}
	codegen: frontend: false
	codegen: backend: false
	current: "v1"
	versions: {
		"v1": {
			schema: {
				spec: {
					openAPIV3Schema: {
						[string]: _
					}
				}
			}
		}
	}
}
austin@Abra test % grafana-app-sdk version
v0.25.1
austin@Abra test % grafana-app-sdk generate --crdencoding=yaml
 * Writing file pkg/generated/resource/test/v1/test_codec_gen.go
 * Writing file pkg/generated/resource/test/v1/test_object_gen.go
 * Writing file pkg/generated/resource/test/v1/test_schema_gen.go
 * Writing file definitions/test.test.ext.grafana.com.yaml
 * Writing file definitions/test-manifest.yaml
 * Writing file pkg/generated/manifest.go
austin@Abra test % cat definitions/test.test.ext.grafana.com.yaml
kind: CustomResourceDefinition
apiVersion: apiextensions.k8s.io/v1
metadata:
    name: tests.test.ext.grafana.com
spec:
    group: test.ext.grafana.com
    versions:
        - name: v1
          served: true
          storage: true
          schema:
            openAPIV3Schema:
                properties:
                    spec:
                        properties:
                            openAPIV3Schema:
                                type: object
                                x-kubernetes-preserve-unknown-fields: true
                        required:
                            - openAPIV3Schema
                        type: object
                    status:
                        properties:
                            additionalFields:
                                description: additionalFields is reserved for future use
                                type: object
                                x-kubernetes-preserve-unknown-fields: true
                            operatorStates:
                                additionalProperties:
                                    properties:
                                        descriptiveState:
                                            description: descriptiveState is an optional more descriptive state field which has no requirements on format
                                            type: string
                                        details:
                                            description: details contains any extra information that is operator-specific
                                            type: object
                                            x-kubernetes-preserve-unknown-fields: true
                                        lastEvaluation:
                                            description: lastEvaluation is the ResourceVersion last evaluated
                                            type: string
                                        state:
                                            description: |-
                                                state describes the state of the lastEvaluation.
                                                It is limited to three possible states for machine evaluation.
                                            enum:
                                                - success
                                                - in_progress
                                                - failed
                                            type: string
                                    required:
                                        - lastEvaluation
                                        - state
                                    type: object
                                description: |-
                                    operatorStates is a map of operator ID to operator state evaluations.
                                    Any operator which consumes this kind SHOULD add its state evaluation information to this field.
                                type: object
                        type: object
                        x-kubernetes-preserve-unknown-fields: true
                required:
                    - spec
                type: object
          subresources:
            status: {}
    names:
        kind: Test
        plural: tests
    scope: Namespaced

If I change

openAPIV3Schema: {
	[string]: _
}

to

openAPIV3Schema: _

Then I can replicate your issue and I get

                    spec:
                        properties:
                            openAPIV3Schema: {}
                        required:
                            - openAPIV3Schema
                        type: object

I'll look into what's going on in the second case, but can you run my test CUE and see if this works for you? And if it doesn't, please let me know the output of grafana-app-sdk version -v and your OS/version

@bcotton
Copy link
Contributor Author

bcotton commented Dec 2, 2024

Sorry, didn't see this comment.

Seems to be when the

openAPIV3Schema: {
	[string]: _
}

is in an a "named" (don't know what cue calls it) type:

This is both:

% grafana-app-sdk version
dev-(HEAD detached at v0.25.2)

grafana-app-sdk version
dev-lts/v0.24

Example:

package kinds

test: {
	kind: "Test"
	group: "test"
	apiResource: {}
	codegen: frontend: false
	codegen: backend: false
	current: "v1"
	versions: {
		"v1": {
			schema: {
				#Version: {
					schema?: {
						customProperties: {
							openAPIV3Schema: {
								[string]: _
							}
						}
					}
				}
				spec: {
					openAPIV3Schema: {
						[string]: _
					}
					versions: [...#Version]
				}
			}
		}
	}
}

Resulting CRD:

kind: CustomResourceDefinition
apiVersion: apiextensions.k8s.io/v1
metadata:
    name: tests.test.ext.grafana.com
spec:
    group: test.ext.grafana.com
    versions:
        - name: v1
          served: true
          storage: true
          schema:
            openAPIV3Schema:
                properties:
                    spec:
                        properties:
                            openAPIV3Schema:
                                type: object
                                x-kubernetes-preserve-unknown-fields: true
                            versions:
                                items:
                                    properties:
                                        schema:
                                            properties:
                                                customProperties:
                                                    properties:
                                                        openAPIV3Schema:
                                                            additionalProperties: {}
                                                            type: object
                                                    required:
                                                        - openAPIV3Schema
                                                    type: object
                                            required:
                                                - customProperties
                                            type: object
                                    type: object
                                type: array
                        required:
                            - openAPIV3Schema
                            - versions
                        type: object
                    status:
                        properties:
                            additionalFields:
                                description: additionalFields is reserved for future use
                                type: object
                                x-kubernetes-preserve-unknown-fields: true
                            operatorStates:
                                additionalProperties:
                                    properties:
                                        descriptiveState:
                                            description: descriptiveState is an optional more descriptive state field which has no requirements on format
                                            type: string
                                        details:
                                            description: details contains any extra information that is operator-specific
                                            type: object
                                            x-kubernetes-preserve-unknown-fields: true
                                        lastEvaluation:
                                            description: lastEvaluation is the ResourceVersion last evaluated
                                            type: string
                                        state:
                                            description: |-
                                                state describes the state of the lastEvaluation.
                                                It is limited to three possible states for machine evaluation.
                                            enum:
                                                - success
                                                - in_progress
                                                - failed
                                            type: string
                                    required:
                                        - lastEvaluation
                                        - state
                                    type: object
                                description: |-
                                    operatorStates is a map of operator ID to operator state evaluations.
                                    Any operator which consumes this kind SHOULD add its state evaluation information to this field.
                                type: object
                        type: object
                        x-kubernetes-preserve-unknown-fields: true
                required:
                    - spec
                type: object
          subresources:
            status: {}
    names:
        kind: Test
        plural: tests
    scope: Namespaced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants