Skip to content

Commit

Permalink
feat: upgraded score-go to 1.1.0 and call upgrade function
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Meier <[email protected]>
  • Loading branch information
astromechza committed Feb 26, 2024
1 parent c507418 commit 48d83d0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/compose-spec/compose-go v1.6.0
github.com/imdario/mergo v0.3.13
github.com/mitchellh/mapstructure v1.5.0
github.com/score-spec/score-go v1.0.3
github.com/score-spec/score-go v1.1.0
github.com/spf13/cobra v1.6.0
github.com/stretchr/testify v1.8.0
github.com/tidwall/sjson v1.2.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
github.com/score-spec/score-go v1.0.3 h1:wNbGcY5Ms4FRfr/qtRVP7fojU9HaDPYkTnzNu0N/ga8=
github.com/score-spec/score-go v1.0.3/go.mod h1:nt6TOq2Ld9SiH3Fd9NF8tiJ9L7S17OE3FNgCrSet5GQ=
github.com/score-spec/score-go v1.1.0 h1:63WM1u93NtGgMuPtVZ/UBfzg/BpYuY8sBquaL0BkrXU=
github.com/score-spec/score-go v1.1.0/go.mod h1:nt6TOq2Ld9SiH3Fd9NF8tiJ9L7S17OE3FNgCrSet5GQ=
github.com/spf13/cobra v1.6.0 h1:42a0n6jwCot1pUmomAp4T7DeMD+20LFv4Q54pxLf2LI=
github.com/spf13/cobra v1.6.0/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down
13 changes: 11 additions & 2 deletions internal/command/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (

"github.com/score-spec/score-compose/internal/compose"

loader "github.com/score-spec/score-go/loader"
schema "github.com/score-spec/score-go/schema"
"github.com/score-spec/score-go/loader"
"github.com/score-spec/score-go/schema"
score "github.com/score-spec/score-go/types"
)

Expand Down Expand Up @@ -146,6 +146,15 @@ func run(cmd *cobra.Command, args []string) error {
}
}

// Apply upgrades to fix backports or backward incompatible things
if changes, err := schema.ApplyCommonUpgradeTransforms(srcMap); err != nil {
return fmt.Errorf("failed to upgrade spec: %w", err)
} else if len(changes) > 0 {
for _, change := range changes {
log.Printf("Applying upgrade to specification: %s\n", change)
}
}

// Validate SCORE spec
//
if !skipValidation {
Expand Down
6 changes: 5 additions & 1 deletion internal/compose/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ func ConvertSpec(spec *score.Workload) (*compose.Project, ExternalVariables, err
ports = []compose.ServicePortConfig{}
for _, pSpec := range spec.Service.Ports {
var pubPort = fmt.Sprintf("%v", pSpec.Port)
var protocol = score.ServicePortProtocolTCP
if pSpec.Protocol != nil {
protocol = *pSpec.Protocol
}
ports = append(ports, compose.ServicePortConfig{
Published: pubPort,
Target: uint32(DerefOr(pSpec.TargetPort, pSpec.Port)),
Protocol: DerefOr(pSpec.Protocol, ""),
Protocol: string(protocol),
})
}
}
Expand Down
9 changes: 5 additions & 4 deletions internal/compose/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestScoreConvert(t *testing.T) {
},
"admin": score.ServicePort{
Port: 8080,
Protocol: Ref("udp"),
Protocol: Ref(score.ServicePortProtocolUDP),
},
},
},
Expand Down Expand Up @@ -83,11 +83,12 @@ func TestScoreConvert(t *testing.T) {
{
Published: "80",
Target: 8080,
Protocol: "TCP",
},
{
Published: "8080",
Target: 8080,
Protocol: "udp",
Protocol: "UDP",
},
},
},
Expand Down Expand Up @@ -199,8 +200,8 @@ func TestScoreConvert(t *testing.T) {
"PORT": stringPtr("81"),
},
Ports: []compose.ServicePortConfig{
{Target: 80, Published: "8080"},
{Target: 81, Published: "8081"},
{Target: 80, Published: "8080", Protocol: "TCP"},
{Target: 81, Published: "8081", Protocol: "TCP"},
},
},
{
Expand Down

0 comments on commit 48d83d0

Please sign in to comment.