Skip to content
Merged
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
8 changes: 4 additions & 4 deletions docs/full-stack-setup-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ Each component's PVC, Service, Ingress, and Deployment all share **one name**:

| Component | Port | Public URL | Mount | Storage | Notes |
| --- | --- | --- | --- | --- | --- |
| VTA | 8100 | `vta-{vta_name}.{domain}` | `/work/vta` | PVC 200Mi + **Vault** seed | reuses `vta_only`'s VTA resources + Vault path |
| Mediator | 7037 | `mediator-{vta_name}.{domain}` | `/work/mediator` | PVC 200Mi + **Vault** (`vault://`, kubernetes auth) | config + `fjall` message store on the PVC; no Redis/Valkey |
| DID Hosting daemon | 8534 | `dids-{vta_name}.{domain}` | `/work/dids` | PVC 200Mi + **Vault** (kubernetes auth) | standard (integrated) topology |
| VTC | 8200 | `vtc-{vtc_name}.{domain}` | `/work/vtc` | PVC 200Mi + **Vault** (kubernetes auth) | `Command`/`workingDir` set by the farm, same as the other three |
| VTA | 8100 | `vta-{vta_name}.{domain}` | `/work/vta` | PVC from Resource defaults (factory 200Mi) + **Vault** seed | reuses `vta_only`'s VTA resources + Vault path |
| Mediator | 7037 | `mediator-{vta_name}.{domain}` | `/work/mediator` | PVC from Resource defaults (factory 200Mi) + **Vault** (`vault://`, kubernetes auth) | config + `fjall` message store on the PVC; no Redis/Valkey |
| DID Hosting daemon | 8534 | `dids-{vta_name}.{domain}` | `/work/dids` | PVC from Resource defaults (factory 200Mi) + **Vault** (kubernetes auth) | standard (integrated) topology |
| VTC | 8200 | `vtc-{vtc_name}.{domain}` | `/work/vtc` | PVC from Resource defaults (factory 200Mi) + **Vault** (kubernetes auth) | `Command`/`workingDir` set by the farm, same as the other three |

Every component is one PVC + one Deployment + one Service + one Ingress, built on the
generic `ComponentJobSpec` / `ComponentDeploymentSpec` helpers — no per-component K8s
Expand Down
3 changes: 2 additions & 1 deletion docs/optional-trust-registry-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ distinguish opted-out stacks from five-component stacks and admit an add-on usin
its incremental cost. The working branch starts with a 10m CPU request, 64Mi
memory request, 256Mi memory limit, and 200Mi PVC. These are provisional factory
values, not measured production sizing. Validate them against expected records
and traffic in staging; memory defaults can be changed through the Farm UI.
and traffic in staging; compute and new-PVC defaults can be changed through the
Farm UI without resizing existing PVCs.

Back up the Registry PVC (records and credential) and the Vault identity cache. Extend deletion to the
registry Jobs, Deployment, Service, PVC, and session Vault prefix. Audit policies
Expand Down
2 changes: 1 addition & 1 deletion docs/vta-setup-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ served by the cluster-wide wildcard, which Traefik serves as **its default certi

| Resource | `vta_only` name | Purpose |
| --- | --- | --- |
| `PersistentVolumeClaim` | `vta-data-{sessionID}` | 200Mi RWO; persists `config.toml` + `data/vta/` into the Deployment |
| `PersistentVolumeClaim` | `vta-data-{sessionID}` | RWO, sized from the VTA Resource default (factory default 200Mi); persists `config.toml` + `data/vta/` into the Deployment |
| `ConfigMap` (setup input) | `vta-setup-{sessionID}` | holds the rendered `vta-setup.toml` |
| `Job` (setup) | `vta-setup-{sessionID}` | runs `vta setup --from …` |
| `Job` (provision) | `vta-provision-{sessionID}` | runs `vta import-did` (+ `did-mgmt servers add`) |
Expand Down
36 changes: 24 additions & 12 deletions internal/apidocs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,17 @@ components:
memory_limit: { type: string, example: 512Mi }
required: [cpu_request, cpu_limit, memory_request, memory_limit]

ResourceDefaultProfile:
allOf:
- $ref: "#/components/schemas/ResourceProfile"
- type: object
properties:
storage_size:
type: string
example: 200Mi
description: PVC size for newly created workloads. Existing PVCs are unchanged.
required: [storage_size]

ResourceDefaults:
type: object
required: [resources, factory_defaults]
Expand Down Expand Up @@ -290,10 +301,11 @@ components:
type: object
required: [mediator, vtc, vta, dids]
properties:
mediator: { $ref: "#/components/schemas/ResourceProfile" }
vtc: { $ref: "#/components/schemas/ResourceProfile" }
vta: { $ref: "#/components/schemas/ResourceProfile" }
dids: { $ref: "#/components/schemas/ResourceProfile" }
mediator: { $ref: "#/components/schemas/ResourceDefaultProfile" }
vtc: { $ref: "#/components/schemas/ResourceDefaultProfile" }
vta: { $ref: "#/components/schemas/ResourceDefaultProfile" }
dids: { $ref: "#/components/schemas/ResourceDefaultProfile" }
trust-registry: { $ref: "#/components/schemas/ResourceDefaultProfile" }

VtaAclEntry:
type: object
Expand Down Expand Up @@ -3050,7 +3062,7 @@ paths:

/api/v1/admin/resource-defaults:
get:
summary: Read saved and factory component memory defaults
summary: Read saved and factory component resource defaults
tags: [Admin]
security:
- CookieAuthAdmin: []
Expand All @@ -3064,14 +3076,13 @@ paths:
"403": { description: Insufficient role }
"500": { description: Could not read defaults }
put:
summary: Save component memory defaults
summary: Save component resource defaults
description: |
Saves the four core components and optionally Trust Registry memory defaults. Each request
and limit must be between 16Mi and 1Gi inclusive, with request <= limit.
Values are Kubernetes quantities. CPU settings are unchanged.
Saves CPU, memory, and PVC storage defaults for the four core components and optionally
Trust Registry. Storage must be between 200Mi and 2Gi. Values are Kubernetes quantities.
New deployments and subsequent capacity estimates read these settings;
existing Deployments are not updated or restarted. To restore factory
defaults, submit the memory fields from GET's factory_defaults.
existing Deployments and PVCs are not updated or restarted. To restore factory
defaults, submit the fields from GET's factory_defaults.
tags: [Admin]
security:
- CookieAuthAdmin: []
Expand All @@ -3089,13 +3100,14 @@ paths:
maxItems: 5
items:
type: object
required: [component, cpu_request, cpu_limit, memory_request, memory_limit]
required: [component, cpu_request, cpu_limit, memory_request, memory_limit, storage_size]
properties:
component: { type: string, enum: [mediator, vtc, vta, dids, trust-registry] }
cpu_request: { type: string, example: 25m }
cpu_limit: { type: string, example: 250m }
memory_request: { type: string, example: 16Mi }
memory_limit: { type: string, example: 64Mi }
storage_size: { type: string, example: 200Mi, description: "PVC size for newly created workloads only." }
responses:
"200":
description: Saved defaults
Expand Down
27 changes: 16 additions & 11 deletions internal/capacity/capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/ic3software/vtafarm-api/internal/k8s"
"github.com/ic3software/vtafarm-api/internal/resourceprofile"
"k8s.io/apimachinery/pkg/api/resource"
)

// Component is one pod of a session mode plus its PVC (StorageBytes 0 = no
Expand All @@ -33,40 +34,41 @@ const (
gi = int64(1) << 30
)

// CPU and memory planning costs use the provisioning resource profiles.
// Keep storage costs in sync with the PVC sizes (internal/k8s/setup_jobs.go and
// internal/setup/orchestrator_fullstack.go).
// CPU, memory, and storage planning costs use the same provisioning resource
// profiles as newly created workloads.
// CPU uses requests. Memory uses hard limits so a reported session count still
// fits if every new component grows to its configured ceiling.
var (
VtaOnly = Mode{Name: "vta_only", Components: []Component{
planningComponent(k8s.ComponentVTA, 200*mi),
planningComponent(k8s.ComponentVTA),
}}

// FullStack covers all four components — the VTC is always provisioned,
// so there is no lighter full-stack shape to plan for.
FullStack = Mode{Name: "full_stack", Components: []Component{
planningComponent(k8s.ComponentDids, 200*mi),
planningComponent(k8s.ComponentMediator, 200*mi),
planningComponent(k8s.ComponentVTA, 200*mi),
planningComponent(k8s.ComponentVTC, 200*mi),
planningComponent(k8s.ComponentDids),
planningComponent(k8s.ComponentMediator),
planningComponent(k8s.ComponentVTA),
planningComponent(k8s.ComponentVTC),
}}
)

var TrustRegistry = Mode{Name: "trust_registry", Components: []Component{planningComponent(k8s.ComponentTrustRegistry, 200*mi)}}
var TrustRegistry = Mode{Name: "trust_registry", Components: []Component{planningComponent(k8s.ComponentTrustRegistry)}}

func FullStackWithRegistry() Mode {
components := slices.Clone(FullStack.Components)
return Mode{Name: "full_stack_registry", Components: append(components, TrustRegistry.Components...)}
}

func planningComponent(name string, storageBytes int64) Component {
func planningComponent(name string) Component {
resources := k8s.DefaultResourceRequirements(name)
profile := resourceprofile.Factory()[name]
storage := resource.MustParse(profile.StorageSize)
return Component{
Name: name,
CPUMillis: resources.Requests.Cpu().MilliValue(),
MemBytes: resources.Limits.Memory().Value(),
StorageBytes: storageBytes,
StorageBytes: storage.Value(),
}
}

Expand All @@ -77,9 +79,12 @@ func Modes(profiles resourceprofile.Profiles) []Mode {
modes[i].Components = slices.Clone(modes[i].Components)
for j := range modes[i].Components {
comp := &modes[i].Components[j]
profile := profiles[comp.Name]
resources := profiles.Requirements(comp.Name)
storage := resource.MustParse(profile.StorageSize)
comp.CPUMillis = resources.Requests.Cpu().MilliValue()
comp.MemBytes = resources.Limits.Memory().Value()
comp.StorageBytes = storage.Value()
}
}
return modes
Expand Down
4 changes: 4 additions & 0 deletions internal/capacity/capacity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func TestModesUseCurrentProfiles(t *testing.T) {
profile := profiles["vta"]
profile.CPURequest = "100m"
profile.MemoryLimit = "1Gi"
profile.StorageSize = "2Gi"
profiles["vta"] = profile
after := Modes(profiles)
if before[0].Components[0].MemBytes != 64*mi || after[0].Components[0].MemBytes != gi {
Expand All @@ -183,6 +184,9 @@ func TestModesUseCurrentProfiles(t *testing.T) {
if before[0].Components[0].CPUMillis != 10 || after[0].Components[0].CPUMillis != 100 {
t.Fatalf("CPU planning did not refresh costs: before=%+v after=%+v", before, after)
}
if before[0].Components[0].StorageBytes != 200*mi || after[0].Components[0].StorageBytes != 2*gi {
t.Fatalf("storage planning did not refresh costs: before=%+v after=%+v", before, after)
}
if VtaOnly.Components[0].MemBytes != 64*mi {
t.Fatal("factory mode was mutated")
}
Expand Down
11 changes: 9 additions & 2 deletions internal/handler/resource_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func (h *SetupHandler) AdminSaveResourceDefaults(c *gin.Context) {
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": err.Error()})
return
}
for _, item := range input.Resources {
if item.StorageSize == "" {
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": "storage_size is required for every component"})
return
}
}
for _, required := range []string{"vta", "mediator", "dids", "vtc"} {
found := false
for _, item := range input.Resources {
Expand All @@ -57,17 +63,18 @@ func (h *SetupHandler) AdminSaveResourceDefaults(c *gin.Context) {
}
rows = append(rows, model.ResourceDefault{
Component: component, CPURequest: item.CPURequest, CPULimit: item.CPULimit,
MemoryRequest: item.MemoryRequest, MemoryLimit: item.MemoryLimit,
MemoryRequest: item.MemoryRequest, MemoryLimit: item.MemoryLimit, StorageSize: item.StorageSize,
})
profile := profiles[component]
profile.CPURequest, profile.CPULimit = item.CPURequest, item.CPULimit
profile.MemoryRequest, profile.MemoryLimit = item.MemoryRequest, item.MemoryLimit
profile.StorageSize = item.StorageSize
profiles[component] = profile
}
}
if err := h.db.WithContext(c.Request.Context()).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "component"}},
DoUpdates: clause.AssignmentColumns([]string{"cpu_request", "cpu_limit", "memory_request", "memory_limit", "updated_at"}),
DoUpdates: clause.AssignmentColumns([]string{"cpu_request", "cpu_limit", "memory_request", "memory_limit", "storage_size", "updated_at"}),
}).Create(&rows).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "could not save resource defaults"})
return
Expand Down
13 changes: 13 additions & 0 deletions internal/handler/resource_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestResourceDefaultsPersistence(t *testing.T) {
testResourceInput("vta", "16Mi", "1Gi"),
testResourceInput("dids", "64Mi", "128Mi"),
}
inputs[2].StorageSize = "2Gi"
encode := func() string {
b, err := json.Marshal(map[string]any{"resources": inputs})
if err != nil {
Expand All @@ -97,12 +98,18 @@ func TestResourceDefaultsPersistence(t *testing.T) {
if saved["vta"].MemoryLimit != "1Gi" || read()["vta"].MemoryLimit != "1Gi" {
t.Fatal("saved defaults were not reloaded")
}
if saved["vta"].StorageSize != "2Gi" || read()["vta"].StorageSize != "2Gi" {
t.Fatal("saved storage default was not reloaded")
}
if saved["trust-registry"].MemoryRequest != "128Mi" || saved["trust-registry"].MemoryLimit != "512Mi" || read()["trust-registry"].MemoryLimit != "512Mi" {
t.Fatal("saved Trust Registry defaults were not reloaded")
}
if capacity.Modes(saved)[0].Components[0].MemBytes != 1<<30 {
t.Fatal("capacity did not use saved defaults")
}
if capacity.Modes(saved)[0].Components[0].StorageBytes != 2<<30 {
t.Fatal("capacity did not use saved storage default")
}
if saved["mediator"].CPURequest != "50m" {
t.Fatal("CPU changed")
}
Expand All @@ -112,6 +119,8 @@ func TestResourceDefaultsPersistence(t *testing.T) {
testResourceInput("dids", "256Mi", "64Mi"),
{Component: "vta", CPURequest: "250m", CPULimit: "100m", MemoryRequest: "16Mi", MemoryLimit: "64Mi"},
{Component: "unknown", CPURequest: "10m", CPULimit: "100m", MemoryRequest: "16Mi", MemoryLimit: "64Mi"},
{Component: "dids", CPURequest: "10m", CPULimit: "100m", MemoryRequest: "64Mi", MemoryLimit: "128Mi", StorageSize: "199Mi"},
{Component: "dids", CPURequest: "10m", CPULimit: "100m", MemoryRequest: "64Mi", MemoryLimit: "128Mi", StorageSize: "3Gi"},
} {
inputs[2].MemoryLimit = "64Mi"
inputs[3] = invalid
Expand All @@ -121,10 +130,14 @@ func TestResourceDefaultsPersistence(t *testing.T) {
}
}
inputs[3] = testResourceInput("dids", "64Mi", "128Mi")
inputs[2].StorageSize = resourceprofile.FactoryStorageSize
request(http.MethodPut, encode(), http.StatusOK)
if read()["vta"].MemoryLimit != "64Mi" {
t.Fatal("factory restore failed")
}
if read()["vta"].StorageSize != resourceprofile.FactoryStorageSize {
t.Fatal("factory storage restore failed")
}
down, err := os.ReadFile("../../migrations/000038_resource_defaults.down.sql")
if err != nil {
t.Fatal(err)
Expand Down
6 changes: 4 additions & 2 deletions internal/handler/setup_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type adminSessionResourceDefault struct {
CPULimit string `json:"cpu_limit"`
MemoryRequest string `json:"memory_request"`
MemoryLimit string `json:"memory_limit"`
StorageSize string `json:"storage_size"`
}

type adminSessionQueryItem struct {
Expand Down Expand Up @@ -207,7 +208,8 @@ SELECT
'cpu_request', rd.cpu_request,
'cpu_limit', rd.cpu_limit,
'memory_request', rd.memory_request,
'memory_limit', rd.memory_limit
'memory_limit', rd.memory_limit,
'storage_size', rd.storage_size
) ORDER BY rd.component) FROM resource_defaults rd
), '[]'::jsonb) AS resource_defaults,
COALESCE((
Expand Down Expand Up @@ -242,7 +244,7 @@ SELECT
for i, item := range defaults {
defaultRows[i] = model.ResourceDefault{
Component: item.Component, CPURequest: item.CPURequest, CPULimit: item.CPULimit,
MemoryRequest: item.MemoryRequest, MemoryLimit: item.MemoryLimit,
MemoryRequest: item.MemoryRequest, MemoryLimit: item.MemoryLimit, StorageSize: item.StorageSize,
}
}
profiles, err := resourceprofile.FromRows(defaultRows)
Expand Down
10 changes: 9 additions & 1 deletion internal/handler/setup_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type workloadResourceInput struct {
CPULimit string `json:"cpu_limit" binding:"required"`
MemoryRequest string `json:"memory_request" binding:"required"`
MemoryLimit string `json:"memory_limit" binding:"required"`
StorageSize string `json:"storage_size,omitempty"`
}

type resourceBatchInput struct {
Expand Down Expand Up @@ -139,7 +140,7 @@ func (h *SetupHandler) AdminSessionResources(c *gin.Context) {
}
}

defaults := profiles[target.Component]
defaults := profiles[target.Component].ResourceProfile
status := "in_sync"
if !sameQuantity(storedResource.CPURequest, actual.CPURequest) ||
!sameQuantity(storedResource.CPULimit, actual.CPULimit) ||
Expand Down Expand Up @@ -431,6 +432,13 @@ func validateResourceInputs(resources []workloadResourceInput) error {
if err := k8s.ValidateMemorySettings(item.MemoryRequest, item.MemoryLimit); err != nil {
return fmt.Errorf("%s: %w", item.Component, err)
}
if item.StorageSize != "" {
if err := resourceprofile.ValidateStorageSize(item.StorageSize); err != nil {
return fmt.Errorf("%s: %w", item.Component, err)
}
storage, _ := resource.ParseQuantity(strings.TrimSpace(item.StorageSize))
item.StorageSize = storage.String()
}
cpuRequest, _ := resource.ParseQuantity(strings.TrimSpace(item.CPURequest))
cpuLimit, _ := resource.ParseQuantity(strings.TrimSpace(item.CPULimit))
request, _ := resource.ParseQuantity(strings.TrimSpace(item.MemoryRequest))
Expand Down
3 changes: 2 additions & 1 deletion internal/handler/setup_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/ic3software/vtafarm-api/internal/k8s"
"github.com/ic3software/vtafarm-api/internal/model"
"github.com/ic3software/vtafarm-api/internal/resourceprofile"
)

func TestValidateResourceBatch(t *testing.T) {
Expand Down Expand Up @@ -41,7 +42,7 @@ func testResourceInput(component, memoryRequest, memoryLimit string) workloadRes
profile, _ := k8s.DefaultResourceProfile(component)
return workloadResourceInput{
Component: component, CPURequest: profile.CPURequest, CPULimit: profile.CPULimit,
MemoryRequest: memoryRequest, MemoryLimit: memoryLimit,
MemoryRequest: memoryRequest, MemoryLimit: memoryLimit, StorageSize: resourceprofile.FactoryStorageSize,
}
}

Expand Down
Loading