func()

in pkg/trait/trait_types.go [463:571]


func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]corev1.VolumeMount) {
	//
	// Volumes :: Sources
	//
	idx := 0
	for _, s := range e.Integration.Sources() {
		if e.isEmbedded(s) {
			continue
		}
		cmName := fmt.Sprintf("%s-source-%03d", e.Integration.Name, idx)
		if s.ContentRef != "" {
			cmName = s.ContentRef
		}
		cmKey := "content"
		if s.ContentKey != "" {
			cmKey = s.ContentKey
		}
		resName := strings.TrimPrefix(s.Name, "/")
		refName := fmt.Sprintf("i-source-%03d", idx)
		resPath := filepath.Join(camel.SourcesMountPath, resName)
		vol := getVolume(refName, "configmap", cmName, cmKey, resName)
		mnt := getMount(refName, resPath, resName, true)

		*vols = append(*vols, *vol)
		*mnts = append(*mnts, *mnt)
		idx++
	}

	if e.Resources != nil {
		e.Resources.VisitConfigMap(func(configMap *corev1.ConfigMap) {
			propertiesType := configMap.Labels["camel.apache.org/properties.type"]
			resName := propertiesType + ".properties"

			var mountPath string
			switch propertiesType {
			case "application":
				mountPath = filepath.Join(camel.BasePath, resName)
			case "user":
				mountPath = filepath.Join(camel.ConfDPath, resName)
			}

			if propertiesType != "" {
				refName := propertiesType + "-properties"
				vol := getVolume(refName, "configmap", configMap.Name, "application.properties", resName)
				mnt := getMount(refName, mountPath, resName, true)

				*vols = append(*vols, *vol)
				*mnts = append(*mnts, *mnt)
			}
		})
	}

	//
	// Volumes :: Additional ConfigMaps
	//
	for _, configmaps := range e.collectConfigurations("configmap") {
		refName := kubernetes.SanitizeLabel(configmaps["value"])
		mountPath := getMountPoint(configmaps["value"], configmaps["resourceMountPoint"], "configmap", configmaps["resourceType"])
		vol := getVolume(refName, "configmap", configmaps["value"], configmaps["resourceKey"], configmaps["resourceKey"])
		mnt := getMount(refName, mountPath, "", true)

		*vols = append(*vols, *vol)
		*mnts = append(*mnts, *mnt)
	}

	//
	// Volumes :: Additional Secrets
	//
	for _, secret := range e.collectConfigurations("secret") {
		refName := kubernetes.SanitizeLabel(secret["value"])
		mountPath := getMountPoint(secret["value"], secret["resourceMountPoint"], "secret", secret["resourceType"])
		vol := getVolume(refName, "secret", secret["value"], secret["resourceKey"], secret["resourceKey"])
		mnt := getMount(refName, mountPath, "", true)

		*vols = append(*vols, *vol)
		*mnts = append(*mnts, *mnt)
	}
	// append Service Binding secrets
	if len(e.ServiceBindingSecret) > 0 {
		secret := e.ServiceBindingSecret
		refName := kubernetes.SanitizeLabel(secret)
		mountPath := filepath.Join(camel.ServiceBindingsMountPath, strings.ToLower(secret))
		vol := getVolume(refName, "secret", secret, "", "")
		mnt := getMount(refName, mountPath, "", true)

		*vols = append(*vols, *vol)
		*mnts = append(*mnts, *mnt)
	}

	//
	// Volumes :: Additional user provided volumes
	//
	for _, volumeConfig := range e.collectConfigurationValues("volume") {
		configParts := strings.Split(volumeConfig, ":")

		if len(configParts) != 2 {
			continue
		}

		pvcName := configParts[0]
		mountPath := configParts[1]
		volumeName := pvcName + "-data"

		vol := getVolume(volumeName, "pvc", pvcName, "", "")
		mnt := getMount(volumeName, mountPath, "", false)
		*vols = append(*vols, *vol)
		*mnts = append(*mnts, *mnt)
	}
}