Skip to content

Commit

Permalink
fix issue #1683
Browse files Browse the repository at this point in the history
  • Loading branch information
realgam3 committed Dec 16, 2023
1 parent af06917 commit f445590
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
25 changes: 25 additions & 0 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package app

import (
"fmt"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -224,6 +225,30 @@ func Convert(opt kobject.ConvertOptions) ([]runtime.Object, error) {

komposeObject.Namespace = opt.Namespace

// convert env_file from absolute to relative path
for _, service := range komposeObject.ServiceConfigs {
if len(service.EnvFile) <= 0 {
continue
}
for i, envFile := range service.EnvFile {
if !filepath.IsAbs(envFile) {
continue
}

workDirAbs, err := filepath.Abs(filepath.Dir(opt.InputFiles[0]))
if err != nil {
log.Fatalf(err.Error())
}

relPath, err := filepath.Rel(workDirAbs, envFile)
if err != nil {
log.Fatalf(err.Error())
}

service.EnvFile[i] = strings.Replace(relPath, "\\", "/", -1)
}
}

// Get a transformer that maps komposeObject to provider's primitives
t := getTransformer(opt)

Expand Down
15 changes: 12 additions & 3 deletions pkg/transformer/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ func (k *Kubernetes) InitSvc(name string, service kobject.ServiceConfig) *api.Se

// InitConfigMapForEnv initializes a ConfigMap object
func (k *Kubernetes) InitConfigMapForEnv(name string, opt kobject.ConvertOptions, envFile string) *api.ConfigMap {
envs, err := GetEnvsFromFile(envFile)
workDir := filepath.Dir(opt.InputFiles[0])
envs, err := GetEnvsFromFile(filepath.Join(workDir, envFile))
if err != nil {
log.Fatalf("Unable to retrieve env file: %s", err)
}
Expand Down Expand Up @@ -1103,7 +1104,8 @@ func ConfigEnvs(service kobject.ServiceConfig, opt kobject.ConvertOptions) ([]ap
envName := FormatEnvName(file)

// Load environment variables from file
envLoad, err := GetEnvsFromFile(file)
workDir := filepath.Dir(opt.InputFiles[0])
envLoad, err := GetEnvsFromFile(filepath.Join(workDir, file))
if err != nil {
return envs, errors.Wrap(err, "Unable to read env_file")
}
Expand Down Expand Up @@ -1579,11 +1581,18 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
return nil, err
}

// Generate pod only and nothing more
// Generate pod and configmap objects
if (service.Restart == "no" || service.Restart == "on-failure") && !opt.IsPodController() {
log.Infof("Create kubernetes pod instead of pod controller due to restart policy: %s", service.Restart)
pod := k.InitPod(name, service)
objects = append(objects, pod)

if len(service.EnvFile) > 0 {
for _, envFile := range service.EnvFile {
configMap := k.InitConfigMapForEnv(name, opt, envFile)
objects = append(objects, configMap)
}
}
} else {
objects = k.CreateWorkloadAndConfigMapObjects(name, service, opt)
}
Expand Down

0 comments on commit f445590

Please sign in to comment.