Skip to content

Commit bdae368

Browse files
rgarciaclaude
andcommitted
Add metadata field to instances for user-defined key-value pairs
Adds optional `metadata` map[string]string to instances, allowing callers to attach arbitrary key-value metadata at creation time. Stored alongside env vars in instance config and returned in GET /instances responses. Updated domain types, API layer, generated OAPI types, and OpenAPI spec. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e77731d commit bdae368

5 files changed

Lines changed: 38 additions & 3 deletions

File tree

cmd/api/api/instances.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ func (s *ApiService) CreateInstance(ctx context.Context, request oapi.CreateInst
111111
env = *request.Body.Env
112112
}
113113

114+
metadata := make(map[string]string)
115+
if request.Body.Metadata != nil {
116+
metadata = *request.Body.Metadata
117+
}
118+
114119
// Parse network enabled (default: true)
115120
networkEnabled := true
116121
if request.Body.Network != nil && request.Body.Network.Enabled != nil {
@@ -216,6 +221,7 @@ func (s *ApiService) CreateInstance(ctx context.Context, request oapi.CreateInst
216221
NetworkBandwidthDownload: networkBandwidthDownload,
217222
NetworkBandwidthUpload: networkBandwidthUpload,
218223
Env: env,
224+
Metadata: metadata,
219225
NetworkEnabled: networkEnabled,
220226
Devices: deviceRefs,
221227
Volumes: volumes,
@@ -666,6 +672,10 @@ func instanceToOAPI(inst instances.Instance) oapi.Instance {
666672
oapiInst.Env = &inst.Env
667673
}
668674

675+
if len(inst.Metadata) > 0 {
676+
oapiInst.Metadata = &inst.Metadata
677+
}
678+
669679
// Convert volume attachments
670680
if len(inst.Volumes) > 0 {
671681
oapiVolumes := make([]oapi.VolumeMount, len(inst.Volumes))

lib/instances/create.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ func (m *manager) createInstance(
192192
if req.Env == nil {
193193
req.Env = make(map[string]string)
194194
}
195+
if req.Metadata == nil {
196+
req.Metadata = make(map[string]string)
197+
}
195198

196199
// 7. Determine network based on NetworkEnabled flag
197200
networkName := ""
@@ -298,6 +301,7 @@ func (m *manager) createInstance(
298301
NetworkBandwidthUpload: req.NetworkBandwidthUpload, // Will be set by caller if using resource manager
299302
DiskIOBps: req.DiskIOBps, // Will be set by caller if using resource manager
300303
Env: req.Env,
304+
Metadata: req.Metadata,
301305
NetworkEnabled: req.NetworkEnabled,
302306
CreatedAt: time.Now(),
303307
StartedAt: nil,

lib/instances/types.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ type StoredMetadata struct {
4646

4747
// Configuration
4848
Env map[string]string
49-
NetworkEnabled bool // Whether instance has networking enabled (uses default network)
50-
IP string // Assigned IP address (empty if NetworkEnabled=false)
51-
MAC string // Assigned MAC address (empty if NetworkEnabled=false)
49+
Metadata map[string]string // User-defined key-value metadata
50+
NetworkEnabled bool // Whether instance has networking enabled (uses default network)
51+
IP string // Assigned IP address (empty if NetworkEnabled=false)
52+
MAC string // Assigned MAC address (empty if NetworkEnabled=false)
5253

5354
// Attached volumes
5455
Volumes []VolumeAttachment // Volumes attached to this instance
@@ -106,6 +107,7 @@ type CreateInstanceRequest struct {
106107
NetworkBandwidthUpload int64 // Upload rate limit bytes/sec (0 = auto, proportional to CPU)
107108
DiskIOBps int64 // Disk I/O rate limit bytes/sec (0 = auto, proportional to CPU)
108109
Env map[string]string // Optional environment variables
110+
Metadata map[string]string // Optional user-defined key-value metadata
109111
NetworkEnabled bool // Whether to enable networking (uses default network)
110112
Devices []string // Device IDs or names to attach (GPU passthrough)
111113
Volumes []VolumeAttachment // Volumes to attach at creation time

lib/oapi/oapi.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openapi.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ components:
144144
example:
145145
PORT: "3000"
146146
NODE_ENV: production
147+
metadata:
148+
type: object
149+
additionalProperties:
150+
type: string
151+
description: User-defined key-value metadata for the instance
152+
example:
153+
team: backend
154+
purpose: staging
147155
network:
148156
type: object
149157
description: Network configuration for the instance
@@ -227,6 +235,11 @@ components:
227235
additionalProperties:
228236
type: string
229237
description: Environment variables
238+
metadata:
239+
type: object
240+
additionalProperties:
241+
type: string
242+
description: User-defined key-value metadata
230243
network:
231244
type: object
232245
description: Network configuration of the instance

0 commit comments

Comments
 (0)