This commit is contained in:
Tomer Zait 2024-02-18 10:50:15 +02:00
parent d872afb377
commit db6a4d7ce1
4 changed files with 5 additions and 23 deletions

View File

@ -152,7 +152,7 @@ func checkUnsupportedKey(composeProject *types.Project) []string {
// LoadFile loads a compose file into KomposeObject
func (c *Compose) LoadFile(files []string, profiles []string) (kobject.KomposeObject, error) {
// Gather the working directory
workingDir, err := getComposeFileDir(files)
workingDir, err := transformer.GetComposeFileDir(files)
if err != nil {
return kobject.KomposeObject{}, err
}

View File

@ -19,7 +19,6 @@ package compose
import (
"io"
"os"
"path/filepath"
"regexp"
"strings"
@ -133,20 +132,6 @@ func loadEnvVars(envars []string) []kobject.EnvVar {
return envs
}
// getComposeFileDir returns compose file directory
// Assume all the docker-compose files are in the same directory
func getComposeFileDir(inputFiles []string) (string, error) {
inputFile := inputFiles[0]
if strings.Index(inputFile, "/") != 0 {
workDir, err := os.Getwd()
if err != nil {
return "", errors.Wrap(err, "Unable to retrieve compose file directory")
}
inputFile = filepath.Join(workDir, inputFile)
}
return filepath.Dir(inputFile), nil
}
func handleServiceType(ServiceType string) (string, error) {
switch strings.ToLower(ServiceType) {
case "", "clusterip":

View File

@ -965,9 +965,5 @@ func GetContainerArgs(service kobject.ServiceConfig) []string {
// The function does not format the file name further, as it may contain periods or other valid characters.
// Returns the extracted file name.
func GetFileName(fileName string) string {
if strings.Contains(fileName, "/") {
fileName = fileName[strings.LastIndex(fileName, "/")+1:]
}
// Not format filename because can begin with .fileName
return fileName
return filepath.Base(fileName)
}

View File

@ -319,9 +319,10 @@ func initConfigMapData(configMap *api.ConfigMap, data map[string]string) {
binData := map[string][]byte{}
for k, v := range data {
isText := util.IsText([]byte(v))
lfText := strings.Replace(v, "\r\n", "\n", -1)
isText := util.IsText([]byte(lfText))
if isText {
stringData[k] = v
stringData[k] = lfText
} else {
binData[k] = []byte(base64.StdEncoding.EncodeToString([]byte(v)))
}