Merge branch 'main' into feature-1635-with-labels

This commit is contained in:
jose luis
2024-04-22 13:47:24 +02:00
18 changed files with 1664 additions and 33 deletions
+12 -4
View File
@@ -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":
+50 -4
View File
@@ -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": {},
},
+8
View File
@@ -94,6 +94,14 @@ const (
LabelInitContainerImage = "kompose.init.containers.image"
// LabelInitContainerCommand defines commands
LabelInitContainerCommand = "kompose.init.containers.command"
// LabelHpaMinReplicas defines min pod replicas
LabelHpaMinReplicas = "kompose.hpa.replicas.min"
// LabelHpaMaxReplicas defines max pod replicas
LabelHpaMaxReplicas = "kompose.hpa.replicas.max"
// LabelHpaCpu defines scaling decisions based on CPU utilization
LabelHpaCPU = "kompose.hpa.cpu"
// LabelHpaMemory defines scaling decisions based on memory utilization
LabelHpaMemory = "kompose.hpa.memory"
// LabelNameOverride defines the override resource name
LabelNameOverride = "kompose.service.name_override"
)