Replies: 2 comments 1 reply
-
|
Would there be a way to figure out or set a default resource for a certain kind of resource? |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Depending on introducing an apiVersion in discussion 2, it will have to be referred here as well |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Enforcing Schema and Dependencies in Resource JSON
Problem Statement
In our Intent-based Catalog Architecture (InCa), we define resources using a JSON format, which includes various fields to describe the resource, its specifications, and potential dependencies on other resources. The challenge arises in ensuring that:
Example Scenario
Consider a scenario where a resource, such as a Kubernetes node pool, requires another resource - Kubernetes - to be defined as a required dependency. Moreover, since there can be more than one instance of Kubernetes, a mechanism to refer to specific resources in the InCa is crucial.
Suggested Solution
JSON Schema Definition
We propose utilizing JSON Schema to define the structure and validation rules for our resource JSON. This schema will define all necessary fields, their data types, and possible values, ensuring that the resource JSON adheres to the expected format and provides all necessary information.
Dependency Management
In the
dependenciessection, we introduce two key subsections:Each dependency specifies:
{ "resourceID": "example_resource", "metadata": { "name": "ExampleResource", "description": "A sample resource in InCa.", "maintainer": "[email protected]", "documentation_link": "http://example.com/docs", "tags": ["example", "sample"] }, "spec": { // ... resource specifications ... }, "dependencies": { "required": { "dep1": { "kind": "SpecificKind", "resourceRef": "SpecificResourceInstance" } }, "optional": { "dep2": { "kind": "AnotherKind", "resourceRef": "AnotherResourceInstance" } } } }Validating Data Types and Enforcing Required Dependencies with JSON Schema
Ensuring that the specified dependencies adhere to the expected data types and that required dependencies are indeed provided is crucial for maintaining the integrity of the resource definitions. JSON Schema allows us to enforce these rules by defining the expected data types for each field and marking fields as required when necessary.
Consider a scenario where a "Kubernetes Node Pool" resource must always have a dependency on a "Kubernetes" resource. We can enforce this in the JSON Schema by marking the "Kubernetes" dependency as required in the
dependenciessection and specifying the expected data type for thekindandresourceReffields.Here's a sample schema for the
dependenciessection of a "Kubernetes Node Pool" resource:{ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": { "dependencies": { "type": "object", "properties": { "required": { "type": "object", "properties": { "kubernetes": { "type": "object", "properties": { "kind": { "type": "string", "enum": ["Kubernetes"] }, "resourceRef": { "type": "string" } }, "required": ["kind", "resourceRef"] } }, "required": ["kubernetes"] }, "optional": { "type": "object", "additionalProperties": { "type": "object", "properties": { "kind": { "type": "string" }, "resourceRef": { "type": "string" } }, "required": ["kind", "resourceRef"] } } }, "required": ["required"] } } }Beta Was this translation helpful? Give feedback.
All reactions