lburgazzoli commented on code in PR #5090: URL: https://github.com/apache/camel-k/pull/5090#discussion_r1500464327
########## pkg/trait/mount.go: ########## @@ -165,4 +193,191 @@ func (t *mountTrait) mountResource(vols *[]corev1.Volume, mnts *[]corev1.VolumeM *vols = append(*vols, *vol) *mnts = append(*mnts, *mnt) + + // User specified location file (only properties file) + if dstDir != "" { + if strings.HasSuffix(dstDir, ".properties") { + return []string{mntPath}, nil + } + return nil, nil + } + + // We only process this for text configuration .properties files, never for resources + if conf.ContentType() == utilResource.ContentTypeText { + // the user asked to store the entire resource without specifying any filter + // we need to list all the resources belonging to the resource + if conf.StorageType() == utilResource.StorageTypeConfigmap { + cm := kubernetes.LookupConfigmap(e.Ctx, e.Client, e.Integration.Namespace, conf.Name()) + if cm != nil { + for k := range cm.Data { + if strings.HasSuffix(k, ".properties") { + paths = append(paths, fmt.Sprintf("%s/%s", mntPath, k)) + } else { + // Deprecated: use explicit configuration instead + envName := strings.ToUpper(strings.ReplaceAll(strings.ReplaceAll(k, "-", "_"), ".", "_")) + t.L.Infof(`Deprecation notice: the operator is adding the environment variable %s which will take runtime value from configmap. + This feature may disappear in future releases, make sure to use properties file in you configmap instead.`, envName) + propsAsEnv = append(propsAsEnv, corev1.EnvVar{ + Name: envName, + ValueFrom: &corev1.EnvVarSource{ + ConfigMapKeyRef: &corev1.ConfigMapKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: cm.Name, + }, + Key: k, + }, + }, + }) + } + } + } + } else if conf.StorageType() == utilResource.StorageTypeSecret { + sec := kubernetes.LookupSecret(e.Ctx, e.Client, e.Integration.Namespace, conf.Name()) + if sec != nil { + for k := range sec.Data { + if strings.HasSuffix(k, ".properties") { + paths = append(paths, fmt.Sprintf("%s/%s", mntPath, k)) + } else { + // Deprecated: use explicit configuration instead + envName := strings.ToUpper(strings.ReplaceAll(strings.ReplaceAll(k, "-", "_"), ".", "_")) + t.L.Infof(`Deprecation notice: the operator is adding the environment variable %s which will take runtime value from secret. + This feature may disappear in future releases, make sure to use properties file in you secret instead.`, envName) + propsAsEnv = append(propsAsEnv, corev1.EnvVar{ + Name: envName, + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: sec.Name, + }, + Key: k, + }, + }, + }) + } + } + } + } + } + + return paths, propsAsEnv +} + +// Configure the list of location which the runtime will look for application.properties files. +func (t *mountTrait) setConfigLocations(container *corev1.Container, configPaths []string) { + if configPaths != nil { + envvar.SetVar(&container.Env, corev1.EnvVar{ + Name: "QUARKUS_CONFIG_LOCATIONS", Review Comment: We have established a contract for which each runtime (quarkus and in future spring boot and eventually plain camel main) must honor in order to be camel-k compatible which states where the config maps, secrets and resources are projected. Given that each runtime has it's own machinery to discover/load properties I think this goes in the wrong direction as implies the operator to have a deep knowledge of the runtime, which we want to avoid. The operator must only mount config maps, secrets and resources in the expected directories and then leave discovery part to the specific runtime. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org