–
1. 背景
当我们写了一遍vaule.yaml,再写一遍value.schema.json这是非常繁琐的。因此,有这样一块关于helm的插件使用一条命令即可达到目的。
helm-schema-gen
2. 安装
该插件适用于 Helm v2 和 v3 版本,因为它与 Helm 二进制版本无关
$ helm plugin install https://github.com/karuppiah7890/helm-schema-gen.git
karuppiah7890/helm-schema-gen info checking GitHub for tag '0.0.4'
karuppiah7890/helm-schema-gen info found version: 0.0.4 for 0.0.4/Darwin/x86_64
karuppiah7890/helm-schema-gen info installed ./bin/helm-schema-gen
Installed plugin: schema-gen
或者你也可以下载helm-schema-gen命令
tar tvf helm-schema-gen_0.0.4_Linux_x86_64.tar
./helm-schema-gen --help
mv helm-schema-gen /usr/local/bin/
3. 用法
该插件适用于 Helm v2 和 v3 版本
让我们采取values.yaml如下示例
replicaCount: 1
image:
repository: nginx
pullPolicy: IfNotPresent
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
serviceAccount:
create: true
name:
podSecurityContext: {}
securityContext: {}
service:
type: ClusterIP
port: 80
ingress:
enabled: false
annotations: {}
hosts:
- host: chart-example.local
paths: []
tls: []
resources: {}
nodeSelector: {}
tolerations: []
affinity: {}
现在,如果您使用插件并将 传递values.yaml给它,您将获得 JSON Schemavalues.yaml
$ helm schema-gen values.yaml
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"properties": {
"affinity": {
"type": "object"
},
"fullnameOverride": {
"type": "string"
},
"image": {
"type": "object",
"properties": {
"pullPolicy": {
"type": "string"
},
"repository": {
"type": "string"
}
}
},
"imagePullSecrets": {
"type": "array"
},
"ingress": {
"type": "object",
"properties": {
"annotations": {
"type": "object"
},
"enabled": {
"type": "boolean"
},
"hosts": {
"type": "array",
"items": {
"type": "object",
"properties": {
"host": {
"type": "string"
},
"paths": {
"type": "array"
}
}
}
},
"tls": {
"type": "array"
}
}
},
"nameOverride": {
"type": "string"
},
"nodeSelector": {
"type": "object"
},
"podSecurityContext": {
"type": "object"
},
"replicaCount": {
"type": "integer"
},
"resources": {
"type": "object"
},
"securityContext": {
"type": "object"
},
"service": {
"type": "object",
"properties": {
"port": {
"type": "integer"
},
"type": {
"type": "string"
}
}
},
"serviceAccount": {
"type": "object",
"properties": {
"create": {
"type": "boolean"
},
"name": {
"type": "null"
}
}
},
"tolerations": {
"type": "array"
}
}
}
您可以将其保存到这样的文件中
$ helm schema-gen values.yaml > values.schema.json
如果是下载的helm-schema-gen命令
helm-schema-gen value.yaml > values.schema.json