Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump compose-go to v2 #141

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.0
toolchain go1.22.7

require (
github.com/compose-spec/compose-go v1.20.2
github.com/compose-spec/compose-go/v2 v2.3.0
github.com/docker/go-units v0.5.0
github.com/joho/godotenv v1.5.1
github.com/sirupsen/logrus v1.9.3
Expand All @@ -26,18 +26,16 @@ require (
github.com/docker/go-connections v0.4.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/json-iterator/go v1.1.12 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mattn/go-shellwords v1.0.12 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/term v0.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/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
Expand Down
12 changes: 4 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
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.3.0 h1:5eomqgNcs/GqVknPtXF68V3muc67cOdXD35zCXn1aes=
github.com/compose-spec/compose-go/v2 v2.3.0/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -18,6 +18,8 @@ github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
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=
Expand All @@ -26,8 +28,6 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
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/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
Expand All @@ -42,8 +42,6 @@ github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhn
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
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/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand All @@ -53,8 +51,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
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=
Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"os"
"time"

composeLoader "github.com/compose-spec/compose-go/loader"
composeTypes "github.com/compose-spec/compose-go/types"
composeLoader "github.com/compose-spec/compose-go/v2/loader"
composeTypes "github.com/compose-spec/compose-go/v2/types"
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -68,7 +68,7 @@ func Main(args []string) int {
for _, shellEnvFile := range shellEnvFiles.Values {
err := godotenv.Load(shellEnvFile)
if err != nil {
logrus.Error(err)
logrus.Errorf("Loading dotfiles: %s", err)
return 1
}
}
Expand All @@ -91,9 +91,9 @@ func Main(args []string) int {
ConfigFiles: composeConfigFiles,
Environment: env,
}
project, err := composeLoader.Load(configDetails)
project, err := composeLoader.Load(configDetails, func(opts *composeLoader.Options) { opts.SetProjectName("k8ify", true) })
if err != nil {
logrus.Error(err)
logrus.Errorf("Loading compose configuration: %s", err)
return 1
}

Expand All @@ -117,7 +117,7 @@ func Main(args []string) int {

err = internal.WriteManifests(config.OutputDir, objects)
if err != nil {
logrus.Error(err)
logrus.Errorf("Writing manifests: %s", err)
return 1
}

Expand Down
11 changes: 5 additions & 6 deletions pkg/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
"os"
"os/exec"
"sort"
"strconv"
"strings"

composeTypes "github.com/compose-spec/compose-go/types"
composeTypes "github.com/compose-spec/compose-go/v2/types"
"github.com/sirupsen/logrus"
"github.com/vshn/k8ify/pkg/ir"
"github.com/vshn/k8ify/pkg/util"
Expand Down Expand Up @@ -602,8 +601,8 @@ func composeServiceToResourceRequirements(composeService composeTypes.ServiceCon
if composeService.Deploy != nil {
if composeService.Deploy.Resources.Reservations != nil {
// NanoCPU appears to be a misnomer, it's actually a float indicating the number of CPU cores, nothing 'nano'
cpuRequest, err := strconv.ParseFloat(composeService.Deploy.Resources.Reservations.NanoCPUs, 64)
if err == nil && cpuRequest > 0 {
cpuRequest := composeService.Deploy.Resources.Reservations.NanoCPUs
if cpuRequest > 0 {
requestsMap["cpu"] = resource.MustParse(fmt.Sprintf("%f", cpuRequest))
limitsMap["cpu"] = resource.MustParse(fmt.Sprintf("%f", cpuRequest*10.0))
}
Expand All @@ -616,8 +615,8 @@ func composeServiceToResourceRequirements(composeService composeTypes.ServiceCon
if composeService.Deploy.Resources.Limits != nil {
// If there are explicit limits configured we ignore the defaults calculated from the requests
limitsMap = core.ResourceList{}
cpuLimit, err := strconv.ParseFloat(composeService.Deploy.Resources.Limits.NanoCPUs, 64)
if err == nil && cpuLimit > 0 {
cpuLimit := composeService.Deploy.Resources.Limits.NanoCPUs
if cpuLimit > 0 {
limitsMap["cpu"] = resource.MustParse(fmt.Sprintf("%f", cpuLimit))
}
memLimit := composeService.Deploy.Resources.Limits.MemoryBytes
Expand Down
7 changes: 4 additions & 3 deletions pkg/ir/ir.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package ir

import (
composeTypes "github.com/compose-spec/compose-go/types"
"github.com/vshn/k8ify/pkg/util"
"k8s.io/apimachinery/pkg/api/resource"
"strconv"
"strings"

composeTypes "github.com/compose-spec/compose-go/v2/types"
"github.com/vshn/k8ify/pkg/util"
"k8s.io/apimachinery/pkg/api/resource"
)

type Inputs struct {
Expand Down
9 changes: 4 additions & 5 deletions tests/golden/demo/docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
version: '3.4'
services:
portal:
image: image-registry.openshift-image-registry.svc:5000/portal/portal:latest
deploy:
replicas: 2
resources:
reservations:
cpus: '0.1'
cpus: "0.1"
memory: 2G
labels:
k8ify.expose.8001: 'portal-k8ify.apps.cloudscale-lpg-2.appuio.cloud'
k8ify.expose.9001: 'portal-k8ify-admin.apps.cloudscale-lpg-2.appuio.cloud'
k8ify.expose.8001: "portal-k8ify.apps.cloudscale-lpg-2.appuio.cloud"
k8ify.expose.9001: "portal-k8ify-admin.apps.cloudscale-lpg-2.appuio.cloud"
k8ify.share-storage: true
k8ify.liveness.path: /health/alive
k8ify.readiness.path: /health/ready
Expand Down Expand Up @@ -40,7 +39,7 @@ services:
limits:
memory: 8G
reservations:
cpus: '0.5'
cpus: "0.5"
memory: 4G

volumes:
Expand Down
5 changes: 2 additions & 3 deletions tests/golden/demo/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
version: '3.4'
services:
mongo:
image: mongo:4.0
restart: always
ports:
- '127.0.0.1:27017:27017'
- "127.0.0.1:27017:27017"
volumes:
- mongodb_data:/data/db
portal:
Expand All @@ -20,7 +19,7 @@ services:
- "8001:8000"
volumes:
- ./:/src
entrypoint:
entrypoint:
- echo
command:
- "Hello World"
Expand Down
8 changes: 4 additions & 4 deletions tests/golden/demo/manifests/portal-oasp-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ spec:
failureThreshold: 3
httpGet:
path: /health/alive
port: 8000
port: 9000
scheme: HTTP
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 60
name: portal-oasp
ports:
- containerPort: 8000
- containerPort: 9000
- containerPort: 8000
readinessProbe:
failureThreshold: 4
httpGet:
path: /health/ready
port: 8000
port: 9000
scheme: HTTPS
initialDelaySeconds: 5
periodSeconds: 31
Expand All @@ -76,7 +76,7 @@ spec:
failureThreshold: 30
httpGet:
path: /health/started
port: 8000
port: 9000
scheme: HTTP
periodSeconds: 10
successThreshold: 1
Expand Down
12 changes: 6 additions & 6 deletions tests/golden/demo/manifests/portal-oasp-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ metadata:
name: portal-oasp
spec:
rules:
- host: portal-k8ify.apps.cloudscale-lpg-2.appuio.cloud
- host: portal-k8ify-admin.apps.cloudscale-lpg-2.appuio.cloud
http:
paths:
- backend:
service:
name: portal-oasp
port:
number: 8001
number: 9001
path: /
pathType: Prefix
- host: portal-k8ify-admin.apps.cloudscale-lpg-2.appuio.cloud
- host: portal-k8ify.apps.cloudscale-lpg-2.appuio.cloud
http:
paths:
- backend:
service:
name: portal-oasp
port:
number: 9001
number: 8001
path: /
pathType: Prefix
tls:
- hosts:
- portal-k8ify.apps.cloudscale-lpg-2.appuio.cloud
- portal-k8ify-admin.apps.cloudscale-lpg-2.appuio.cloud
secretName: portal-oasp
- hosts:
- portal-k8ify-admin.apps.cloudscale-lpg-2.appuio.cloud
- portal-k8ify.apps.cloudscale-lpg-2.appuio.cloud
secretName: portal-oasp
status:
loadBalancer: {}
6 changes: 3 additions & 3 deletions tests/golden/demo/manifests/portal-oasp-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ metadata:
name: portal-oasp
spec:
ports:
- name: "8001"
port: 8001
targetPort: 8000
- name: "9001"
port: 9001
targetPort: 9000
- name: "8001"
port: 8001
targetPort: 8000
selector:
k8ify.ref-slug: oasp
k8ify.service: portal
Expand Down
2 changes: 1 addition & 1 deletion tests/golden/empty-env-vars-list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
environments:
prod:
vars:
foo:
foo:
bar: ""
baz: asdf
2 changes: 0 additions & 2 deletions tests/golden/empty-env-vars-list/compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.4'
services:
pinger:
image: pinger:4.0
Expand All @@ -7,4 +6,3 @@ services:
- testempty2=$foo
- testempty3=$bar
- testnotempty=$baz

2 changes: 1 addition & 1 deletion tests/golden/empty-env-vars-map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
environments:
prod:
vars:
foo:
foo:
bar: ""
baz: asdf
2 changes: 0 additions & 2 deletions tests/golden/empty-env-vars-map/compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.4'
services:
pinger:
image: pinger:4.0
Expand All @@ -9,4 +8,3 @@ services:
testempty4:
testempty5: null
testnotempty: $baz

6 changes: 3 additions & 3 deletions tests/golden/env-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
environments:
test:
vars:
FOO : "one"
BAR : "two"
BAZ : "three"
FOO: "one"
BAR: "two"
BAZ: "three"
3 changes: 1 addition & 2 deletions tests/golden/external-converter/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
version: '3.4'
services:
mongo:
labels:
k8ify.annotations.abc: def
image: mongo:4
volumes:
- mongo-data:/var/lib/mongodb

volumes:
mongo-data:
labels:
Expand Down
1 change: 0 additions & 1 deletion tests/golden/noports/compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.4'
services:
pinger:
labels:
Expand Down
3 changes: 1 addition & 2 deletions tests/golden/parts-ingress/compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.4'
services:
nginx-frontend:
ports:
Expand All @@ -8,6 +7,6 @@ services:
image: php-backend:prod
labels:
k8ify.partOf: nginx-frontend
k8ify.expose: 'nginx-bypass.mywebapp.example.com'
k8ify.expose: "nginx-bypass.mywebapp.example.com"
ports:
- "1180-1190:4480"
Loading