Skip to content

Commit

Permalink
feat: implement resource id and refactor sdl parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Jul 20, 2023
1 parent 23056a0 commit 6588466
Show file tree
Hide file tree
Showing 24 changed files with 991 additions and 456 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/akash-network/node
go 1.20

require (
github.com/akash-network/akash-api v0.0.23
github.com/akash-network/akash-api v0.0.24
github.com/blang/semver/v4 v4.0.0
github.com/boz/go-lifecycle v0.1.1
github.com/cosmos/cosmos-sdk v0.45.16
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBA
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/akash-network/akash-api v0.0.23 h1:zsu5ARReF7h8pD5jlBci3RpyJaahcvwI56IvNpR9+gE=
github.com/akash-network/akash-api v0.0.23/go.mod h1:9/uYusyBcZecBQCgZWUbXRu0i1tyxj4/ze45XB2oLIU=
github.com/akash-network/akash-api v0.0.24 h1:nIuftXhNI6w5oLjfncbb2BLxLEZvkwfxknbjYuFBI5M=
github.com/akash-network/akash-api v0.0.24/go.mod h1:9/uYusyBcZecBQCgZWUbXRu0i1tyxj4/ze45XB2oLIU=
github.com/akash-network/cometbft v0.34.27-akash h1:V1dApDOr8Ee7BJzYyQ7Z9VBtrAul4+baMeA6C49dje0=
github.com/akash-network/cometbft v0.34.27-akash/go.mod h1:BcCbhKv7ieM0KEddnYXvQZR+pZykTKReJJYf7YC7qhw=
github.com/akash-network/ledger-go v0.14.3 h1:LCEFkTfgGA2xFMN2CtiKvXKE7dh0QSM77PJHCpSkaAo=
Expand Down
80 changes: 80 additions & 0 deletions sdl/_testdata/service-mix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
version: "2.0"
services:
svca:
image: nginx
expose:
- port: 80
accept:
- ahostname.com
to:
- global: true
- port: 12345
to:
- global: true
proto: udp
svcb:
image: nginx
expose:
- port: 80
accept:
- bhostname.com
to:
- global: true
- port: 12346
to:
- global: true
proto: udp

profiles:
compute:
profilea:
resources:
cpu:
units: "100m"
gpu:
units: "1"
attributes:
vendor:
nvidia:
memory:
size: "128Mi"
storage:
- size: "1Gi"
profileb:
resources:
cpu:
units: "100m"
memory:
size: "128Mi"
storage:
- size: "1Gi"
placement:
westcoast:
attributes:
region: us-west
blalbla: foo
signedBy:
anyOf:
- 1
- 2
allOf:
- 3
- 4
pricing:
profilea:
denom: uakt
amount: 50
profileb:
denom: uakt
amount: 50

deployment:
svca:
westcoast:
profile: profilea
count: 1
svcb:
westcoast:
profile: profileb
count: 1
69 changes: 69 additions & 0 deletions sdl/_testdata/service-mix2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
version: "2.0"
services:
svca:
image: nginx
expose:
- port: 80
accept:
- ahostname.com
to:
- global: true
- port: 12345
to:
- global: true
proto: udp
svcb:
image: nginx
expose:
- port: 80
accept:
- bhostname.com
to:
- global: true
- port: 12346
to:
- global: true
proto: udp

profiles:
compute:
profilea:
resources:
cpu:
units: "100m"
gpu:
units: "1"
attributes:
vendor:
nvidia:
memory:
size: "128Mi"
storage:
- size: "1Gi"
placement:
westcoast:
attributes:
region: us-west
blalbla: foo
signedBy:
anyOf:
- 1
- 2
allOf:
- 3
- 4
pricing:
profilea:
denom: uakt
amount: 50

deployment:
svca:
westcoast:
profile: profilea
count: 1
svcb:
westcoast:
profile: profilea
count: 1
50 changes: 50 additions & 0 deletions sdl/_testdata/simple-with-ip.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
version: "2.0"
services:
web:
image: nginx
expose:
- port: 80
accept:
- ahostname.com
to:
- global: true
- port: 12345
to:
- global: true
ip: "meow"
proto: udp
profiles:
compute:
web:
resources:
cpu:
units: "100m"
memory:
size: "128Mi"
storage:
size: "1Gi"
placement:
westcoast:
attributes:
region: us-west
signedBy:
anyOf:
- 1
- 2
allOf:
- 3
- 4
pricing:
web:
denom: uakt
amount: 50
deployment:
web:
westcoast:
profile: web
count: 2

endpoints:
meow:
kind: "ip"
88 changes: 88 additions & 0 deletions sdl/expose.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sdl
import (
"net/url"

manifest "github.com/akash-network/akash-api/go/manifest/v2beta2"
"gopkg.in/yaml.v3"
)

Expand All @@ -23,5 +24,92 @@ func (p *v2Accept) UnmarshalYAML(node *yaml.Node) error {
}

p.Items = accept

return nil
}

func (sdl v2Exposes) toManifestExpose(endpointNames map[string]uint32) (manifest.ServiceExposes, error) {
exposeCount := 0
for _, expose := range sdl {
if len(expose.To) > 0 {
exposeCount += len(expose.To)
} else {
exposeCount++
}

Check warning on line 38 in sdl/expose.go

View check run for this annotation

Codecov / codecov/patch

sdl/expose.go#L37-L38

Added lines #L37 - L38 were not covered by tests
}

res := make([]manifest.ServiceExpose, 0, exposeCount)

for _, expose := range sdl {
exp, err := expose.toManifestExposes(endpointNames)
if err != nil {
return nil, err
}

Check warning on line 47 in sdl/expose.go

View check run for this annotation

Codecov / codecov/patch

sdl/expose.go#L46-L47

Added lines #L46 - L47 were not covered by tests

res = append(res, exp...)
}

return res, nil
}

func (sdl v2Expose) toManifestExposes(endpointNames map[string]uint32) (manifest.ServiceExposes, error) {
exposeCount := len(sdl.To)
if exposeCount == 0 {
exposeCount = 1
}

Check warning on line 59 in sdl/expose.go

View check run for this annotation

Codecov / codecov/patch

sdl/expose.go#L58-L59

Added lines #L58 - L59 were not covered by tests

res := make(manifest.ServiceExposes, 0, exposeCount)

proto, err := manifest.ParseServiceProtocol(sdl.Proto)
if err != nil {
return nil, err
}

Check warning on line 66 in sdl/expose.go

View check run for this annotation

Codecov / codecov/patch

sdl/expose.go#L65-L66

Added lines #L65 - L66 were not covered by tests

httpOptions, err := sdl.HTTPOptions.asManifest()
if err != nil {
return nil, err
}

Check warning on line 71 in sdl/expose.go

View check run for this annotation

Codecov / codecov/patch

sdl/expose.go#L70-L71

Added lines #L70 - L71 were not covered by tests

if len(sdl.To) > 0 {
for _, to := range sdl.To {
if !to.Global {
continue
}

// This value is created just so it can be passed to the utility function
expose := manifest.ServiceExpose{
Service: to.Service,
Port: sdl.Port,
ExternalPort: sdl.As,
Proto: proto,
Global: to.Global,
Hosts: sdl.Accept.Items,
HTTPOptions: httpOptions,
IP: to.IP,
}

// Check to see if an IP endpoint is also specified
if expose.Global && len(expose.IP) != 0 {
seqNo := endpointNames[expose.IP]
expose.EndpointSequenceNumber = seqNo
}

res = append(res, expose)
}
} else {
expose := manifest.ServiceExpose{
Service: "",
Port: sdl.Port,
ExternalPort: sdl.As,
Proto: proto,
Global: false,
Hosts: sdl.Accept.Items,
HTTPOptions: httpOptions,
IP: "",
}

res = append(res, expose)
}

Check warning on line 112 in sdl/expose.go

View check run for this annotation

Codecov / codecov/patch

sdl/expose.go#L99-L112

Added lines #L99 - L112 were not covered by tests

return res, nil
}
4 changes: 3 additions & 1 deletion sdl/gpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sdl

import (
"fmt"
"sort"

"gopkg.in/yaml.v3"

Expand Down Expand Up @@ -97,7 +98,8 @@ func (sdl *v2GPUAttributes) UnmarshalYAML(node *yaml.Node) error {
Value: "true",
})
}
res.Sort()

sort.Sort(res)

if err := res.Validate(); err != nil {
return fmt.Errorf("sdl: invalid GPU attributes: %w", err)
Expand Down
Loading

0 comments on commit 6588466

Please sign in to comment.