-3

我有以下片段



func fakeGetInclusterConfig() (*corev1.ConfigMap, error) {
        configMap := &corev1.ConfigMap{
                Data: map[string]map[string]string{"cluster-config.json":{
                        "cluster_id":"xxx",
                        "cluster_name":"yyy",
                        "cluster_type":"zzz",
                        "cluster_pay_tier":"paid",
                },
                },
        }
        return configMap, nil
}

但是这Data部分有一些问题。我无法正确声明类型。我尝试了所有我知道的选项,但显然不是正确的选项。请有人帮忙

主要代码期望

        configmap, err := cm.GetConfigMap(handler.k8sclient, Configmap, ConfigmapNS)
        clusterConfigJSON := configmap.Data["cluster-config.json"]
        clusterConfigJSON = strings.Replace(clusterConfigJSON, "\n", "", -1)
        clusterConfigJSON = strings.Replace(clusterConfigJSON, " ", "", -1)
        var clusterConfigInfo clusterInfo
        err = json.Unmarshal([]byte(clusterConfigJSON), &clusterConfigInfo)
        if err != nil {

cluster-config.json所以我想要一个key的json结构。我正在尝试为测试用例创建虚拟数据。

4

1 回答 1

0

我可以这样解决

clusterDetails := `{"cluster_id":"xxx","cluster_name":"yyy","cluster_type":"kkk","cluster_pay_tier":"paid","datacenter": "dal","account_id": "mmm","created": "2021-11-23T07:18:25+0000","name": "tokreleasetest","master_public_url": "https://xxx.containers.cloud.nnn.com:1111","master_url": "https://c106.dal-tok.containers.cloud.nnn.com:1111","crn":  "crn:v1:bluemix:public:containers-kubernetes:dal-tok:2334445:cdfr343"}`
        configMap := &corev1.ConfigMap{
                Data: map[string]string{"cluster-config.json":clusterDetails},
        }

于 2022-01-12T16:40:02.187 回答