Skip to content

Conversation

@liebman
Copy link
Contributor

@liebman liebman commented Apr 28, 2025

This PR adds JSONPatch support to the Model CRD.

There is difficulty representing the Value field in JSONPatch, its a go interface{} but there seems to be no type to map it to in CRDs. So this is implemented as a string expected to contain the JSON encoded value, For instance if the value is a string: "\"this-is-a string-value\""

@liebman
Copy link
Contributor Author

liebman commented Apr 28, 2025

I added a test that tries to set a string value and as expected when defining the Type as object it fails

    model_jsonpatch_test.go:40: 
                Error Trace:    kubeai/test/integration/model_jsonpatch_test.go:40
                Error:          Received unexpected error:
                                Model.kubeai.org "testjsonpatch" is invalid: [spec.jsonPatches[0].value: Invalid value: "string": spec.jsonPatches[0].value in body must be of type object: "string", <nil>: Invalid value: "null": some validation rules were not checked because the object was invalid; correct the existing errors to complete validation]
                Test:           TestJSONPatch

If I don't set a Type it errors loading the CRD complaining there is no type.

@liebman
Copy link
Contributor Author

liebman commented Apr 29, 2025

@nstogner any ideas on how to declare the Value field?

@liebman
Copy link
Contributor Author

liebman commented Apr 29, 2025

The only way I can think of to make this work is to store Value as a string containing json. So a string value would be encoded as ""string-value"", an integer as "123" and an object as "{"something": 42}" and I don't like it as it's not what the user would expect, especially in a Model yaml file, the value would still need to be a encoded as json in a string.

@liebman
Copy link
Contributor Author

liebman commented May 2, 2025

Implemented where JSONPatch.value is a string expected to contain valid JSON.

@liebman liebman marked this pull request as ready for review May 5, 2025 15:22
@liebman liebman force-pushed the support-jsonpath-in-model branch 3 times, most recently from b5387d9 to 24e7ec7 Compare July 23, 2025 19:28
@liebman liebman force-pushed the support-jsonpath-in-model branch from 24e7ec7 to 1dc8dd5 Compare December 8, 2025 17:23
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

Successfully merging this pull request may close these issues.

1 participant