Spot Go SDK

AI Tools

Overview

The Rackspace Spot Go SDK is an idiomatic Go client library for programmatically managing Rackspace Spot resources. It provides a clean, type-safe interface for automating your cloud infrastructure management.

GitHub Repository | Full Examples


Installation

Add the SDK to your Go project:

go get github.com/rackspace-spot/spot-go-sdk/api/v1

Then import it in your code:

import v1 "github.com/rackspace-spot/spot-go-sdk/api/v1"

Authentication

Obtaining a Refresh Token

  1. Navigate to Rackspace Spot API Access

  2. Generate or copy your Refresh Token

Creating a Client

Create a SpotClient with your refresh token:

package main import ( "context" "fmt" "log" v1 "github.com/rackspace-spot/spot-go-sdk/api/v1" ) func main() { // Initialize the Spot client spotClient, err := v1.NewSpotClient(&v1.Config{ RefreshToken: "<YOUR_REFRESH_TOKEN>", // Replace with Refresh Token or set in ENV }) if err != nil { log.Fatalf("Failed to create client: %v", err) } // Authenticate and obtain access token _, err = spotClient.Authenticate(context.Background()) if err != nil { log.Fatalf("Failed to authenticate: %v", err) } fmt.Println("Successfully authenticated!") }

Tip: Set SPOT_REFRESH_TOKEN as an environment variable instead of hardcoding it in your config.


Quick Start

List Available Regions

ctx := context.Background() regions, err := spotClient.ListRegions(ctx) if err != nil { log.Fatalf("Failed to list regions: %v", err) } fmt.Println("Available Regions:") for _, region := range regions { fmt.Printf(" - %s: %s\n", region.Name, region.Description) }

Create a Cloudspace (K8s Cluster)

ctx := context.Background() // Define a spot node pool with 3 workers spotPool := v1.SpotNodePool{ Name: "my-spot-pool", Org: "my-org", Cloudspace: "my-cluster", ServerClass: "ch.vs1.large-dfw", Desired: 3, BidPrice: "$0.08", CustomLabels: map[string]string{ "environment": "production", "team": "platform", }, } // Create the cloudspace with new nodepool err := spotClient.CreateCloudspace(ctx, v1.CloudSpace{ Name: "my-cluster", Org: "my-org", KubernetesVersion: "1.31.1", CNI: "calico", Region: "us-east-iad-1", SpotNodepools: []*v1.SpotNodePool{&spotPool}, }) if err != nil { log.Fatalf("Failed to create cloudspace: %v", err) } fmt.Println("Cloudspace created successfully!")

Query Market Pricing

ctx := context.Background() // Get pricing for a specific server class pricing, err := spotClient.GetPriceDetailsForServerClass(ctx, "ch.vs1.large-dfw") if err != nil { log.Fatalf("Failed to get pricing: %v", err) } fmt.Printf("Server Class: %s\n", pricing.ServerClassName) fmt.Printf("Current Market Price: %s/hour\n", pricing.MarketPrice) fmt.Printf("Region: %s\n", pricing.Region) fmt.Printf("CPU: %s | Memory: %s\n", pricing.CPU, pricing.Memory)

Full Example: See examples/main.go for a complete cloudspace lifecycle example.


API Reference

Authentication

Method

Description

Authenticate(ctx)

Authenticate with refresh token and obtain access token

Organizations

Method

Description

ListOrganizations(ctx)

List all organizations accessible to your account

Cloudspaces

Method

Description

CreateCloudspace(ctx, cloudspace)

Create a new Kubernetes cluster with node pools

ListCloudspaces(ctx, org)

List all cloudspaces in an organization

GetCloudspace(ctx, org, name)

Retrieve details of a specific cloudspace

GetCloudspaceConfig(ctx, org, name)

Download the kubeconfig for a cloudspace

DeleteCloudspace(ctx, org, name)

Delete a cloudspace and all associated resources

Spot Node Pools

Method

Description

CreateSpotNodePool(ctx, org, pool)

Add a new spot node pool to a cloudspace

ListSpotNodePools(ctx, org, cloudspace)

List all spot node pools in a cloudspace

GetSpotNodePool(ctx, org, name)

Get details of a specific spot node pool

UpdateSpotNodePool(ctx, org, pool)

Update spot node pool configuration

DeleteSpotNodePool(ctx, org, name)

Remove a spot node pool from a cloudspace

On-Demand Node Pools

Method

Description

CreateOnDemandNodePool(ctx, org, pool)

Add an on-demand node pool to a cloudspace

ListOnDemandNodePools(ctx, org, cloudspace)

List all on-demand node pools in a cloudspace

GetOnDemandNodePool(ctx, org, name)

Get details of an on-demand node pool

UpdateOnDemandNodePool(ctx, org, pool)

Update on-demand node pool configuration

DeleteOnDemandNodePool(ctx, org, name)

Remove an on-demand node pool

Regions

Method

Description

ListRegions(ctx)

List all available Rackspace Spot regions

GetRegion(ctx, name)

Get details about a specific region

Server Classes

Method

Description

ListServerClasses(ctx, region)

List all server classes available in a region

GetServerClass(ctx, name)

Get specifications for a server class

Pricing

Method

Description

GetPriceDetails(ctx)

Get pricing for all server classes

GetPriceDetailsForServerClass(ctx, serverClass)

Get pricing for a specific server class

GetPriceDetailsForRegion(ctx, region)

Get pricing for all server classes in a region

GetMarketPriceForServerClass(ctx, status)

Get current market price for a server class

GetMinimumBidPriceForServerClass(ctx, spec)

Get minimum acceptable bid price


Data Types

CloudSpace

type CloudSpace struct { Name string Org string KubernetesVersion string CNI string // "calico" or "cilium" Region string SpotNodepools []*SpotNodePool OnDemandNodePools []*OnDemandNodePool Status string APIServerEndpoint string PreemptionWebhookURL string }

SpotNodePool

type SpotNodePool struct { Name string Org string Cloudspace string ServerClass string Desired int BidPrice string // e.g., "$0.08" CustomAnnotations map[string]string CustomLabels map[string]string CustomTaints []interface{} Autoscaling struct { Enabled bool MinNodes int64 MaxNodes int64 } Status string WonCount int }

OnDemandNodePool

type OnDemandNodePool struct { Name string Org string Cloudspace string ServerClass string Desired int OnDemandPricePerHour string CustomAnnotations map[string]string CustomLabels map[string]string CustomTaints []interface{} Autoscaling struct { Enabled bool MinNodes int MaxNodes int } Status string WonCount int }

Contributing

This is an open source project. Contributions are welcome!

  1. Fork the repository

  2. Create a feature branch

  3. Make your changes with tests

  4. Submit a pull request

Report Issues


Resources

Support: For issues, open a GitHub issue. For security concerns, email product@rackspace.com.