k3s-io/helm-controller

MountVolume.SetUp failed for volume "content" error if chart.Spec.ChartContent not set

cubinet-code opened this issue · 1 comments

Issue
If chart.Spec.ChartContent is empty (like for most charts which come from a repo), an empty ConfigMap "chart-content-%s" is created, causing the helm-install job to try to mount this empty ConfigMap as volume leading to an error.

setContentConfigMap() checks for nil, however a skeleton ConfigMap is returned by contentConfigMap() anyway causing the check to pass and the volume mount added to the job.Spec.

Proposed Fix:
Check in setContentConfigMap() if the ConfigMap.Data is empty and skip adding the volume mount to the job.

func contentConfigMap(chart *helmv1.HelmChart) *core.ConfigMap {
	configMap := &core.ConfigMap{
		TypeMeta: meta.TypeMeta{
			APIVersion: "v1",
			Kind:       "ConfigMap",
		},
		ObjectMeta: meta.ObjectMeta{
			Name:      fmt.Sprintf("chart-content-%s", chart.Name),
			Namespace: chart.Namespace,
		},
		Data: map[string]string{},
	}

	if chart.Spec.ChartContent != "" {
		key := fmt.Sprintf("%s.tgz.base64", chart.Name)
		configMap.Data[key] = chart.Spec.ChartContent
	}

	return configMap
}
func setContentConfigMap(job *batch.Job, chart *helmv1.HelmChart) *core.ConfigMap {
	configMap := contentConfigMap(chart)
	if configMap == nil {
		return nil
	}

	job.Spec.Template.Spec.Volumes = append(job.Spec.Template.Spec.Volumes, []core.Volume{
		{
			Name: "content",

I can't reproduce this; I regularly install charts (both Rancher and cert-manager) from repos without any ChartContent.