Symptom:
We use partial yaml below to create a statefulset with mount a volume for configmap.It is successfulapiVersion: apps/v1
kind: StatefulSet
......
spec:
volumes:
- name: pgreplica-config
configMap:
name: pgconfigmap
........
When we try to use client-go to do the same thing.
Related codes
o.pgreplicamaster.Spec.Template.Spec.Volumes = []corev1.Volume{
{Name: "pgreplica-config",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
Items: corev1.KeyToPath{{Key: "name",Path: pgconfigmap}},
},
},
},
}
We hit error
Error: spec.volumes[1].configMap.name: Required value, spec.containers[0].volumeMounts[1].name: Not found
Solution
Refer k8s doc of ConfigMapVolumeSourceThere is LocalObjectReference which we should use, instead of using Items
Update code as below to make it work
o.pgreplicamaster.Spec.Template.Spec.Volumes = []corev1.Volume{
{Name: "pgreplica-config",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{Name: "pgconfigmap"},
},
},
},
}
No comments:
Post a Comment