forked from LaconicNetwork/kompose
Merge pull request #1838 from microsec-ambrose/upgrade-compose-go
chore(deps): bump Go version and github.com/compose-spec/compose-go
This commit is contained in:
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package compose
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
@@ -24,8 +25,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/compose-spec/compose-go/cli"
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/compose-spec/compose-go/v2/cli"
|
||||
"github.com/compose-spec/compose-go/v2/types"
|
||||
"github.com/fatih/structs"
|
||||
"github.com/google/shlex"
|
||||
"github.com/kubernetes/kompose/pkg/kobject"
|
||||
@@ -167,7 +168,7 @@ func (c *Compose) LoadFile(files []string, profiles []string) (kobject.KomposeOb
|
||||
return kobject.KomposeObject{}, errors.Wrap(err, "Unable to create compose options")
|
||||
}
|
||||
|
||||
project, err := cli.ProjectFromOptions(projectOptions)
|
||||
project, err := cli.ProjectFromOptions(context.Background(), projectOptions)
|
||||
if err != nil {
|
||||
return kobject.KomposeObject{}, errors.Wrap(err, "Unable to load files")
|
||||
}
|
||||
@@ -566,7 +567,7 @@ func dockerComposeToKomposeMapping(composeObject *types.Project) (kobject.Kompos
|
||||
parseEnvironment(&composeServiceConfig, &serviceConfig)
|
||||
|
||||
// Get env_file
|
||||
serviceConfig.EnvFile = composeServiceConfig.EnvFile
|
||||
parseEnvFiles(&composeServiceConfig, &serviceConfig)
|
||||
|
||||
// Parse the ports
|
||||
// v3 uses a new format called "long syntax" starting in 3.2
|
||||
@@ -695,6 +696,13 @@ func parseEnvironment(composeServiceConfig *types.ServiceConfig, serviceConfig *
|
||||
}
|
||||
}
|
||||
|
||||
func parseEnvFiles(composeServiceConfig *types.ServiceConfig, serviceConfig *kobject.ServiceConfig) {
|
||||
for _, value := range composeServiceConfig.EnvFiles {
|
||||
serviceConfig.EnvFile = append(serviceConfig.EnvFile, value.Path)
|
||||
// value.Required is ignored
|
||||
}
|
||||
}
|
||||
|
||||
func handleCronJobConcurrencyPolicy(policy string) (batchv1.ConcurrencyPolicy, error) {
|
||||
switch policy {
|
||||
case "Allow":
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/compose-spec/compose-go/v2/types"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/kubernetes/kompose/pkg/kobject"
|
||||
"github.com/pkg/errors"
|
||||
@@ -429,6 +429,52 @@ func TestLoadEnvVar(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseEnvFiles(t *testing.T) {
|
||||
tests := []struct {
|
||||
service types.ServiceConfig
|
||||
want []string
|
||||
}{
|
||||
{service: types.ServiceConfig{
|
||||
Name: "baz",
|
||||
Image: "foo/baz",
|
||||
EnvFiles: []types.EnvFile{
|
||||
{
|
||||
Path: "",
|
||||
Required: false,
|
||||
},
|
||||
{
|
||||
Path: "foo",
|
||||
Required: false,
|
||||
},
|
||||
{
|
||||
Path: "bar",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: []string{"", "foo", "bar"},
|
||||
},
|
||||
{
|
||||
service: types.ServiceConfig{
|
||||
Name: "baz",
|
||||
Image: "foo/baz",
|
||||
EnvFiles: []types.EnvFile{},
|
||||
},
|
||||
want: []string{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
sc := kobject.ServiceConfig{
|
||||
EnvFile: []string{},
|
||||
}
|
||||
parseEnvFiles(&tt.service, &sc)
|
||||
if !reflect.DeepEqual(sc.EnvFile, tt.want) {
|
||||
t.Errorf("Expected %q, got %q", tt.want, sc.EnvFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestUnsupportedKeys test checkUnsupportedKey function with various
|
||||
// docker-compose projects
|
||||
func TestUnsupportedKeys(t *testing.T) {
|
||||
@@ -441,7 +487,7 @@ func TestUnsupportedKeys(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Services: types.Services{
|
||||
types.ServiceConfig{
|
||||
"foo": types.ServiceConfig{
|
||||
Name: "foo",
|
||||
Image: "foo/bar",
|
||||
Build: &types.BuildConfig{
|
||||
@@ -453,7 +499,7 @@ func TestUnsupportedKeys(t *testing.T) {
|
||||
"net1": {},
|
||||
},
|
||||
},
|
||||
types.ServiceConfig{
|
||||
"bar": types.ServiceConfig{
|
||||
Name: "bar",
|
||||
Image: "bar/foo",
|
||||
Build: &types.BuildConfig{
|
||||
@@ -476,7 +522,7 @@ func TestUnsupportedKeys(t *testing.T) {
|
||||
|
||||
projectWithDefaultNetwork := &types.Project{
|
||||
Services: types.Services{
|
||||
types.ServiceConfig{
|
||||
"foo": types.ServiceConfig{
|
||||
Networks: map[string]*types.ServiceNetworkConfig{
|
||||
"default": {},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user