Cue Kind Definition

作者 grafana1ccacf29049fApache-2.0279 个星标收录于 2026年10月8日更新于 2026年10月8日仓库今天更新

Author CUE kind definitions for grafana-app-sdk apps - schemas, versioning, field constraints, named type definitions, custom routes, and codegen configuration. Scaffolds kinds via `grafana-app-sdk project kind add`, writes spec/status schemas with type constraints (regex, enum, range), defines `#`-prefixed named types for reusable structs, registers versions in the app manifest, and runs `grafana-app-sdk generate` with explicit error recovery. Use when working with CUE kinds, adding a new resource type, adding a version to an existing kind, writing schema field constraints, defining `#Definition` types, adding custom routes, editing files under `kinds/`, or when the user asks to "model a resource", "add a CUE schema", or "write a kind" — even without saying "CUE" explicitly.

AI 生成的概览

为 grafana-app-sdk 应用编写 CUE kind 定义,涵盖 schema、版本管理、约束与代码生成。

功能
该技能指导为 grafana-app-sdk 应用编写 CUE kind 定义。它使用 grafana-app-sdk project kind add 命令搭建 kind 文件,编写带字段约束的 spec 与 status schema,定义可复用的命名类型,在应用清单中注册版本,并运行 grafana-app-sdk generate 并提供错误恢复方法。它还涵盖为现有 kind 添加版本以及配置 TypeScript 和 Go 代码生成。
适用场景
适用于处理 CUE kind、添加新资源类型或为现有 kind 添加版本、编写 schema 字段约束、定义命名类型、添加自定义路由,或编辑 kinds/ 目录下文件时。当用户要求对资源建模、添加 CUE schema 或编写 kind 时也适用。
运行要求
需要 grafana-app-sdk 命令行工具用于搭建和代码生成,以及 CUE 工具用于 schema 校验。该技能不附带脚本,仅包含说明和参考文档。

CUE Kind Definition

Common Workflows

Adding a new kind

bash
# 1. Scaffold the kind filesgrafana-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 clientsgrafana-app-sdk generate
# 4. Verify the generated artifacts existls pkg/generated/    # should contain new types for MyKind

If 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. string field assigned an int), unresolved reference between version files
  • Fix the .cue source, re-run grafana-app-sdk generate. Never edit files under pkg/generated/ — they're overwritten on every run.

Adding a new version to an existing kind

bash
# 1. Copy the existing version filecp 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-generategrafana-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 config

For 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 [blocked].

CUE Kind Anatomy

Three layers per kind:

1. Common kind metadata

cue
// kinds/mykind.cuepackage 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

cue
// kinds/mykind_v1alpha1.cuepackage 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

cue
// kinds/manifest.cuepackage kinds
App: {    appName: "my-app"    versions: {        "v1alpha1": { schema: myKindv1alpha1 }    }}

Codegen configuration

Control what gets generated per kind per version:

cue
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 [blocked] — full common-metadata field reference + app manifest fields + per-kind subdirectory layout
  • references/schema-types.md [blocked] — CUE schema field types (basic types, constraints, regex, enums, maps, lists) + #-prefixed named type definitions
  • references/custom-routes.md [blocked] — kind-level + version-level custom routes + handler registration in app.go

External resources

来源与署名

来源:grafana/skills位于skills/grafana-app-sdk/cue-kind-definition提交1ccacf2

许可证: Apache-2.0

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架

更多来自 grafana/skills 的技能

React 19 Plugin Migration

grafana

指导将 Grafana 插件迁移至 React 19 兼容,按顺序完成构建、依赖与源码修改步骤。

Software Development279今天更新

Plugin Bundle Size

grafana

指导使用 React.lazy、Suspense 和 webpack 代码分割来优化 Grafana 应用插件包体积。

Software Development279今天更新

Grafana Scenes

grafana

使用 @grafana/scenes 框架构建 Grafana 插件页面,涵盖场景、面板、变量与下钻导航。

Software Development279今天更新

Check Npm

grafana

对 JS/TS 仓库的 npm、yarn 或 pnpm 配置进行只读供应链加固审计。

Security279今天更新

Mimir

grafana

指导搭建和运维 Grafana Mimir,用于可扩展、多租户、长期的 Prometheus 与 OTLP 指标存储。

DevOps & Cloud279今天更新

K6 Trend Analysis

grafana

Analyze Grafana Cloud k6 test run trends over time. Detects slow metric drift (e.g., P95 latency creeping up while still passing thresholds), computes headroom to thresholds, flags anomalies, and recommends threshold tightening. Use when the user asks about test performance trends, wants to know if metrics are degrading, asks whether thresholds should be tightened, or wants a health check across recent runs for a specific test. Trigger on phrases like "how is my test trending", "is P95 getting worse", "check for performance regression", "should I tighten thresholds", "are my tests degrading", "show me trends for test X", "analyze my k6 test runs", or "is my test getting slower". Also trigger when a user asks to check all tests in a project -- run this skill once per test and synthesize.

待分类279今天更新