client-go 使用 configmap 作为卷创建一个 Pod

问题描述

我正在实施一个准入 webhook,它应该添加一个 sidecar 容器,其配置需要从 configmap 按照当前流程,假设 configmap 存在于集群中,我只需要 VolumeMounts 它。 我正在 client-go 中尝试以下代码:

pod.Spec.Volumes = append(pod.Spec.Volumes,corev1.Volume{
        Name: "startup-config",VolumeSource: corev1.VolumeSource{
            ConfigMap: &corev1.ConfigMapVolumeSource{
                v1.LocalObjectReference{
                    Name: "my-configmap",},})

但是我收到了 too few values in "k8s.io/api/core/v1".ConfigMapVolumeSource literal 错误 由于 configmap 对象已存在于集群中,因此除了 Nameconfigmap 之外,我不想/不需要提供任何其他字段 我在这里缺少什么? ps:文档提到 ConfigMapVolumeSource 中的所有其他字段都是可选的。 我想实现一些简单的事情:

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "/bin/sh","-c","ls /etc/config/" ]
      volumeMounts:
      - name: config-volume
        mountPath: /etc/config
  volumes:
    - name: config-volume
      configMap:
        # Provide the name of the ConfigMap containing the files you want
        # to add to the container
        name: special-config

YAML 清单只是一个例子。我想要达到的目标

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...