1 Commits

Author SHA1 Message Date
1fa07c29e5 Work in progress on compose-go v2
As explained in #102, the compose-go package changes types and needs
massive changes.
This branches is OK for now, but needs some tests.
It MUST be quickly fixed to be integrated in main branch.
2024-12-28 19:37:51 +01:00
22 changed files with 77 additions and 64 deletions

View File

@@ -13,7 +13,7 @@ import (
"os"
"strings"
"github.com/compose-spec/compose-go/cli"
"github.com/compose-spec/compose-go/v2/cli"
"github.com/spf13/cobra"
)

View File

@@ -10,7 +10,7 @@ import (
"path/filepath"
"strings"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
corev1 "k8s.io/api/core/v1"
)

View File

@@ -12,7 +12,7 @@ import (
"strings"
"unicode/utf8"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

View File

@@ -6,7 +6,7 @@ import (
"os"
"testing"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
v1 "k8s.io/api/core/v1"
"sigs.k8s.io/yaml"
)

View File

@@ -18,7 +18,7 @@ import (
"strings"
"time"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
)
const ingressClassHelp = `# Default value for ingress.class annotation

View File

@@ -7,7 +7,7 @@ import (
"log"
"strings"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

View File

@@ -12,7 +12,7 @@ import (
"strings"
"time"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

View File

@@ -9,7 +9,7 @@ import (
"regexp"
"strings"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
corev1 "k8s.io/api/core/v1"
)

View File

@@ -7,7 +7,7 @@ import (
"log"
"strings"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
networkv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

View File

@@ -12,7 +12,7 @@ import (
"reflect"
"strings"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
"github.com/invopop/jsonschema"
"gopkg.in/yaml.v3"
)
@@ -72,27 +72,29 @@ func OverrideWithConfig(project *types.Project) {
}
for i, p := range project.Services {
name := p.Name
if project.Services[i].Labels == nil {
project.Services[i].Labels = make(map[string]string)
if p.Labels == nil {
p.Labels = make(map[string]string)
project.Services[i] = p
}
if s, ok := services[name]; ok {
getLabelContent(s.MainApp, &project.Services[i], labels.LabelMainApp)
getLabelContent(s.Values, &project.Services[i], labels.LabelValues)
getLabelContent(s.Secrets, &project.Services[i], labels.LabelSecrets)
getLabelContent(s.Ports, &project.Services[i], labels.LabelPorts)
getLabelContent(s.Ingress, &project.Services[i], labels.LabelIngress)
getLabelContent(s.HealthCheck, &project.Services[i], labels.LabelHealthCheck)
getLabelContent(s.SamePod, &project.Services[i], labels.LabelSamePod)
getLabelContent(s.Description, &project.Services[i], labels.LabelDescription)
getLabelContent(s.Ignore, &project.Services[i], labels.LabelIgnore)
getLabelContent(s.Dependencies, &project.Services[i], labels.LabelDependencies)
getLabelContent(s.ConfigMapFile, &project.Services[i], labels.LabelConfigMapFiles)
getLabelContent(s.MapEnv, &project.Services[i], labels.LabelMapEnv)
getLabelContent(s.CronJob, &project.Services[i], labels.LabelCronJob)
getLabelContent(s.EnvFrom, &project.Services[i], labels.LabelEnvFrom)
getLabelContent(s.ExchangeVolumes, &project.Services[i], labels.LabelExchangeVolume)
getLabelContent(s.ValuesFrom, &project.Services[i], labels.LabelValueFrom)
service := project.Services[i]
getLabelContent(s.MainApp, &service, labels.LabelMainApp)
getLabelContent(s.Values, &service, labels.LabelValues)
getLabelContent(s.Secrets, &service, labels.LabelSecrets)
getLabelContent(s.Ports, &service, labels.LabelPorts)
getLabelContent(s.Ingress, &service, labels.LabelIngress)
getLabelContent(s.HealthCheck, &service, labels.LabelHealthCheck)
getLabelContent(s.SamePod, &service, labels.LabelSamePod)
getLabelContent(s.Description, &service, labels.LabelDescription)
getLabelContent(s.Ignore, &service, labels.LabelIgnore)
getLabelContent(s.Dependencies, &service, labels.LabelDependencies)
getLabelContent(s.ConfigMapFile, &service, labels.LabelConfigMapFiles)
getLabelContent(s.MapEnv, &service, labels.LabelMapEnv)
getLabelContent(s.CronJob, &service, labels.LabelCronJob)
getLabelContent(s.EnvFrom, &service, labels.LabelEnvFrom)
getLabelContent(s.ExchangeVolumes, &service, labels.LabelExchangeVolume)
getLabelContent(s.ValuesFrom, &service, labels.LabelValueFrom)
}
}
fmt.Println(utils.IconInfo, "Katenary file loaded successfully, the services are now configured.")
@@ -123,6 +125,9 @@ func getLabelContent(o any, service *types.ServiceConfig, labelName string) erro
val = strings.TrimSpace(string(c))
}
if service.Labels == nil {
service.Labels = make(map[string]string)
}
service.Labels[labelName] = val
return nil
}

View File

@@ -1,13 +1,14 @@
package katenaryfile
import (
"context"
"katenary/generator/labels"
"log"
"os"
"path/filepath"
"testing"
"github.com/compose-spec/compose-go/cli"
"github.com/compose-spec/compose-go/v2/cli"
)
func TestBuildSchema(t *testing.T) {
@@ -33,7 +34,7 @@ webapp:
// create /tmp/katenary-test-override directory, save the compose.yaml file
tmpDir, err := os.MkdirTemp("", "katenary-test-override")
if err != nil {
t.Fatalf(err.Error())
t.Fatal(err.Error())
}
composeFile := filepath.Join(tmpDir, "compose.yaml")
katenaryFile := filepath.Join(tmpDir, "katenary.yaml")
@@ -56,10 +57,13 @@ webapp:
cli.WithWorkingDirectory(tmpDir),
cli.WithDefaultConfigPath,
)
project, err := cli.ProjectFromOptions(options)
project, err := cli.ProjectFromOptions(context.TODO(), options)
if err != nil {
t.Fatal(err)
}
OverrideWithConfig(project)
w := project.Services[0].Labels
w := project.Services["webapp"].Labels
if v, ok := w[labels.LabelPorts]; !ok {
t.Fatal("Expected ports to be defined", v)
}
@@ -83,7 +87,7 @@ webapp:
// create /tmp/katenary-test-override directory, save the compose.yaml file
tmpDir, err := os.MkdirTemp("", "katenary-test-override")
if err != nil {
t.Fatalf(err.Error())
t.Fatal(err.Error())
}
composeFile := filepath.Join(tmpDir, "compose.yaml")
katenaryFile := filepath.Join(tmpDir, "katenary.yaml")
@@ -106,10 +110,14 @@ webapp:
cli.WithWorkingDirectory(tmpDir),
cli.WithDefaultConfigPath,
)
project, err := cli.ProjectFromOptions(options)
project, err := cli.ProjectFromOptions(context.TODO(), options)
if err != nil {
t.Fatal(err)
}
OverrideWithConfig(project)
w := project.Services[0].Labels
log.Println(project.Services["webapp"].Labels)
w := project.Services["webapp"].Labels
if v, ok := w[labels.LabelPorts]; !ok {
t.Fatal("Expected ports to be defined", v)
}

View File

@@ -3,7 +3,7 @@ package generator
import (
"katenary/utils"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

View File

@@ -6,7 +6,7 @@ import (
"katenary/utils"
"strings"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

View File

@@ -5,7 +5,7 @@ import (
"regexp"
"strings"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"

View File

@@ -8,7 +8,7 @@ import (
"strconv"
"strings"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/yaml"
)

View File

@@ -1,13 +1,14 @@
package generator
import (
"context"
"fmt"
"katenary/generator/labels"
"os"
"path/filepath"
"testing"
"github.com/compose-spec/compose-go/cli"
"github.com/compose-spec/compose-go/v2/cli"
)
func TestSplitPorts(t *testing.T) {
@@ -37,15 +38,18 @@ services:
cli.WithWorkingDirectory(tmpDir),
cli.WithDefaultConfigPath,
)
project, err := cli.ProjectFromOptions(options)
project, err := cli.ProjectFromOptions(context.TODO(), options)
if err != nil {
t.Fatal(err)
}
if err := fixPorts(&project.Services[0]); err != nil {
service := project.Services["foo"]
if err := fixPorts(&service); err != nil {
t.Errorf("Expected no error, got %s", err)
}
project.Services["foo"] = service
found := 0
for _, p := range project.Services[0].Ports {
t.Log(service.Ports, project.Services["foo"].Ports)
for _, p := range project.Services["foo"].Ports {
switch p.Target {
case 80, 443:
found++
@@ -85,15 +89,16 @@ services:
cli.WithWorkingDirectory(tmpDir),
cli.WithDefaultConfigPath,
)
project, err := cli.ProjectFromOptions(options)
project, err := cli.ProjectFromOptions(context.TODO(), options)
if err != nil {
t.Fatal(err)
}
if err := fixPorts(&project.Services[0]); err != nil {
service := project.Services["foo"]
if err := fixPorts(&service); err != nil {
t.Errorf("Expected no error, got %s", err)
}
found := 0
for _, p := range project.Services[0].Ports {
for _, p := range service.Ports {
switch p.Target {
case 80, 443, 8080:
found++

View File

@@ -3,7 +3,7 @@ package generator
import (
"strings"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
)
// RepositoryValue is a docker repository image and tag that will be saved in values.yaml.

View File

@@ -4,7 +4,7 @@ import (
"katenary/utils"
"strings"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

6
go.mod
View File

@@ -5,7 +5,7 @@ go 1.23.0
toolchain go1.23.4
require (
github.com/compose-spec/compose-go v1.20.2
github.com/compose-spec/compose-go/v2 v2.4.6
github.com/invopop/jsonschema v0.12.0
github.com/mitchellh/go-wordwrap v1.0.1
github.com/spf13/cobra v1.8.1
@@ -24,19 +24,17 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mattn/go-shellwords v1.0.12 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect

12
go.sum
View File

@@ -2,8 +2,8 @@ github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPn
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/compose-spec/compose-go v1.20.2 h1:u/yfZHn4EaHGdidrZycWpxXgFffjYULlTbRfJ51ykjQ=
github.com/compose-spec/compose-go v1.20.2/go.mod h1:+MdqXV4RA7wdFsahh/Kb8U0pAJqkg7mr4PM9tFKU8RM=
github.com/compose-spec/compose-go/v2 v2.4.6 h1:QiqXQ2L/f0OCbAl41bPpeiGAWVRIQ+GEDrYxO+dRPhQ=
github.com/compose-spec/compose-go/v2 v2.4.6/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -23,6 +23,8 @@ github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ4
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/go-viper/mapstructure/v2 v2.0.0 h1:dhn8MZ1gZ0mzeodTG3jt5Vj/o87xZKuNAprG2mQfMfc=
github.com/go-viper/mapstructure/v2 v2.0.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
@@ -33,8 +35,6 @@ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgYQBbFN4U4JNXUNYpxael3UzMyo=
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
@@ -53,8 +53,6 @@ github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebG
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -66,8 +64,6 @@ github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4=
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

View File

@@ -2,11 +2,12 @@
package parser
import (
"context"
"log"
"path/filepath"
"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"
)
func init() {
@@ -53,5 +54,5 @@ func Parse(profiles []string, envFiles []string, dockerComposeFile ...string) (*
if err != nil {
return nil, err
}
return cli.ProjectFromOptions(options)
return cli.ProjectFromOptions(context.TODO(), options)
}

View File

@@ -7,7 +7,7 @@ import (
"path/filepath"
"strings"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/compose-go/v2/types"
"github.com/mitchellh/go-wordwrap"
"github.com/thediveo/netdb"
"gopkg.in/yaml.v3"