feat: migrate from libcompose to compose-go (#1547)
* feat: migrate from libcompose to compose-go libcompose has been deprecated since summer 2021 in favor of https://github.com/compose-spec/compose-go. Kompose should now be able to load all versions of compose. * chore: replace golint with staticcheck golint has been deprecated. Recommended replacement is staticcheck.
This commit is contained in:
@@ -493,10 +493,8 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic
|
||||
}
|
||||
}
|
||||
|
||||
if cms != nil {
|
||||
for _, c := range cms {
|
||||
*objects = append(*objects, c)
|
||||
}
|
||||
for _, c := range cms {
|
||||
*objects = append(*objects, c)
|
||||
}
|
||||
|
||||
// Configure the container ports.
|
||||
@@ -724,8 +722,6 @@ func TranslatePodResource(service *kobject.ServiceConfig, template *api.PodTempl
|
||||
|
||||
template.Spec.Containers[0].Resources.Requests = resourceRequests
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetImagePullPolicy get image pull settings
|
||||
|
||||
@@ -39,8 +39,8 @@ func TestCreateService(t *testing.T) {
|
||||
service := kobject.ServiceConfig{
|
||||
ContainerName: "name",
|
||||
Image: "image",
|
||||
Environment: []kobject.EnvVar{kobject.EnvVar{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{kobject.Ports{HostPort: 123, ContainerPort: 456, Protocol: string(corev1.ProtocolTCP)}},
|
||||
Environment: []kobject.EnvVar{{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{{HostPort: 123, ContainerPort: 456, Protocol: string(corev1.ProtocolTCP)}},
|
||||
Command: []string{"cmd"},
|
||||
WorkingDir: "dir",
|
||||
Args: []string{"arg1", "arg2"},
|
||||
@@ -82,8 +82,8 @@ func TestCreateServiceWithMemLimit(t *testing.T) {
|
||||
service := kobject.ServiceConfig{
|
||||
ContainerName: "name",
|
||||
Image: "image",
|
||||
Environment: []kobject.EnvVar{kobject.EnvVar{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{kobject.Ports{HostPort: 123, ContainerPort: 456, Protocol: string(corev1.ProtocolTCP)}},
|
||||
Environment: []kobject.EnvVar{{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{{HostPort: 123, ContainerPort: 456, Protocol: string(corev1.ProtocolTCP)}},
|
||||
Command: []string{"cmd"},
|
||||
WorkingDir: "dir",
|
||||
Args: []string{"arg1", "arg2"},
|
||||
@@ -134,8 +134,8 @@ func TestCreateServiceWithCPULimit(t *testing.T) {
|
||||
service := kobject.ServiceConfig{
|
||||
ContainerName: "name",
|
||||
Image: "image",
|
||||
Environment: []kobject.EnvVar{kobject.EnvVar{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{kobject.Ports{HostPort: 123, ContainerPort: 456, Protocol: string(corev1.ProtocolTCP)}},
|
||||
Environment: []kobject.EnvVar{{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{{HostPort: 123, ContainerPort: 456, Protocol: string(corev1.ProtocolTCP)}},
|
||||
Command: []string{"cmd"},
|
||||
WorkingDir: "dir",
|
||||
Args: []string{"arg1", "arg2"},
|
||||
@@ -187,8 +187,8 @@ func TestCreateServiceWithServiceUser(t *testing.T) {
|
||||
service := kobject.ServiceConfig{
|
||||
ContainerName: "name",
|
||||
Image: "image",
|
||||
Environment: []kobject.EnvVar{kobject.EnvVar{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{kobject.Ports{HostPort: 123, ContainerPort: 456, Protocol: string(corev1.ProtocolTCP)}},
|
||||
Environment: []kobject.EnvVar{{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{{HostPort: 123, ContainerPort: 456, Protocol: string(corev1.ProtocolTCP)}},
|
||||
Command: []string{"cmd"},
|
||||
WorkingDir: "dir",
|
||||
Args: []string{"arg1", "arg2"},
|
||||
@@ -230,8 +230,8 @@ func TestTransformWithPid(t *testing.T) {
|
||||
service := kobject.ServiceConfig{
|
||||
ContainerName: "name",
|
||||
Image: "image",
|
||||
Environment: []kobject.EnvVar{kobject.EnvVar{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{kobject.Ports{HostPort: 123, ContainerPort: 456, Protocol: string(corev1.ProtocolTCP)}},
|
||||
Environment: []kobject.EnvVar{{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{{HostPort: 123, ContainerPort: 456, Protocol: string(corev1.ProtocolTCP)}},
|
||||
Command: []string{"cmd"},
|
||||
WorkingDir: "dir",
|
||||
Args: []string{"arg1", "arg2"},
|
||||
@@ -266,8 +266,8 @@ func TestTransformWithInvalidPid(t *testing.T) {
|
||||
service := kobject.ServiceConfig{
|
||||
ContainerName: "name",
|
||||
Image: "image",
|
||||
Environment: []kobject.EnvVar{kobject.EnvVar{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{kobject.Ports{HostPort: 123, ContainerPort: 456, Protocol: string(corev1.ProtocolTCP)}},
|
||||
Environment: []kobject.EnvVar{{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{{HostPort: 123, ContainerPort: 456, Protocol: string(corev1.ProtocolTCP)}},
|
||||
Command: []string{"cmd"},
|
||||
WorkingDir: "dir",
|
||||
Args: []string{"arg1", "arg2"},
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/cli/cli/compose/types"
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/fatih/structs"
|
||||
"github.com/kubernetes/kompose/pkg/kobject"
|
||||
"github.com/kubernetes/kompose/pkg/loader/compose"
|
||||
@@ -871,7 +871,7 @@ func (k *Kubernetes) getSecretPathsLegacy(secretConfig types.ServiceSecretConfig
|
||||
}
|
||||
|
||||
// if the target isn't absolute path
|
||||
if strings.HasPrefix(secretConfig.Target, "/") == false {
|
||||
if !strings.HasPrefix(secretConfig.Target, "/") {
|
||||
// concat the default secret directory
|
||||
mountPath = "/run/secrets/" + mountPath
|
||||
}
|
||||
@@ -1474,20 +1474,17 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
|
||||
SetVolumes(volumes),
|
||||
)
|
||||
|
||||
if pvc != nil {
|
||||
// Looping on the slice pvc instead of `*objects = append(*objects, pvc...)`
|
||||
// because the type of objects and pvc is different, but when doing append
|
||||
// one element at a time it gets converted to runtime.Object for objects slice
|
||||
for _, p := range pvc {
|
||||
objects = append(objects, p)
|
||||
}
|
||||
// Looping on the slice pvc instead of `*objects = append(*objects, pvc...)`
|
||||
// because the type of objects and pvc is different, but when doing append
|
||||
// one element at a time it gets converted to runtime.Object for objects slice
|
||||
for _, p := range pvc {
|
||||
objects = append(objects, p)
|
||||
}
|
||||
|
||||
if cms != nil {
|
||||
for _, c := range cms {
|
||||
objects = append(objects, c)
|
||||
}
|
||||
for _, c := range cms {
|
||||
objects = append(objects, c)
|
||||
}
|
||||
|
||||
podSpec.Append(
|
||||
SetPorts(service),
|
||||
ImagePullPolicy(name, service),
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
dockerCliTypes "github.com/docker/cli/cli/compose/types"
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
|
||||
"github.com/kubernetes/kompose/pkg/kobject"
|
||||
"github.com/kubernetes/kompose/pkg/loader/compose"
|
||||
@@ -43,8 +43,8 @@ func newServiceConfig() kobject.ServiceConfig {
|
||||
Name: "app",
|
||||
ContainerName: "name",
|
||||
Image: "image",
|
||||
Environment: []kobject.EnvVar{kobject.EnvVar{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{kobject.Ports{HostPort: 123, ContainerPort: 456}, kobject.Ports{HostPort: 123, ContainerPort: 456, Protocol: string(api.ProtocolUDP)}, kobject.Ports{HostPort: 55564, ContainerPort: 55564}, kobject.Ports{HostPort: 55563, ContainerPort: 55563}},
|
||||
Environment: []kobject.EnvVar{{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{{HostPort: 123, ContainerPort: 456}, {HostPort: 123, ContainerPort: 456, Protocol: string(api.ProtocolUDP)}, {HostPort: 55564, ContainerPort: 55564}, {HostPort: 55563, ContainerPort: 55563}},
|
||||
Command: []string{"cmd"},
|
||||
WorkingDir: "dir",
|
||||
Args: []string{"arg1", "arg2"},
|
||||
@@ -65,8 +65,8 @@ func newServiceConfig() kobject.ServiceConfig {
|
||||
Replicas: 2,
|
||||
Volumes: []kobject.Volumes{{SvcName: "app", MountPath: "/tmp/volume", PVCName: "app-claim0"}},
|
||||
GroupAdd: []int64{1003, 1005},
|
||||
Configs: []dockerCliTypes.ServiceConfigObjConfig{{Source: "config", Target: "/etc/world"}},
|
||||
ConfigsMetaData: map[string]dockerCliTypes.ConfigObjConfig{"config": dockerCliTypes.ConfigObjConfig{Name: "myconfig", File: "kubernetes_test.go"}},
|
||||
Configs: []types.ServiceConfigObjConfig{{Source: "config", Target: "/etc/world"}},
|
||||
ConfigsMetaData: types.Configs{"config": types.ConfigObjConfig{Name: "myconfig", File: "kubernetes_test.go"}},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -495,7 +495,7 @@ func TestKomposeConvert(t *testing.T) {
|
||||
if (int)(dc.Spec.Replicas) != replicas {
|
||||
t.Errorf("Expected %d replicas, got %d", replicas, dc.Spec.Replicas)
|
||||
}
|
||||
if len(dc.Spec.Selector) < 0 {
|
||||
if len(dc.Spec.Selector) == 0 {
|
||||
t.Errorf("Expect selector be set, got: %#v", dc.Spec.Selector)
|
||||
}
|
||||
foundDC = true
|
||||
@@ -529,8 +529,8 @@ func TestConvertRestartOptions(t *testing.T) {
|
||||
svc kobject.KomposeObject
|
||||
restartPolicy api.RestartPolicy
|
||||
}{
|
||||
"'restart' is set to 'no'": {kobject.KomposeObject{ServiceConfigs: map[string]kobject.ServiceConfig{"app": kobject.ServiceConfig{Image: "foobar", Restart: "no"}}}, api.RestartPolicyNever},
|
||||
"'restart' is set to 'on-failure'": {kobject.KomposeObject{ServiceConfigs: map[string]kobject.ServiceConfig{"app": kobject.ServiceConfig{Image: "foobar", Restart: "on-failure"}}}, api.RestartPolicyOnFailure},
|
||||
"'restart' is set to 'no'": {kobject.KomposeObject{ServiceConfigs: map[string]kobject.ServiceConfig{"app": {Image: "foobar", Restart: "no"}}}, api.RestartPolicyNever},
|
||||
"'restart' is set to 'on-failure'": {kobject.KomposeObject{ServiceConfigs: map[string]kobject.ServiceConfig{"app": {Image: "foobar", Restart: "on-failure"}}}, api.RestartPolicyOnFailure},
|
||||
}
|
||||
|
||||
for name, test := range testCases {
|
||||
|
||||
@@ -190,10 +190,10 @@ func (o *OpenShift) initDeploymentConfig(name string, service kobject.ServiceCon
|
||||
},
|
||||
Triggers: []deployapi.DeploymentTriggerPolicy{
|
||||
// Trigger new deploy when DeploymentConfig is created (config change)
|
||||
deployapi.DeploymentTriggerPolicy{
|
||||
{
|
||||
Type: deployapi.DeploymentTriggerOnConfigChange,
|
||||
},
|
||||
deployapi.DeploymentTriggerPolicy{
|
||||
{
|
||||
Type: deployapi.DeploymentTriggerOnImageChange,
|
||||
ImageChangeParams: &deployapi.DeploymentTriggerImageChangeParams{
|
||||
//Automatic - if new tag is detected - update image update inside the pod template
|
||||
|
||||
@@ -36,8 +36,8 @@ func newServiceConfig() kobject.ServiceConfig {
|
||||
return kobject.ServiceConfig{
|
||||
ContainerName: "myfoobarname",
|
||||
Image: "image",
|
||||
Environment: []kobject.EnvVar{kobject.EnvVar{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{kobject.Ports{HostPort: 123, ContainerPort: 456, Protocol: string(corev1.ProtocolTCP)}},
|
||||
Environment: []kobject.EnvVar{{Name: "env", Value: "value"}},
|
||||
Port: []kobject.Ports{{HostPort: 123, ContainerPort: 456, Protocol: string(corev1.ProtocolTCP)}},
|
||||
Command: []string{"cmd"},
|
||||
WorkingDir: "dir",
|
||||
Args: []string{"arg1", "arg2"},
|
||||
@@ -125,7 +125,7 @@ func TestKomposeConvertRoute(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
//Test getting git remote url for a directory
|
||||
// Test getting git remote url for a directory
|
||||
func TestGetGitRemote(t *testing.T) {
|
||||
var output string
|
||||
var err error
|
||||
|
||||
@@ -342,7 +342,7 @@ func GetComposeFileDir(inputFiles []string) (string, error) {
|
||||
return filepath.Dir(inputFile), nil
|
||||
}
|
||||
|
||||
//BuildDockerImage builds docker image
|
||||
// BuildDockerImage builds docker image
|
||||
func BuildDockerImage(service kobject.ServiceConfig, name string) error {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
|
||||
@@ -119,7 +119,7 @@ func TestParseWindowsVolumeMountLinuxContainer(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"container",
|
||||
fmt.Sprintf("%s", linuxContainer),
|
||||
linuxContainer,
|
||||
"",
|
||||
"",
|
||||
linuxContainer,
|
||||
@@ -214,7 +214,7 @@ func TestParseWindowsVolumeMountWindowsContainer(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"container",
|
||||
fmt.Sprintf("%s", windowsContainer),
|
||||
windowsContainer,
|
||||
"",
|
||||
"",
|
||||
windowsContainer,
|
||||
@@ -311,7 +311,7 @@ func TestParseVolume(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"container",
|
||||
fmt.Sprintf("%s", container2),
|
||||
container2,
|
||||
"",
|
||||
"",
|
||||
container2,
|
||||
|
||||
Reference in New Issue
Block a user