问题描述
我正在尝试使用YAML文件在OpenShift中创建ConfigMap。
我的YAML的值列表如下。
kind: ConfigMap
apiVersion: v1
metadata:
name: sample-map-json-fields
namespace: default
data:
fields:
- hello
- world
- my.test.field
我像下面这样执行-
oc create -f filename.yaml
获取如下异常-
来自服务器的错误(BadRequest):创建“ filename.yaml”时出错: 版本“ v1”中的ConfigMap不能作为ConfigMap处理:[pos 42]: json:期望为char'“',但得到char'['
如果我在数据中没有列表内容的情况下也这样做,那么它将起作用。
请帮助您处理ConfigMap的YAML列表。
解决方法
这不起作用,因为您提供的是array
,而Kubernetes希望收到string
。
got "array",expected "string"
请在Kubernetes API文档中阅读有关configMap的更多信息:
data - _object_
Data contains the configuration data. Each key must
consist of alphanumeric characters,'-','_' or '.'. Values with
non-UTF-8 byte sequences must use the BinaryData field. The keys
stored in Data must not overlap with the keys in the BinaryData field,this is enforced during validation process.
或者随时随地docs:
// Data contains the configuration data.
// Each key must consist of alphanumeric characters,'_' or '.'.
// Values with non-UTF-8 byte sequences must use the BinaryData field.
// The keys stored in Data must not overlap with the keys in
// the BinaryData field,this is enforced during validation process.
// +optional
Data map[string]string `json:"data,omitempty" protobuf:"bytes,2,rep,name=data"`