provider

package
v0.0.0-...-119c5e1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 1 Imported by: 0

README

Provider package

This package defines the cloud provider interface and common types for GPU instance provisioning.

Overview

The provider package provides:

  • A Provider interface for cloud-agnostic provisioning.
  • Common types for nodes, instance types, and requests.
  • An optional InstanceTypeLister interface for querying available types.

Provider interface

type Provider interface {
    Name() string
    Provision(ctx context.Context, req ProvisionRequest) (*Node, error)
    Terminate(ctx context.Context, nodeID string) error
    List(ctx context.Context) ([]*Node, error)
}
Method Description
Name() Returns the provider name (e.g., "lambda", "gcp", "aws")
Provision() Creates a new GPU instance
Terminate() Terminates an instance by ID
List() Lists all active instances

Types

Node

Represents a provisioned GPU instance:

type Node struct {
    ID           string            // Provider-assigned instance ID
    Provider     string            // Provider name
    Region       string            // Cloud region
    Zone         string            // Availability zone
    InstanceType string            // Instance type name
    Status       string            // provisioning, running, terminating, terminated
    IPAddress    string            // Public or private IP
    GPUCount     int               // Number of GPUs
    GPUType      string            // GPU model (e.g., "NVIDIA H100 80GB")
    Labels       map[string]string // User-defined labels
}
ProvisionRequest

Parameters for provisioning:

type ProvisionRequest struct {
    Name         string            // Instance name
    InstanceType string            // Instance type to launch
    Region       string            // Target region
    Zone         string            // Target zone (optional)
    SSHKeyNames  []string          // SSH keys to authorize
    Labels       map[string]string // Labels to apply
    UserData     string            // Startup script (cloud-init)
}
InstanceType

Describes an available instance type:

type InstanceType struct {
    Name       string   // Instance type name
    GPUCount   int      // Number of GPUs
    GPUType    string   // GPU model
    MemoryGB   int      // System memory
    VCPUs      int      // Virtual CPU count
    PricePerHr float64  // Price per hour in USD
    Regions    []string // Available regions
    Available  bool     // Current availability
}

InstanceTypeLister

Optional interface for providers that can list available types:

type InstanceTypeLister interface {
    ListInstanceTypes(ctx context.Context) ([]InstanceType, error)
}

Implementations

Provider Package Status
Lambda Labs pkg/provider/lambda Implemented
Google Cloud pkg/provider/gcp Implemented
AWS pkg/provider/aws Placeholder
Fake pkg/provider/fake For testing

Usage

import (
    "github.com/NavarchProject/navarch/pkg/provider"
    "github.com/NavarchProject/navarch/pkg/provider/lambda"
)

// Create a provider
lambdaProvider, err := lambda.New(lambda.Config{
    APIKey: os.Getenv("LAMBDA_API_KEY"),
})
if err != nil {
    log.Fatal(err)
}

// Provision a node
node, err := lambdaProvider.Provision(ctx, provider.ProvisionRequest{
    Name:         "training-node-1",
    InstanceType: "gpu_8x_h100_sxm5",
    Region:       "us-west-2",
    SSHKeyNames:  []string{"my-key"},
    Labels: map[string]string{
        "workload": "training",
    },
})
if err != nil {
    log.Fatal(err)
}

fmt.Printf("Provisioned: %s (%s)\n", node.ID, node.Status)

// List instances
nodes, err := lambdaProvider.List(ctx)
for _, n := range nodes {
    fmt.Printf("%s: %s (%d x %s)\n", n.ID, n.Status, n.GPUCount, n.GPUType)
}

// Terminate when done
err = lambdaProvider.Terminate(ctx, node.ID)

Multi-provider pools

Pools can use multiple providers for fungible compute. See pkg/pool for details on provider selection strategies (priority, cost, availability, round-robin).

pool, err := pool.NewWithOptions(pool.NewPoolOptions{
    Config: pool.Config{Name: "fungible"},
    Providers: []pool.ProviderConfig{
        {Name: "lambda", Provider: lambdaProvider, Priority: 1},
        {Name: "gcp", Provider: gcpProvider, Priority: 2},
    },
    ProviderStrategy: "priority",
})

Implementing a provider

To add a new cloud provider:

  1. Create a package under pkg/provider/ (e.g., pkg/provider/azure).
  2. Implement the Provider interface.
  3. Optionally implement InstanceTypeLister for instance type discovery.
  4. Add configuration loading in pkg/config.
package azure

type Provider struct {
    // ...
}

func New(cfg Config) (*Provider, error) {
    // Initialize Azure client
}

func (p *Provider) Name() string {
    return "azure"
}

func (p *Provider) Provision(ctx context.Context, req provider.ProvisionRequest) (*provider.Node, error) {
    // Call Azure API to create VM
}

func (p *Provider) Terminate(ctx context.Context, nodeID string) error {
    // Call Azure API to delete VM
}

func (p *Provider) List(ctx context.Context) ([]*provider.Node, error) {
    // Call Azure API to list VMs
}

Testing

Use the fake provider for testing:

import "github.com/NavarchProject/navarch/pkg/provider/fake"

fp := fake.New(fake.Config{GPUCount: 8})

node, _ := fp.Provision(ctx, provider.ProvisionRequest{
    Name:         "test-node",
    InstanceType: "fake-8gpu",
})
// node.Status == "running"

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InstanceTypeMappings = map[string]map[string]string{
	"h100-8x": {
		"lambda": "gpu_8x_h100_sxm5",
		"gcp":    "a3-highgpu-8g",
		"aws":    "p5.48xlarge",
	},
	"h100-1x": {
		"lambda": "gpu_1x_h100_pcie",
		"gcp":    "a3-highgpu-1g",
		"aws":    "p5.xlarge",
	},
	"a100-8x": {
		"lambda": "gpu_8x_a100",
		"gcp":    "a2-highgpu-8g",
		"aws":    "p4d.24xlarge",
	},
	"a100-4x": {
		"lambda": "gpu_4x_a100",
		"gcp":    "a2-highgpu-4g",
		"aws":    "p4de.24xlarge",
	},
	"a100-1x": {
		"lambda": "gpu_1x_a100",
		"gcp":    "a2-highgpu-1g",
	},
	"a10-1x": {
		"lambda": "gpu_1x_a10",
		"gcp":    "g2-standard-4",
		"aws":    "g5.xlarge",
	},
	"l4-1x": {
		"gcp": "g2-standard-4",
		"aws": "g6.xlarge",
	},
}

InstanceTypeMappings maps abstract instance types to provider-specific type names. Key is the abstract type (e.g., "h100-8x"), value is a map of provider to concrete type.

Functions

func GetSupportedProviders

func GetSupportedProviders(abstractType string) []string

GetSupportedProviders returns which providers support an abstract type.

func IsAbstractType

func IsAbstractType(typeName string) bool

IsAbstractType checks if a type name is an abstract type with mappings.

func ResolveInstanceType

func ResolveInstanceType(abstractType, providerName string) string

ResolveInstanceType maps an abstract type to a provider-specific type. If the type is already provider-specific or not found in mappings, returns as-is.

Types

type AbstractType

type AbstractType struct {
	GPUCount int
	GPUModel string // h100, a100, l4, etc.
}

AbstractType represents a hardware specification independent of provider. Users can request "h100-8x" and Navarch maps it to provider-specific types.

type InstanceType

type InstanceType struct {
	Name       string   // Instance type name (e.g., "gpu_8x_h100_sxm5")
	GPUCount   int      // Number of GPUs
	GPUType    string   // GPU model description
	MemoryGB   int      // System memory in gigabytes
	VCPUs      int      // Virtual CPU count
	PricePerHr float64  // Price per hour in USD
	Regions    []string // Regions where this type is offered
	Available  bool     // True if capacity is currently available
}

InstanceType describes an available instance type from a provider.

type InstanceTypeLister

type InstanceTypeLister interface {
	ListInstanceTypes(ctx context.Context) ([]InstanceType, error)
}

InstanceTypeLister is an optional interface for providers that can list available types.

type Node

type Node struct {
	ID           string            // Provider-assigned instance ID
	Provider     string            // Provider name (e.g., "lambda", "gcp")
	Region       string            // Cloud region
	Zone         string            // Availability zone
	InstanceType string            // Instance type name
	Status       string            // Instance state: provisioning, running, terminating, terminated
	IPAddress    string            // Public or private IP address
	SSHPort      int               // SSH port (default: 22). Used by docker provider for port mapping.
	GPUCount     int               // Number of GPUs attached
	GPUType      string            // GPU model description (e.g., "NVIDIA H100 80GB")
	Labels       map[string]string // User-defined key-value labels
}

Node represents a provisioned GPU instance.

type Provider

type Provider interface {
	Name() string
	Provision(ctx context.Context, req ProvisionRequest) (*Node, error)
	Terminate(ctx context.Context, nodeID string) error
	List(ctx context.Context) ([]*Node, error)
}

Provider abstracts cloud-specific provisioning operations.

type ProvisionRequest

type ProvisionRequest struct {
	Name         string            // Instance name (may be used as hostname)
	InstanceType string            // Instance type to launch
	Region       string            // Target region
	Zone         string            // Target availability zone (optional)
	SSHKeyNames  []string          // SSH key names to authorize
	Labels       map[string]string // Labels to apply to the instance
	UserData     string            // Startup script (cloud-init format)
}

ProvisionRequest contains parameters for provisioning a node.

type SelfBootstrapping

type SelfBootstrapping interface {
	// SelfBootstraps returns true if the provider handles node agent installation.
	SelfBootstraps() bool
}

SelfBootstrapping is an optional interface for providers that manage node setup internally. When a provider implements this and returns true, the pool skips SSH bootstrap. Examples: fake provider (spawns agents directly), Kubernetes (uses init containers).

Directories

Path Synopsis
Package docker provides a container-based provider for integration testing.
Package docker provides a container-based provider for integration testing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL