Skip to content
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
2 changes: 2 additions & 0 deletions .goreleaser-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ builds:
goos:
- linux
env:
- GOWORK=off
- CC=aarch64-linux-gnu-gcc
- CXX=aarch64-linux-gnu-g++
flags:
Expand All @@ -33,6 +34,7 @@ builds:
goos:
- linux
env:
- GOWORK=off
- CC=x86_64-linux-gnu-gcc
- CXX=x86_64-linux-gnu-g++
flags:
Expand Down
4 changes: 4 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ builds:
goos:
- darwin
env:
- GOWORK=off
- CC=oa64-clang
- CXX=oa64-clang++
flags:
Expand All @@ -32,6 +33,7 @@ builds:
goos:
- darwin
env:
- GOWORK=off
- CC=o64-clang
- CXX=o64-clang++
flags:
Expand All @@ -50,6 +52,7 @@ builds:
goos:
- linux
env:
- GOWORK=off
- CC=aarch64-linux-gnu-gcc
- CXX=aarch64-linux-gnu-g++
flags:
Expand All @@ -69,6 +72,7 @@ builds:
goos:
- linux
env:
- GOWORK=off
- CC=x86_64-linux-gnu-gcc
- CXX=x86_64-linux-gnu-g++
flags:
Expand Down
2 changes: 1 addition & 1 deletion _run/kube/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ there may be a problem.

| Option | __t1 Step: 1__ | Explanation |
|---------------------------------------------------|------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Map random local port to port 80 of your workload | `make kind-cluster-setup` | This is less error-prone, but makes it difficult to access your app through the browser. |
| Map random local port to port 80 of your workload | `GOWORK=off make kind-cluster-setup` | This is less error-prone, but makes it difficult to access your app through the browser. |
| Map localhost port 80 to workload | `KIND_CONFIG=kind-config-80.yaml make kind-cluster-create` | If anything else is listening on port 80 (any other web server), this method will fail. If it does succeed, you will be able to browse your app from the browser. |

## Build Akash binaries and initialize network
Expand Down
6 changes: 5 additions & 1 deletion _run/kube/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ profiles:
resources:
cpu:
units: 0.1
attributes:
arch:
- arm64
- amd64
memory:
size: 16Mi
storage:
Expand All @@ -52,4 +56,4 @@ deployment:
bew:
westcoast:
profile: web
count: 1
count: 1
3 changes: 2 additions & 1 deletion _run/kube/provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ attributes:
value: ram
- key: capabilities/storage/3/persistent
value: false

- key: capabilities/cpu/arch/arm64
value: true
1 change: 1 addition & 0 deletions cluster/kube/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
AkashNetworkStorageClasses = "akash.network/storageclasses"
AkashServiceTarget = "akash.network/service-target"
AkashServiceCapabilityGPU = "akash.network/capabilities.gpu"
AkashServiceCapabilityCPU = "akash.network/capabilities.cpu"
AkashServiceCapabilityStorage = "akash.network/capabilities.storage"
AkashMetalLB = "metal-lb"
akashDeploymentPolicyName = "akash-deployment-restrictions"
Expand Down
40 changes: 38 additions & 2 deletions cluster/kube/operators/clients/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (inv *inventory) tryAdjust(node int, res *types.Resources) (*crd.SchedulerP
nd := inv.Nodes[node].Dup()
sparams := &crd.SchedulerParams{}

if !tryAdjustCPU(&nd.Resources.CPU.Quantity, res.CPU) {
if !tryAdjustCPU(&nd.Resources.CPU.Quantity, res.CPU, nd.Resources.CPU.Info) {
return nil, false, true
}

Expand Down Expand Up @@ -117,7 +117,43 @@ func (inv *inventory) tryAdjust(node int, res *types.Resources) (*crd.SchedulerP
return sparams, true, true
}

func tryAdjustCPU(rp *inventoryV1.ResourcePair, res *types.CPU) bool {
func tryAdjustCPU(rp *inventoryV1.ResourcePair, res *types.CPU, nodeCPUInfo inventoryV1.CPUInfoS) bool {
// Parse CPU attributes if present
if len(res.Attributes) > 0 {
attrs, err := cinventory.ParseCPUAttributes(res.Attributes)
if err != nil {
return false
}

// Check if CPU architecture requirements are specified
if cpuAttrs, exists := attrs["cpu"]; exists && len(cpuAttrs.Architectures) > 0 {
// Check if the node supports any of the requested architectures
supported := false
for _, requestedArch := range cpuAttrs.Architectures {
// For now, we'll use a simple heuristic based on CPU model
// In a real implementation, you would have actual architecture info
for _, cpuInfo := range nodeCPUInfo {
nodeArch := "amd64" // Default
if strings.Contains(strings.ToLower(cpuInfo.Model), "arm") {
nodeArch = "arm64"
}

if requestedArch == nodeArch || requestedArch == "*" {
supported = true
break
}
}
if supported {
break
}
}

if !supported {
return false
}
}
}

return rp.SubMilliNLZ(res.Units)
}

Expand Down
40 changes: 38 additions & 2 deletions cluster/types/v1beta3/clients/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (inv *inventory) tryAdjust(node int, res *types.Resources) (*crd.SchedulerP
nd := inv.Nodes[node].Dup()
sparams := &crd.SchedulerParams{}

if !tryAdjustCPU(&nd.Resources.CPU.Quantity, res.CPU) {
if !tryAdjustCPU(&nd.Resources.CPU.Quantity, res.CPU, nd.Resources.CPU.Info) {
return nil, false, true
}

Expand Down Expand Up @@ -356,7 +356,43 @@ func (inv *inventory) tryAdjust(node int, res *types.Resources) (*crd.SchedulerP
return sparams, true, true
}

func tryAdjustCPU(rp *inventoryV1.ResourcePair, res *types.CPU) bool {
func tryAdjustCPU(rp *inventoryV1.ResourcePair, res *types.CPU, nodeCPUInfo inventoryV1.CPUInfoS) bool {
// Parse CPU attributes if present
if len(res.Attributes) > 0 {
attrs, err := ParseCPUAttributes(res.Attributes)
if err != nil {
return false
}

// Check if CPU architecture requirements are specified
if cpuAttrs, exists := attrs["cpu"]; exists && len(cpuAttrs.Architectures) > 0 {
// Check if the node supports any of the requested architectures
supported := false
for _, requestedArch := range cpuAttrs.Architectures {
// For now, we'll use a simple heuristic based on CPU model
// In a real implementation, you would have actual architecture info
for _, cpuInfo := range nodeCPUInfo {
nodeArch := "amd64" // Default
if strings.Contains(strings.ToLower(cpuInfo.Model), "arm") {
nodeArch = "arm64"
}

if requestedArch == nodeArch || requestedArch == "*" {
supported = true
break
}
}
if supported {
break
}
}

if !supported {
return false
}
}
}

return rp.SubMilliNLZ(res.Units)
}

Expand Down
127 changes: 127 additions & 0 deletions cluster/types/v1beta3/clients/inventory/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ type StorageAttributes struct {
Class string `json:"class,omitempty"`
}

type CPUArchitectureAttributes struct {
Architectures []string
}

type CPUAttributes map[string]*CPUArchitectureAttributes

func (m GPUModels) ExistsOrWildcard(model string) (*GPUModelAttributes, bool) {
attr, exists := m[model]
if exists {
Expand Down Expand Up @@ -133,3 +139,124 @@ func ParseStorageAttributes(attrs types.Attributes) (StorageAttributes, error) {

return res, nil
}

func ParseCPUAttributes(attrs types.Attributes) (CPUAttributes, error) {
cpuAttrs := make(CPUAttributes)

for _, attr := range attrs {
tokens := strings.Split(attr.Key, "/")
if len(tokens) < 3 {
return CPUAttributes{}, fmt.Errorf("invalid CPU attribute") // nolint: err113
}

switch tokens[0] {
case "capabilities":
default:
return CPUAttributes{}, fmt.Errorf("unexpected CPU attribute type (%s)", tokens[0]) // nolint: err113
}

switch tokens[1] {
case "cpu":
default:
return CPUAttributes{}, fmt.Errorf("unexpected CPU attribute type (%s)", tokens[1]) // nolint: err113
}

switch tokens[2] {
case "arch":
default:
return CPUAttributes{}, fmt.Errorf("unexpected CPU attribute type (%s)", tokens[2]) // nolint: err113
}

if len(tokens) < 4 {
return CPUAttributes{}, fmt.Errorf("invalid CPU architecture attribute") // nolint: err113
}

architecture := tokens[3]

// Check if the attribute value is "true" to indicate support
if attr.Value == "true" {
if cpuAttrs["cpu"] == nil {
cpuAttrs["cpu"] = &CPUArchitectureAttributes{
Architectures: make([]string, 0),
}
}
cpuAttrs["cpu"].Architectures = append(cpuAttrs["cpu"].Architectures, architecture)
}
}

return cpuAttrs, nil
}

// ParseCPUAttributesFromSDL parses CPU architecture attributes from SDL format
// This supports the format: attributes: arch: [arm64, amd64]
func ParseCPUAttributesFromSDL(attrs map[string]interface{}) (CPUAttributes, error) {
cpuAttrs := make(CPUAttributes)

if archAttr, exists := attrs["arch"]; exists {
switch v := archAttr.(type) {
case []interface{}:
architectures := make([]string, 0, len(v))
for _, arch := range v {
if archStr, ok := arch.(string); ok {
architectures = append(architectures, archStr)
} else {
return CPUAttributes{}, fmt.Errorf("invalid architecture type in SDL") // nolint: err113
}
}
cpuAttrs["cpu"] = &CPUArchitectureAttributes{
Architectures: architectures,
}
case string:
// Single architecture as string
cpuAttrs["cpu"] = &CPUArchitectureAttributes{
Architectures: []string{v},
}
default:
return CPUAttributes{}, fmt.Errorf("invalid architecture format in SDL") // nolint: err113
}
}

return cpuAttrs, nil
}

func (c *CPUArchitectureAttributes) HasArchitecture(arch string) bool {
for _, supportedArch := range c.Architectures {
if supportedArch == arch || supportedArch == "*" {
return true
}
}
return false
}

// ConvertSDLCPUAttributesToKeyValue converts SDL format CPU attributes to key-value format
// This function handles the conversion from: attributes: arch: [arm64, amd64]
// To: attributes: [{key: "capabilities/cpu/arch/arm64", value: "true"}, {key: "capabilities/cpu/arch/amd64", value: "true"}]
func ConvertSDLCPUAttributesToKeyValue(sdlAttrs map[string]interface{}) (types.Attributes, error) {
var attrs types.Attributes

if archAttr, exists := sdlAttrs["arch"]; exists {
switch v := archAttr.(type) {
case []interface{}:
for _, arch := range v {
if archStr, ok := arch.(string); ok {
attrs = append(attrs, types.Attribute{
Key: fmt.Sprintf("capabilities/cpu/arch/%s", archStr),
Value: "true",
})
} else {
return nil, fmt.Errorf("invalid architecture type in SDL") // nolint: err113
}
}
case string:
// Single architecture as string
attrs = append(attrs, types.Attribute{
Key: fmt.Sprintf("capabilities/cpu/arch/%s", v),
Value: "true",
})
default:
return nil, fmt.Errorf("invalid architecture format in SDL") // nolint: err113
}
}

return attrs, nil
}
Loading
Loading