Cue Kind Definition
Grafana LabsOfficialPublished by Grafana Labs
- Skill
- Tool integration
- Cloud and DevOps
- Apache-2.0
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured approach to defining resource kinds within the grafana-app-sdk ecosystem using CUE. It covers the full lifecycle of kind management, including scaffolding new resources, defining complex schemas with field constraints, versioning, and configuring code generation for Go and TypeScript. It ensures that developers can maintain consistent, type-safe resource models while adhering to the framework's specific manifest and directory requirements.
What it does
- Scaffolds new resource kinds using the CLI.
- Defines spec and status schemas with advanced CUE constraints like regex, enums, and ranges.
- Supports reusable struct definitions using # prefixed types.
- Manages multi-version resource schemas and manifest registration.
- Configures per-kind code generation settings for Go and TypeScript.
- Facilitates the definition of custom API routes at the kind or version level.
When to use it
- When creating a new resource type for a grafana-app-sdk application.
- When adding a new version to an existing resource kind.
- When defining or updating schema field constraints and validation rules.
- When you need to define reusable struct types for complex resource models.
- When adding custom API routes to your application.
Advantages
- Ensures type safety through CUE's constraint-based language.
- Automates the generation of Go and TypeScript code from schema definitions.
- Provides a standardized directory structure for maintainable projects.
- Supports explicit versioning to handle breaking changes safely.
- Reduces manual boilerplate by integrating directly with the SDK's generation tools.
Usage examples
- “How do I add a new resource kind called 'DashboardConfig' to my app?”
- The agent will guide you to run 'grafana-app-sdk project kind add DashboardConfig', edit the generated .cue files in the kinds/ directory, and execute 'grafana-app-sdk generate' to create the necessary Go and TypeScript artifacts.
- “I need to add a regex constraint to a string field in my schema.”
- The agent will show you how to use the '&' operator with the regex pattern, such as 'myField: string & =~"^[a-z]+"'.
- “How do I create a new version for an existing kind?”
- The agent will instruct you to copy the existing version file, rename the top-level object, register the new version in 'kinds/manifest.cue', and re-run the generation command.
- “How can I define a reusable struct for my spec?”
- The agent will explain how to define a '#'-prefixed type within the schema block, which allows you to reuse the struct across multiple fields and ensures it is generated as a named type.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/grafana/cue-kind-definition/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip cue-kind-definition.zip -d .agents/skills
Documentation by Grafana Labs
CUE Kind Definition
Common Workflows
Adding a new kind
# 1. Scaffold the kind files
grafana-app-sdk project kind add MyKind --overwrite
# Produces kinds/mykind.cue + kinds/mykind_v1alpha1.cue + updates kinds/manifest.cue.
# 2. Edit the generated .cue files — fill in schema.spec / schema.status fields
# 3. Generate types and clients
grafana-app-sdk generate
# 4. Verify the generated artifacts exist
ls pkg/generated/ # should contain new types for MyKindIf generate fails with CUE errors:
Read the error — CUE prints the offending file + line + which constraint failed
Common causes: missing required field, type mismatch (e.g.
stringfield assigned anint), unresolved reference between version filesFix the
.cuesource, re-rungrafana-app-sdk generate. Never edit files underpkg/generated/— they're overwritten on every run.
Adding a new version to an existing kind
# 1. Copy the existing version file
cp kinds/mykind_v1alpha1.cue kinds/mykind_v1.cue
# 2. Edit kinds/mykind_v1.cue — rename the top-level object (e.g. myKindv1) and adjust the schema
# 3. Register the new version in kinds/manifest.cue
# Add a versions["v1"]: { schema: myKindv1 } entry
# 4. Re-generate
grafana-app-sdk generate
# 5. Verify both versions were generated — per-version Go types live under pkg/generated/<group>/<version>/
ls pkg/generated/ # should list both version directories (e.g. v1alpha1/ v1/)
# Optionally inspect the CRD spec under definitions/ to confirm both versions appear in `spec.versions[]`Breaking changes (removing fields, changing types, adding required fields) must go into a new version — never modify a stable version (v1, v2) in place.
Kind file structure
The CLI produces a flat layout under kinds/:
kinds/
├── manifest.cue # App manifest + version list declarations
├── mykind.cue # Common (cross-version) kind metadata
└── mykind_v1alpha1.cue # v1alpha1 schema + codegen configFor multi-version kinds, additional version files sit alongside (mykind_v1.cue, etc.). For very large kind sets (10+ kinds), consider the per-kind subdirectory layout — full kind anatomy reference in references/kind-layout.md.
CUE Kind Anatomy
Three layers per kind:
1. Common kind metadata
// kinds/mykind.cue
package kinds
myKind: {
kind: "MyKind" // Required: PascalCase kind name
// other cross-version fields (scope, pluralName, validation, mutation, conversion, …)
// Full field reference in references/kind-layout.md.
}2. Per-version schema
// kinds/mykind_v1alpha1.cue
package kinds
myKindv1alpha1: myKind & {
schema: {
spec: { // desired state — user-set
title: string
description: string | *""
count: int & >=0
enabled: bool | *true
}
status: { // observed state — operator-set
lastObservedGeneration: int | *0
state: string | *""
message: string | *""
}
}
codegen: {
ts: { enabled: true }
go: { enabled: true }
}
}3. App manifest
// kinds/manifest.cue
package kinds
App: {
appName: "my-app"
versions: {
"v1alpha1": { schema: myKindv1alpha1 }
}
}Codegen configuration
Control what gets generated per kind per version:
codegen: {
ts: { enabled: true | false } // TypeScript types
go: { enabled: true | false } // Go types + client
}Disabling go for frontend-only apps avoids unused Go code. Disabling ts for backend-only resources reduces bundle size. Both default to true when omitted.
References
references/kind-layout.md— full common-metadata field reference + app manifest fields + per-kind subdirectory layoutreferences/schema-types.md— CUE schema field types (basic types, constraints, regex, enums, maps, lists) +#-prefixed named type definitionsreferences/custom-routes.md— kind-level + version-level custom routes + handler registration inapp.go
External resources
Files
- ATTRIBUTION.mdAdded by AutoGineer861 B
- LICENSELicence file added by AutoGineer11.1 KiB
- SKILL.md5.3 KiB
- references/cue-constraints.md6.3 KiB
- references/custom-routes.md1.6 KiB
- references/kind-layout.md7.6 KiB
- references/schema-types.md2.0 KiB
- references/versioning-guide.md6.3 KiB
references/kind-layout.md
Kind Layout Reference
Overview
The default layout produced by grafana-app-sdk project kind add places all CUE files directly in kinds/, sharing package kinds. A kind is split into two objects:
myKind(myKind.cue) — common metadata shared across all versions (kind,group,scope, admission config, etc.)myKindv1alpha1(myKind_v1alpha1.cue) — per-version schema joined to the metadata via CUE's&operator
The app manifest (myapp.cue) references version objects directly — no imports needed in the flat layout.
See SKILL.md for the full three-layer anatomy and file structure details.
Full Example Kind
An example kind with all possible fields populated:
package kinds
myKind: {
kind: "MyKind" // [required] The name of the kind
pluralName: "MyKinds" // [optional] The plural form of `kind`. Defaults to `kind`+`s`
scope: "Namespaced" // [optional] "Cluster" or "Namespaced", defaults to "Namespaced"
validation: { // [optional] Validating admission control configuration for the kind
operations: ["POST","PUT","PATCH"] // values limited to "GET","POST","PUT","DELETE","PATCH"
}
mutation: { // [optional] Mutating admission control configuration for the kind
operations: ["POST","PUT","PATCH"] // values limited to "GET","POST","PUT","DELETE","PATCH"
}
conversion: true // [optional] Explicit conversion supported, defaults to false. When true, the App must register a Converter in app.go and ValidateManifest will fail at startup if it is missing.
conversionWebhookProps: { // [optional] Only required if conversion=true and the app is running as a standalone binary
url: "https://myapp.svc.cluster.local:443/convert" // The URL of the conversion webhook which should be called to conver the kind between versions
}
codegen: {
ts: { // [optional] TypeScript codegen settings
enabled: true // [optional] If true TypeScript types are generated for this kind. Defaults to true
config: { // [optional] Configuration to pass into github.com/grafana/cog when running TypeScript generation
// [optional] importsMap associates package names to their import path.
importsMap: {
"common": "github.com/example/common"
}
// [optional] enumsAsUnionTypes controls how CUE enums (disjunctions) are emitted in TypeScript.
// false (default): generates a TypeScript enum declaration, e.g.:
// enum Direction { Up = "up", Down = "down" }
// true: generates a union type, e.g.:
// type Direction = "up" | "down"
// Use true when consumers prefer plain string unions over enum objects (e.g. for JSON serialization compatibility).
enumsAsUnionTypes: false
}
}
go: { // [optional] go codegen settings
enabled: true // [optional] If true go types are generated for this kind. Defaults to true
}
}
}And an example version v1 of that kind with all possible fields populated:
package kinds
myKindv1: myKind & {
// schema is the schema for the kind version, defined as a CUE definition. It must contain at least `spec`.
// Any top-level fields aside from `spec` are considered subresources of the object, the most common of which is `status`
schema: {
spec: {
foo: string
}
status: {
observedGeneration?: int
}
}
// [optional] selectableFields is a list of JSON paths to fields in the schema which can be used as field selectors in the resulting kubernetes API. CRDs limit the number of selectableFields to 8, so it is good practice to have 8 or fewer
selectableFields: [".spec.foo"]
// [optional] additionalPrinterColumns is a list of additional columns to display in a `kubectl get` output for the kind
additionalPrinterColumns: [{
// name is a human readable name for the column.
name: "Foo"
// type is an OpenAPI type definition for this column.
// See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types for details.
type: "string"
// [optional] format is an optional OpenAPI type definition for this column.
// See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types for details.
// Use format: "name" on the column that displays the resource name (.metadata.name) — this signals
// to clients (e.g. kubectl) that the column is the primary identifier.
format: ""
// [optional] description is a human readable description of this column.
description: "Lorem ipsum"
// priority is an integer defining the relative importance of this column compared to others. Lower
// numbers are considered higher priority. Columns that may be omitted in limited space scenarios
// should be given a priority greater than 0.
priority: 1
// jsonPath is a simple JSON path (i.e. with array notation) which is evaluated against
// each custom resource to produce the value for this column.
jsonPath: ".spec.foo"
}]
// [optional] routes is any custom subresource routes for the kind.
// Subresource routes differ from subresources defined in `schema` in that they call a handler, rather than
// store/retrieve a payload to the underlying storage. Route paths must not conflict with subresources defined in `schema` (like `spec` and `status`)
routes: {
// This defines a subresource /message on the kind. Keys in the subsequent map must be all-caps HTTP verbs which correlate to handlers for this subresource
"message": {
// This defines a GET handler for the /message subresource
"GET": {
name: "getMessage" // name is the OpenAPI name of the route, must begin with a kubernetes verb and match the regex `^(get|log|read|replace|patch|delete|deletecollection|watch|connect|proxy|list|create|patch)([A-Za-z0-9]+)$`
// [optional] request information
request: {
// query parameters
query: {
echo: int
}
}
// successful response schema
response: {
message: string
}
// [optional] kubernetes metadata to include in the response payload (impacts codegen and OpenAPI)
responseMetadata: {
typeMeta: true // [optional] include meta/v1.TypeMeta (`kind` and `apiVersion`), defaults to true
objectMeta: false // [optional] include a `metadata` field that contains meta/v1.ObjectMeta (defaults to false). Mutually exclusive with `listMeta`
listMeta: false // [optional] include a `metadata` field that contains meta/v1.ListMeta (defaults to false). Mutually exclusive with `objectMeta`
}
// OpenAPI extensions to add to the generated OpenAPI for the route
extensions: {
"x-myapp-some-extension": "foo"
}
}
// This defines a POST handler for the /message subresource
"POST": {
name: "replaceMessage"
request: {
// [optional] request body schema
body: {
message: string
}
}
response: {
message: string
}
}
}
}
}Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- Grafana Labs
- Publisher
- Grafana Labs (Official)
- Source
- grafana/skills · skills/grafana-app-sdk/cue-kind-definition · commit 8fb72a5
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Grafana Labs.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download cue-kind-definition.zip