开发者社区 > 云原生 > 正文

在使用OAM/KubeVela 时,报这种错误,怎么排查 自己写的cue啊?

问题一:Error: cannot generate manifests from components and traits: evaluate template trait=scaler app=app-volumes: cue: marshal error: spec.template.spec.volumes.2.secret.secretName: cannot convert incomplete value "string" to JSON 在使用OAM/KubeVela 时,报这种错误,怎么排查 自己写的cue啊? 问题二:volumes: { alias: "" annotations: {} attributes: { appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"] podDisruptive: true } description: "Add volumes on K8s pod for your workload which follows the pod spec in path 'spec.template'." labels: { cae: "true" } type: "trait" }

template: { patch: { spec: template: spec: { if parameter.volumes != | { volumes: [ for v in parameter.volumes { { name: v.name if v.type == "pvc" { persistentVolumeClaim: claimName: v.claimName } if v.type == "configMap" { configMap: { defaultMode: v.defaultMode name: v.name if v.items != | { items: v.items } } } if v.type == "secret" { secret: { defaultMode: v.defaultMode secretName: v.secretName if v.items != | { items: v.items } } } if v.type == "emptyDir" { emptyDir: medium: v.medium } if v.type == "nfs" { nfs: { server: v.server path: v.path readOnly: v.readOnly } } } }] } } } parameter: { // +usage=Declare volumes volumes?: [...{ name: string // +usage=Specify volume type, options: "pvc","configMap","secret","emptyDir","nfs", default to emptyDir type: *"emptyDir" | "pvc" | "configMap" | "secret" | "nfs" if type == "pvc" { claimName: string } if type == "configMap" { defaultMode: *420 | int name: string items?: [...{ key: string path: string mode: *511 | int }] } if type == "secret" { defaultMode: *420 | int secretName: string items?: [...{ key: string path: string mode: *511 | int }] } if type == "emptyDir" { medium: *"" | "Memory" } if type == "nfs" { server: string path: string readOnly: *false | bool } }] } }

这样的cue apiVersion: core.oam.dev/v1beta1 kind: Application metadata: annotations: app.oam.dev/publishVersion: "20230626154212642" oam.dev/kubevela-version: v1.8.1 creationTimestamp: "2023-06-26T06:22:36Z" finalizers: - app.oam.dev/resource-tracker-finalizer generation: 8 name: app-volumes namespace: sce resourceVersion: "94664613" uid: 3fb4e47b-b30a-4b55-a3bd-1b93ed171b39 spec: components: - name: app-volumes properties: image: registry.nevis.sina.com.cn/sce/sce-app02:171 traits: - properties: containers: - containerName: app13 limits: cpu: "0.5" memory: 345Mi requests: cpu: "0.5" memory: 345Mi type: resource - properties: ports: - port: 8090 type: expose - properties: volumes: - emptyDir: {} name: test01 type: emptyDir - configMap: defaultMode: 430 name: app-info name: test02 type: configMap - name: test03 secret: defaultMode: 420 secretName: king-cluster-autoscaler-cloud-config-v2 type: secret type: volumes type: webservice configMap 可以 secret 不行

展开
收起
乐天香橙派 2023-07-04 15:39:20 72 0
2 条回答
写回答
取消 提交回答
  • 对于问题一中的错误,报错信息提示在生成组件和 traits 的清单时出现了问题。具体是在处理 spec.template.spec.volumes.2.secret.secretName 时出现错误。根据错误信息,该值不能转换为 JSON。

    要排查这个问题,您可以执行以下步骤:

    1. 检查 cue 文件:检查 app-volumes.cue 文件中的相关代码,确保没有语法错误或拼写错误。尤其需要注意涉及到 volumessecret 的部分。

    2. 验证数据结构:检查 cue 文件中定义的数据结构(例如 parameter)与实际提供的数据是否匹配。比较 cue 文件中的参数和您在应用程序清单中提供的内容,确保参数名、类型和层次结构都正确。

    3. 调试数据传递:如果 cue 文件中涉及到数据传递,例如 traits 中使用了 templatepatch 字段,确保数据能够正确传递给相应的字段,并且格式与期望的 JSON 结构匹配。

    4. 打印日志:在 cue 文件中添加一些调试日志语句来输出变量和值,以便更详细地了解错误发生的位置和原因。您可以使用 println 函数来打印信息。

    2023-07-28 16:23:16
    赞同 展开评论 打赏
  • 针对问题一的回答:就是你的secretName不够明确,最终的解析结果是string这种类型而不是一个确定的字符串。 spec.template.spec.volumes.2.secret.secretName给了出错的字段路径 针对问题二的回答:你这个secretName是放在secret下面的,但是cue中的parameter定义没有放在secret下面——此回答来自钉群”OAM/KubeVela 社区交流群“

    2023-07-04 16:54:51
    赞同 展开评论 打赏

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载