Skip to content
Closed
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
40 changes: 40 additions & 0 deletions sdl/_testdata/simple-arm64.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
version: "2.0"
services:
web:
image: nginx
expose:
- port: 80
accept:
- ahostname.com
to:
- global: true
- port: 12345
to:
- global: true
proto: udp
profiles:
compute:
web:
resources:
cpu:
units: "100m"
attributes:
arch: arm64
memory:
size: "128Mi"
storage:
- size: "1Gi"
placement:
westcoast:
attributes:
region: us-west
pricing:
web:
denom: uakt
amount: 50
deployment:
web:
westcoast:
profile: web
count: 1
27 changes: 18 additions & 9 deletions sdl/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,32 @@ func (sdl *v2CPUAttributes) UnmarshalYAML(node *yaml.Node) error {
var attr v2CPUAttributes

for i := 0; i+1 < len(node.Content); i += 2 {
var value string
switch node.Content[i].Value {
case "arch":
if err := node.Content[i+1].Decode(&value); err != nil {
return err
// Support both string and slice of strings
var archs []string
if node.Content[i+1].Kind == yaml.SequenceNode {
if err := node.Content[i+1].Decode(&archs); err != nil {
return err
}
} else {
var single string
if err := node.Content[i+1].Decode(&single); err != nil {
return err
}
archs = append(archs, single)
}
for _, value := range archs {
attr = append(attr, types.Attribute{
Key: fmt.Sprintf("capabilities/cpu/arch/%s", value),
Value: "true",
})
}
default:
return fmt.Errorf("unsupported cpu attribute \"%s\"", node.Content[i].Value)
}

attr = append(attr, types.Attribute{
Key: node.Content[i].Value,
Value: value,
})
}

// keys are unique in attributes parsed from sdl so don't need to use sort.SliceStable
sort.Slice(attr, func(i, j int) bool {
return attr[i].Key < attr[j].Key
})
Expand Down
40 changes: 38 additions & 2 deletions sdl/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,42 @@ attributes:
require.NoError(t, err)
require.Equal(t, cpuQuantity(100), p.Units)
require.Equal(t, 1, len(p.Attributes))
require.Equal(t, "arch", p.Attributes[0].Key)
require.Equal(t, "amd64", p.Attributes[0].Value)
require.Equal(t, "capabilities/cpu/arch/amd64", p.Attributes[0].Key)
require.Equal(t, "true", p.Attributes[0].Value)
}

func TestV2ResourceCPU_ARM64(t *testing.T) {
var stream = `
units: 0.5
attributes:
arch: arm64
`
var p v2ResourceCPU

err := yaml.Unmarshal([]byte(stream), &p)
require.NoError(t, err)
require.Equal(t, cpuQuantity(500), p.Units)
require.Equal(t, 1, len(p.Attributes))
require.Equal(t, "capabilities/cpu/arch/arm64", p.Attributes[0].Key)
require.Equal(t, "true", p.Attributes[0].Value)
}

func TestV2ResourceCPU_ArchSlice(t *testing.T) {
var stream = `
units: 1
attributes:
arch:
- amd64
- arm64
`
var p v2ResourceCPU

err := yaml.Unmarshal([]byte(stream), &p)
require.NoError(t, err)
require.Equal(t, cpuQuantity(1000), p.Units)
require.Equal(t, 2, len(p.Attributes))
require.Equal(t, "capabilities/cpu/arch/amd64", p.Attributes[0].Key)
require.Equal(t, "true", p.Attributes[0].Value)
require.Equal(t, "capabilities/cpu/arch/arm64", p.Attributes[1].Key)
require.Equal(t, "true", p.Attributes[1].Value)
}
127 changes: 127 additions & 0 deletions sdl/v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,3 +938,130 @@ func TestV2ParseStorageName(t *testing.T) {
},
}, mani.GetGroups()[0])
}

func TestV2ParseSimpleARM64(t *testing.T) {
sdl, err := ReadFile("./_testdata/simple-arm64.yaml")
require.NoError(t, err)

groups, err := sdl.DeploymentGroups()
require.NoError(t, err)
assert.Len(t, groups, 1)

group := groups[0]
assert.Len(t, group.GetResourceUnits(), 1)
assert.Len(t, group.Requirements.Attributes, 1)

assert.Equal(t, atypes.Attribute{
Key: "region",
Value: "us-west",
}, group.Requirements.Attributes[0])

assert.Len(t, group.GetResourceUnits(), 1)

assert.Equal(t, dtypes.ResourceUnit{
Count: 1,
Resources: atypes.Resources{
ID: 1,
CPU: &atypes.CPU{
Units: atypes.NewResourceValue(randCPU),
Attributes: atypes.Attributes{
{
Key: "capabilities/cpu/arch/arm64",
Value: "true",
},
},
},
GPU: &atypes.GPU{
Units: atypes.NewResourceValue(0),
},
Memory: &atypes.Memory{
Quantity: atypes.NewResourceValue(randMemory),
},
Storage: atypes.Volumes{
{
Name: "default",
Quantity: atypes.NewResourceValue(randStorage),
},
},
Endpoints: []atypes.Endpoint{
{
Kind: atypes.Endpoint_SHARED_HTTP,
},
{
Kind: atypes.Endpoint_RANDOM_PORT,
},
},
},
Price: AkashDecCoin(t, 50),
}, group.GetResourceUnits()[0])

mani, err := sdl.Manifest()
require.NoError(t, err)

assert.Len(t, mani.GetGroups(), 1)

expectedHosts := make([]string, 1)
expectedHosts[0] = "ahostname.com"
assert.Equal(t, manifest.Group{
Name: "westcoast",
Services: []manifest.Service{
{
Name: "web",
Image: "nginx",
Resources: atypes.Resources{
ID: 1,
CPU: &atypes.CPU{
Units: atypes.NewResourceValue(100),
Attributes: atypes.Attributes{
{
Key: "capabilities/cpu/arch/arm64",
Value: "true",
},
},
},
GPU: &atypes.GPU{
Units: atypes.NewResourceValue(0),
},
Memory: &atypes.Memory{
Quantity: atypes.NewResourceValue(128 * unit.Mi),
},
Storage: atypes.Volumes{
{
Name: "default",
Quantity: atypes.NewResourceValue(1 * unit.Gi),
},
},
Endpoints: []atypes.Endpoint{
{
Kind: atypes.Endpoint_SHARED_HTTP,
},
{
Kind: atypes.Endpoint_RANDOM_PORT,
},
},
},
Count: 1,
Expose: []manifest.ServiceExpose{
{Port: 80, Global: true, Proto: manifest.TCP, Hosts: expectedHosts,
HTTPOptions: manifest.ServiceExposeHTTPOptions{
MaxBodySize: 1048576,
ReadTimeout: 60000,
SendTimeout: 60000,
NextTries: 3,
NextTimeout: 0,
NextCases: []string{"error", "timeout"},
}},
{Port: 12345, Global: true, Proto: manifest.UDP,
HTTPOptions: manifest.ServiceExposeHTTPOptions{
MaxBodySize: 1048576,
ReadTimeout: 60000,
SendTimeout: 60000,
NextTries: 3,
NextTimeout: 0,
NextCases: []string{"error", "timeout"},
}},
},
},
},
}, mani.GetGroups()[0])
}
1 change: 1 addition & 0 deletions x/deployment/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func GetTxCmd(key string) *cobra.Command {
SuggestionsMinimumDistance: 2,
RunE: sdkclient.ValidateCmd,
}

cmd.AddCommand(
cmdCreate(key),
cmdUpdate(key),
Expand Down
Loading