From b1c5c940e47d72bf8e84bff97189e42fbbab081e Mon Sep 17 00:00:00 2001 From: mblos Date: Wed, 25 Mar 2026 11:54:05 +0100 Subject: [PATCH] commitment resources use new naming schema hw_version_$hw_version_ram --- .../api_change_commitments_monitor_test.go | 12 +-- .../api_change_commitments_test.go | 78 +++++++++---------- .../reservations/commitments/api_info.go | 2 +- .../reservations/commitments/api_info_test.go | 24 +++--- .../commitments/api_report_capacity_test.go | 4 +- .../commitments/api_report_usage_test.go | 22 +++--- .../reservations/commitments/capacity.go | 4 +- .../reservations/commitments/state.go | 24 +++++- .../reservations/commitments/state_test.go | 32 ++++++-- .../reservations/commitments/syncer.go | 7 +- .../reservations/commitments/syncer_test.go | 10 +-- .../reservations/commitments/usage.go | 2 +- .../reservations/commitments/usage_test.go | 10 +-- 13 files changed, 132 insertions(+), 99 deletions(-) diff --git a/internal/scheduling/reservations/commitments/api_change_commitments_monitor_test.go b/internal/scheduling/reservations/commitments/api_change_commitments_monitor_test.go index 255f05bd8..74fc0c938 100644 --- a/internal/scheduling/reservations/commitments/api_change_commitments_monitor_test.go +++ b/internal/scheduling/reservations/commitments/api_change_commitments_monitor_test.go @@ -172,24 +172,24 @@ func TestCountCommitments(t *testing.T) { { name: "Single commitment", request: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-1", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-1", "confirmed", 2), ), expected: 1, }, { name: "Multiple commitments same project", request: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-1", "confirmed", 2), - createCommitment("ram_hana_2", "project-A", "uuid-2", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-1", "confirmed", 2), + createCommitment("hw_version_hana_2_ram", "project-A", "uuid-2", "confirmed", 2), ), expected: 2, }, { name: "Multiple commitments multiple projects", request: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-1", "confirmed", 2), - createCommitment("ram_hana_1", "project-B", "uuid-2", "confirmed", 3), - createCommitment("ram_gp_1", "project-C", "uuid-3", "confirmed", 1), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-1", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-B", "uuid-2", "confirmed", 3), + createCommitment("hw_version_gp_1_ram", "project-C", "uuid-3", "confirmed", 1), ), expected: 3, }, diff --git a/internal/scheduling/reservations/commitments/api_change_commitments_test.go b/internal/scheduling/reservations/commitments/api_change_commitments_test.go index 6ceb8b65f..a30db33c5 100644 --- a/internal/scheduling/reservations/commitments/api_change_commitments_test.go +++ b/internal/scheduling/reservations/commitments/api_change_commitments_test.go @@ -55,7 +55,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { {CommitmentID: "uuid-123", Host: "host-2", Flavor: m1Small, ProjectID: "project-A"}, {CommitmentID: "uuid-123", Host: "host-3", Flavor: m1Small, ProjectID: "project-A"}, }, - CommitmentRequest: newCommitmentRequest("az-a", false, 1234, createCommitment("ram_hana_1", "project-A", "uuid-123", "confirmed", 2)), + CommitmentRequest: newCommitmentRequest("az-a", false, 1234, createCommitment("hw_version_hana_1_ram", "project-A", "uuid-123", "confirmed", 2)), ExpectedReservations: []*TestReservation{ {CommitmentID: "uuid-123", Host: "host-1", Flavor: m1Small, ProjectID: "project-A", VMs: []string{"vm-a1"}}, {CommitmentID: "uuid-123", Host: "host-3", Flavor: m1Small, ProjectID: "project-A"}, @@ -67,7 +67,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { VMs: []*TestVM{}, Flavors: []*TestFlavor{m1Small}, ExistingReservations: []*TestReservation{{CommitmentID: "uuid-456", Host: "host-1", Flavor: m1Small, ProjectID: "project-A"}}, - CommitmentRequest: newCommitmentRequest("az-a", false, 1234, createCommitment("ram_hana_1", "project-A", "uuid-456", "confirmed", 3)), + CommitmentRequest: newCommitmentRequest("az-a", false, 1234, createCommitment("hw_version_hana_1_ram", "project-A", "uuid-456", "confirmed", 3)), AvailableResources: &AvailableResources{PerHost: map[string]int64{"host-1": 1024, "host-2": 0}}, ExpectedReservations: []*TestReservation{{CommitmentID: "uuid-456", Host: "host-1", Flavor: m1Small, ProjectID: "project-A"}}, ExpectedAPIResponse: newAPIResponse("1 commitment(s) failed", "commitment uuid-456: not sufficient capacity"), @@ -78,7 +78,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { Flavors: []*TestFlavor{m1Small}, ExistingReservations: []*TestReservation{}, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", strings.Repeat("long-", 13), "confirmed", 3), + createCommitment("hw_version_hana_1_ram", "project-A", strings.Repeat("long-", 13), "confirmed", 3), ), AvailableResources: &AvailableResources{}, ExpectedReservations: []*TestReservation{}, @@ -90,7 +90,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { Flavors: []*TestFlavor{m1Small}, ExistingReservations: []*TestReservation{}, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid with space", "confirmed", 3), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid with space", "confirmed", 3), ), AvailableResources: &AvailableResources{}, ExpectedReservations: []*TestReservation{}, @@ -103,8 +103,8 @@ func TestCommitmentChangeIntegration(t *testing.T) { {CommitmentID: "uuid-456", Host: "host-1", Flavor: m1Small, ProjectID: "project-A"}, {CommitmentID: "uuid-456", Host: "host-2", Flavor: m1Small, ProjectID: "project-A"}}, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-456", "confirmed", 0), - createCommitment("ram_hana_1", "project-B", "uuid-123", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-456", "confirmed", 0), + createCommitment("hw_version_hana_1_ram", "project-B", "uuid-123", "confirmed", 2), ), AvailableResources: &AvailableResources{PerHost: map[string]int64{"host-1": 0, "host-2": 0}}, ExpectedReservations: []*TestReservation{ @@ -119,8 +119,8 @@ func TestCommitmentChangeIntegration(t *testing.T) { {CommitmentID: "uuid-123", Host: "host-1", Flavor: m1Small, ProjectID: "project-B"}, {CommitmentID: "uuid-123", Host: "host-2", Flavor: m1Small, ProjectID: "project-B"}}, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-456", "confirmed", 2), - createCommitment("ram_hana_1", "project-B", "uuid-123", "confirmed", 0), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-456", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-B", "uuid-123", "confirmed", 0), ), AvailableResources: &AvailableResources{PerHost: map[string]int64{"host-1": 0, "host-2": 0}}, ExpectedReservations: []*TestReservation{ @@ -133,7 +133,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { // Greedy selection: 10GB request with 8/4/1GB flavors → picks 1×8GB + 2×1GB Flavors: []*TestFlavor{m1XL, m1Large, m1Small}, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-binpack", "confirmed", 10), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-binpack", "confirmed", 10), ), ExpectedReservations: []*TestReservation{ {CommitmentID: "uuid-binpack", Flavor: m1XL, ProjectID: "project-A"}, @@ -147,7 +147,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { // InfoVersion validation prevents stale requests (1233 vs 1234) Flavors: []*TestFlavor{m1Small}, CommitmentRequest: newCommitmentRequest("az-a", false, 1233, - createCommitment("ram_hana_1", "project-A", "uuid-version", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-version", "confirmed", 2), ), EnvInfoVersion: 1234, ExpectedReservations: []*TestReservation{}, @@ -161,8 +161,8 @@ func TestCommitmentChangeIntegration(t *testing.T) { {CommitmentID: "uuid-project-a", Host: "host-1", Flavor: m1Small, ProjectID: "project-A"}, }, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-project-a", "confirmed", 2), - createCommitment("ram_hana_1", "project-B", "uuid-project-b", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-project-a", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-B", "uuid-project-b", "confirmed", 2), ), AvailableResources: &AvailableResources{PerHost: map[string]int64{"host-1": 1024, "host-2": 0}}, ExpectedReservations: []*TestReservation{ @@ -180,8 +180,8 @@ func TestCommitmentChangeIntegration(t *testing.T) { {CommitmentID: "commitment-A", Host: "host-1", Flavor: m1Small, ProjectID: "project-A"}, }, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "commitment-A", "confirmed", 0), - createCommitment("ram_hana_1", "project-B", "commitment-B", "confirmed", 6), + createCommitment("hw_version_hana_1_ram", "project-A", "commitment-A", "confirmed", 0), + createCommitment("hw_version_hana_1_ram", "project-B", "commitment-B", "confirmed", 6), ), AvailableResources: &AvailableResources{PerHost: map[string]int64{"host-1": 0}}, ExpectedReservations: []*TestReservation{ @@ -195,7 +195,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { Name: "New commitment creation - from zero to N reservations", Flavors: []*TestFlavor{m1Small}, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-new", "confirmed", 3), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-new", "confirmed", 3), ), ExpectedReservations: []*TestReservation{ {CommitmentID: "uuid-new", Flavor: m1Small, ProjectID: "project-A"}, @@ -208,7 +208,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { Name: "New commitment creation - large batch", Flavors: []*TestFlavor{m1Small}, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-new", "confirmed", 200), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-new", "confirmed", 200), ), ExpectedReservations: func() []*TestReservation { var reservations []*TestReservation @@ -232,7 +232,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { {CommitmentID: "uuid-custom", Host: "host-2", Flavor: m1Small, ProjectID: "project-A", MemoryMB: 2048}, }, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-custom", "confirmed", 4), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-custom", "confirmed", 4), ), ExpectedReservations: []*TestReservation{ {CommitmentID: "uuid-custom", Host: "host-1", Flavor: m1Small, ProjectID: "project-A", MemoryMB: 2048}, @@ -249,7 +249,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { {CommitmentID: "uuid-custom", Host: "host-2", Flavor: m1Small, ProjectID: "project-A", MemoryMB: 2048}, }, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-custom", "confirmed", 6), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-custom", "confirmed", 6), ), ExpectedReservations: []*TestReservation{ {CommitmentID: "uuid-custom", Host: "host-1", Flavor: m1Small, ProjectID: "project-A", MemoryMB: 2048}, @@ -268,7 +268,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { {CommitmentID: "uuid-custom", Host: "host-2", Flavor: m1Small, ProjectID: "project-A", MemoryMB: 2048}, }, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-custom", "confirmed", 3), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-custom", "confirmed", 3), ), ExpectedReservations: []*TestReservation{ {CommitmentID: "uuid-custom", Flavor: m1Small, ProjectID: "project-A", MemoryMB: 2048}, @@ -287,7 +287,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { {CommitmentID: "uuid-a-1", Host: "host-3", Flavor: m1Small, ProjectID: "project-A"}, }, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-delete", "confirmed", 0), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-delete", "confirmed", 0), ), ExpectedReservations: []*TestReservation{ {CommitmentID: "uuid-b-1", Host: "host-3", Flavor: m1Small, ProjectID: "project-B"}, @@ -304,7 +304,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { {CommitmentID: "uuid-growth", Host: "host-2", Flavor: m1Small, ProjectID: "project-A"}, }, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-growth", "confirmed", 3), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-growth", "confirmed", 3), ), ExpectedReservations: []*TestReservation{ {CommitmentID: "uuid-growth", Host: "host-1", Flavor: m1Small, ProjectID: "project-A", VMs: []string{"vm-existing"}}, @@ -317,8 +317,8 @@ func TestCommitmentChangeIntegration(t *testing.T) { Name: "Multi-project success - both projects succeed", Flavors: []*TestFlavor{m1Small}, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-a", "confirmed", 2), - createCommitment("ram_hana_1", "project-B", "uuid-b", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-a", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-B", "uuid-b", "confirmed", 2), ), ExpectedReservations: []*TestReservation{ {CommitmentID: "uuid-a", Flavor: m1Small, ProjectID: "project-A"}, @@ -329,15 +329,15 @@ func TestCommitmentChangeIntegration(t *testing.T) { ExpectedAPIResponse: newAPIResponse(), }, { - Name: "Multiple flavor groups - ram_hana_1 and ram_hana_2", + Name: "Multiple flavor groups - hw_version_hana_1_ram and hw_version_hana_2_ram", // Amount in multiples of smallest flavor: hana_1 (2×1GB), hana_2 (2×2GB) Flavors: []*TestFlavor{ m1Small, {Name: "m2.small", Group: "hana_2", MemoryMB: 2048, VCPUs: 8}, }, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-hana1", "confirmed", 2), - createCommitment("ram_hana_2", "project-A", "uuid-hana2", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-hana1", "confirmed", 2), + createCommitment("hw_version_hana_2_ram", "project-A", "uuid-hana2", "confirmed", 2), ), ExpectedReservations: []*TestReservation{ {CommitmentID: "uuid-hana1", Flavor: m1Small, ProjectID: "project-A"}, @@ -351,7 +351,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { Name: "Unknown flavor group - clear rejection message", Flavors: []*TestFlavor{m1Small}, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_nonexistent", "project-A", "uuid-unknown", "confirmed", 2), + createCommitment("hw_version_nonexistent_ram", "project-A", "uuid-unknown", "confirmed", 2), ), ExpectedReservations: []*TestReservation{}, ExpectedAPIResponse: newAPIResponse("flavor group not found"), @@ -366,9 +366,9 @@ func TestCommitmentChangeIntegration(t *testing.T) { {CommitmentID: "uuid-b", Host: "host-3", Flavor: m1Small, ProjectID: "project-B"}, }, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-a", "confirmed", 0), - createCommitment("ram_hana_1", "project-B", "uuid-b", "confirmed", 0), - createCommitment("ram_hana_1", "project-C", "uuid-c", "confirmed", 3), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-a", "confirmed", 0), + createCommitment("hw_version_hana_1_ram", "project-B", "uuid-b", "confirmed", 0), + createCommitment("hw_version_hana_1_ram", "project-C", "uuid-c", "confirmed", 3), ), AvailableResources: &AvailableResources{PerHost: map[string]int64{"host-1": 0, "host-2": 0, "host-3": 0}}, ExpectedReservations: []*TestReservation{ @@ -388,7 +388,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { {CommitmentID: "uuid-repair", Host: "host-4", Flavor: m1Small, ProjectID: "project-A", AZ: "wrong-az"}, }, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-repair", "confirmed", 8, "az-a"), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-repair", "confirmed", 8, "az-a"), ), ExpectedReservations: []*TestReservation{ {CommitmentID: "uuid-repair", Host: "host-preserved", Flavor: m1Small, ProjectID: "project-A", AZ: "az-a"}, @@ -410,7 +410,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { Name: "Dry run request - feature not yet implemented", Flavors: []*TestFlavor{m1Small}, CommitmentRequest: newCommitmentRequest("az-a", true, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-dryrun", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-dryrun", "confirmed", 2), ), ExpectedReservations: []*TestReservation{}, ExpectedAPIResponse: newAPIResponse("Dry run not supported"), @@ -419,7 +419,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { Name: "Knowledge not ready - clear rejection with RetryAt", Flavors: []*TestFlavor{m1Small}, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-knowledge", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-knowledge", "confirmed", 2), ), ExpectedReservations: []*TestReservation{}, ExpectedAPIResponse: APIResponseExpectation{ @@ -432,7 +432,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { Name: "API disabled - returns 503 Service Unavailable", Flavors: []*TestFlavor{m1Small}, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-disabled", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-disabled", "confirmed", 2), ), CustomConfig: func() *Config { cfg := DefaultConfig() @@ -449,9 +449,9 @@ func TestCommitmentChangeIntegration(t *testing.T) { // Tests that multiple failed commitments are all mentioned in the rejection reason Flavors: []*TestFlavor{m1Small, m1Tiny}, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-multi-fail-1", "confirmed", 3), - createCommitment("ram_hana_1", "project-B", "uuid-multi-fail-2", "confirmed", 3), - createCommitment("ram_gp_1", "project-C", "uuid-would-not-fail", "confirmed", 1), // would be rolled back, but not part of the reject reason + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-multi-fail-1", "confirmed", 3), + createCommitment("hw_version_hana_1_ram", "project-B", "uuid-multi-fail-2", "confirmed", 3), + createCommitment("hw_version_gp_1_ram", "project-C", "uuid-would-not-fail", "confirmed", 1), // would be rolled back, but not part of the reject reason ), AvailableResources: &AvailableResources{PerHost: map[string]int64{"host-1": 256}}, ExpectedReservations: []*TestReservation{}, @@ -470,7 +470,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { {CommitmentID: "commitment-1", Host: "host-2", Flavor: m1Small, ProjectID: "project-A"}, }, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "commitment-1", "confirmed", 4), + createCommitment("hw_version_hana_1_ram", "project-A", "commitment-1", "confirmed", 4), ), AvailableResources: &AvailableResources{PerHost: map[string]int64{"host-1": 0, "host-2": 1024}}, ExpectedReservations: []*TestReservation{ @@ -485,7 +485,7 @@ func TestCommitmentChangeIntegration(t *testing.T) { Name: "Watch timeout with custom config - triggers rollback with timeout error", Flavors: []*TestFlavor{m1Small}, CommitmentRequest: newCommitmentRequest("az-a", false, 1234, - createCommitment("ram_hana_1", "project-A", "uuid-timeout", "confirmed", 2), + createCommitment("hw_version_hana_1_ram", "project-A", "uuid-timeout", "confirmed", 2), ), // With 0ms timeout, the watch will timeout immediately before reservations become ready CustomConfig: func() *Config { diff --git a/internal/scheduling/reservations/commitments/api_info.go b/internal/scheduling/reservations/commitments/api_info.go index 7c8c72748..d25235d99 100644 --- a/internal/scheduling/reservations/commitments/api_info.go +++ b/internal/scheduling/reservations/commitments/api_info.go @@ -107,7 +107,7 @@ func (api *HTTPAPI) buildServiceInfo(ctx context.Context, logger logr.Logger) (l // Build resources map resources := make(map[liquid.ResourceName]liquid.ResourceInfo) for groupName, groupData := range flavorGroups { - resourceName := liquid.ResourceName(commitmentResourceNamePrefix + groupName) + resourceName := liquid.ResourceName(ResourceNameFromFlavorGroup(groupName)) flavorNames := make([]string, 0, len(groupData.Flavors)) for _, flavor := range groupData.Flavors { diff --git a/internal/scheduling/reservations/commitments/api_info_test.go b/internal/scheduling/reservations/commitments/api_info_test.go index 4f42cd2a2..846d4c279 100644 --- a/internal/scheduling/reservations/commitments/api_info_test.go +++ b/internal/scheduling/reservations/commitments/api_info_test.go @@ -218,38 +218,38 @@ func TestHandleInfo_HasCapacityEqualsHandlesCommitments(t *testing.T) { t.Fatalf("expected 2 resources, got %d", len(serviceInfo.Resources)) } - // Test fixed ratio group: ram_hana_fixed - fixedResource, ok := serviceInfo.Resources["ram_hana_fixed"] + // Test fixed ratio group: hw_version_hana_fixed_ram + fixedResource, ok := serviceInfo.Resources["hw_version_hana_fixed_ram"] if !ok { - t.Fatal("expected ram_hana_fixed resource to exist") + t.Fatal("expected hw_version_hana_fixed_ram resource to exist") } if !fixedResource.HasCapacity { - t.Error("ram_hana_fixed: expected HasCapacity=true") + t.Error("hw_version_hana_fixed_ram: expected HasCapacity=true") } if !fixedResource.HandlesCommitments { - t.Error("ram_hana_fixed: expected HandlesCommitments=true (fixed ratio group)") + t.Error("hw_version_hana_fixed_ram: expected HandlesCommitments=true (fixed ratio group)") } if fixedResource.HasCapacity != fixedResource.HandlesCommitments { - t.Errorf("ram_hana_fixed: HasCapacity (%v) should equal HandlesCommitments (%v)", + t.Errorf("hw_version_hana_fixed_ram: HasCapacity (%v) should equal HandlesCommitments (%v)", fixedResource.HasCapacity, fixedResource.HandlesCommitments) } - // Test variable ratio group: ram_v2_variable - variableResource, ok := serviceInfo.Resources["ram_v2_variable"] + // Test variable ratio group: hw_version_v2_variable_ram + variableResource, ok := serviceInfo.Resources["hw_version_v2_variable_ram"] if !ok { - t.Fatal("expected ram_v2_variable resource to exist") + t.Fatal("expected hw_version_v2_variable_ram resource to exist") } // Variable ratio groups don't accept commitments, and we only report capacity for groups // that accept commitments, so both HasCapacity and HandlesCommitments should be false if variableResource.HasCapacity { - t.Error("ram_v2_variable: expected HasCapacity=false (variable ratio groups don't report capacity)") + t.Error("hw_version_v2_variable_ram: expected HasCapacity=false (variable ratio groups don't report capacity)") } if variableResource.HandlesCommitments { - t.Error("ram_v2_variable: expected HandlesCommitments=false (variable ratio group)") + t.Error("hw_version_v2_variable_ram: expected HandlesCommitments=false (variable ratio group)") } // Verify HasCapacity == HandlesCommitments for consistency if variableResource.HasCapacity != variableResource.HandlesCommitments { - t.Errorf("ram_v2_variable: HasCapacity (%v) should equal HandlesCommitments (%v)", + t.Errorf("hw_version_v2_variable_ram: HasCapacity (%v) should equal HandlesCommitments (%v)", variableResource.HasCapacity, variableResource.HandlesCommitments) } } diff --git a/internal/scheduling/reservations/commitments/api_report_capacity_test.go b/internal/scheduling/reservations/commitments/api_report_capacity_test.go index beb08c0b4..455127a8d 100644 --- a/internal/scheduling/reservations/commitments/api_report_capacity_test.go +++ b/internal/scheduling/reservations/commitments/api_report_capacity_test.go @@ -187,9 +187,9 @@ func TestCapacityCalculator(t *testing.T) { t.Fatalf("Expected 1 resource, got %d", len(report.Resources)) } - resource := report.Resources[liquid.ResourceName("ram_test-group")] + resource := report.Resources[liquid.ResourceName("hw_version_test-group_ram")] if resource == nil { - t.Fatal("Expected ram_test-group resource to exist") + t.Fatal("Expected hw_version_test-group_ram resource to exist") } // Should have empty perAZ map when no host details diff --git a/internal/scheduling/reservations/commitments/api_report_usage_test.go b/internal/scheduling/reservations/commitments/api_report_usage_test.go index 2a81fa468..21dddb766 100644 --- a/internal/scheduling/reservations/commitments/api_report_usage_test.go +++ b/internal/scheduling/reservations/commitments/api_report_usage_test.go @@ -57,7 +57,7 @@ func TestReportUsageIntegration(t *testing.T) { Reservations: []*UsageTestReservation{}, AllAZs: []string{"az-a"}, Expected: map[string]ExpectedResourceUsage{ - "ram_hana_1": { + "hw_version_hana_1_ram": { PerAZ: map[string]ExpectedAZUsage{ "az-a": {Usage: 0, VMs: []ExpectedVMUsage{}}, }, @@ -77,7 +77,7 @@ func TestReportUsageIntegration(t *testing.T) { }, AllAZs: []string{"az-a"}, Expected: map[string]ExpectedResourceUsage{ - "ram_hana_1": { + "hw_version_hana_1_ram": { PerAZ: map[string]ExpectedAZUsage{ "az-a": { Usage: 4, // 4096 MB / 1024 MB = 4 units @@ -99,7 +99,7 @@ func TestReportUsageIntegration(t *testing.T) { Reservations: []*UsageTestReservation{}, // No commitments AllAZs: []string{"az-a"}, Expected: map[string]ExpectedResourceUsage{ - "ram_hana_1": { + "hw_version_hana_1_ram": { PerAZ: map[string]ExpectedAZUsage{ "az-a": { Usage: 4, @@ -127,7 +127,7 @@ func TestReportUsageIntegration(t *testing.T) { }, AllAZs: []string{"az-a"}, Expected: map[string]ExpectedResourceUsage{ - "ram_hana_1": { + "hw_version_hana_1_ram": { PerAZ: map[string]ExpectedAZUsage{ "az-a": { Usage: 12, // 12 units total @@ -157,7 +157,7 @@ func TestReportUsageIntegration(t *testing.T) { }, AllAZs: []string{"az-a"}, Expected: map[string]ExpectedResourceUsage{ - "ram_hana_1": { + "hw_version_hana_1_ram": { PerAZ: map[string]ExpectedAZUsage{ "az-a": { Usage: 12, @@ -187,7 +187,7 @@ func TestReportUsageIntegration(t *testing.T) { }, AllAZs: []string{"az-a"}, Expected: map[string]ExpectedResourceUsage{ - "ram_hana_1": { + "hw_version_hana_1_ram": { PerAZ: map[string]ExpectedAZUsage{ "az-a": { Usage: 13, // 1 + 4 + 8 = 13 units @@ -216,7 +216,7 @@ func TestReportUsageIntegration(t *testing.T) { }, AllAZs: []string{"az-a"}, Expected: map[string]ExpectedResourceUsage{ - "ram_hana_1": { + "hw_version_hana_1_ram": { PerAZ: map[string]ExpectedAZUsage{ "az-a": { Usage: 8, @@ -243,7 +243,7 @@ func TestReportUsageIntegration(t *testing.T) { }, AllAZs: []string{"az-a", "az-b"}, Expected: map[string]ExpectedResourceUsage{ - "ram_hana_1": { + "hw_version_hana_1_ram": { PerAZ: map[string]ExpectedAZUsage{ "az-a": { Usage: 4, @@ -275,7 +275,7 @@ func TestReportUsageIntegration(t *testing.T) { }, AllAZs: []string{"az-a"}, Expected: map[string]ExpectedResourceUsage{ - "ram_hana_1": { + "hw_version_hana_1_ram": { PerAZ: map[string]ExpectedAZUsage{ "az-a": { Usage: 4, // 4096 MB / 1024 MB = 4 units @@ -285,7 +285,7 @@ func TestReportUsageIntegration(t *testing.T) { }, }, }, - "ram_gp_1": { + "hw_version_gp_1_ram": { PerAZ: map[string]ExpectedAZUsage{ "az-a": { Usage: 4, // 2048 MB / 512 MB = 4 units @@ -332,7 +332,7 @@ func TestReportUsageIntegration(t *testing.T) { }, AllAZs: []string{"az-a"}, Expected: map[string]ExpectedResourceUsage{ - "ram_hana_1": { + "hw_version_hana_1_ram": { PerAZ: map[string]ExpectedAZUsage{ "az-a": { Usage: 4, diff --git a/internal/scheduling/reservations/commitments/capacity.go b/internal/scheduling/reservations/commitments/capacity.go index 1dff26b71..7726b1dbe 100644 --- a/internal/scheduling/reservations/commitments/capacity.go +++ b/internal/scheduling/reservations/commitments/capacity.go @@ -53,8 +53,8 @@ func (c *CapacityCalculator) CalculateCapacity(ctx context.Context) (liquid.Serv continue } - // Resource name follows pattern: ram_ - resourceName := liquid.ResourceName(commitmentResourceNamePrefix + groupName) + // Resource name follows pattern: hw_version__ram + resourceName := liquid.ResourceName(ResourceNameFromFlavorGroup(groupName)) // Calculate per-AZ capacity and usage azCapacity, err := c.calculateAZCapacity(ctx, groupName, groupData) diff --git a/internal/scheduling/reservations/commitments/state.go b/internal/scheduling/reservations/commitments/state.go index c8e75ff83..4ed288d16 100644 --- a/internal/scheduling/reservations/commitments/state.go +++ b/internal/scheduling/reservations/commitments/state.go @@ -18,14 +18,30 @@ import ( // commitmentUUIDPattern validates commitment UUID format. var commitmentUUIDPattern = regexp.MustCompile(`^[a-zA-Z0-9-]{6,40}$`) -// Limes LIQUID resource naming convention: ram_ -const commitmentResourceNamePrefix = "ram_" +// Limes LIQUID resource naming convention: hw_version__ram +const ( + resourceNamePrefix = "hw_version_" + resourceNameSuffix = "_ram" +) + +// ResourceNameFromFlavorGroup creates a LIQUID resource name from a flavor group name. +// Format: hw_version__ram +func ResourceNameFromFlavorGroup(flavorGroup string) string { + return resourceNamePrefix + flavorGroup + resourceNameSuffix +} func getFlavorGroupNameFromResource(resourceName string) (string, error) { - if !strings.HasPrefix(resourceName, commitmentResourceNamePrefix) { + if !strings.HasPrefix(resourceName, resourceNamePrefix) || !strings.HasSuffix(resourceName, resourceNameSuffix) { return "", fmt.Errorf("invalid resource name: %s", resourceName) } - return strings.TrimPrefix(resourceName, commitmentResourceNamePrefix), nil + // Remove prefix and suffix + name := strings.TrimPrefix(resourceName, resourceNamePrefix) + name = strings.TrimSuffix(name, resourceNameSuffix) + // Validate that the extracted group name is not empty + if name == "" { + return "", fmt.Errorf("invalid resource name: %s (empty group name)", resourceName) + } + return name, nil } // CommitmentState represents desired or current commitment resource allocation. diff --git a/internal/scheduling/reservations/commitments/state_test.go b/internal/scheduling/reservations/commitments/state_test.go index 7060300db..717069708 100644 --- a/internal/scheduling/reservations/commitments/state_test.go +++ b/internal/scheduling/reservations/commitments/state_test.go @@ -36,7 +36,7 @@ func TestFromCommitment_CalculatesMemoryCorrectly(t *testing.T) { commitment := Commitment{ UUID: "test-uuid", ProjectID: "project-1", - ResourceName: "ram_test-group", + ResourceName: "hw_version_test-group_ram", Amount: 5, // 5 multiples of smallest flavor } @@ -236,7 +236,8 @@ func TestFromReservations_NonCommittedResourceType(t *testing.T) { } func TestGetFlavorGroupNameFromResource_Valid(t *testing.T) { - name, err := getFlavorGroupNameFromResource("ram_hana_medium_v2") + // Test valid resource names with underscores in flavor group + name, err := getFlavorGroupNameFromResource("hw_version_hana_medium_v2_ram") if err != nil { t.Fatalf("unexpected error: %v", err) } @@ -246,8 +247,29 @@ func TestGetFlavorGroupNameFromResource_Valid(t *testing.T) { } func TestGetFlavorGroupNameFromResource_Invalid(t *testing.T) { - _, err := getFlavorGroupNameFromResource("invalid_resource") - if err == nil { - t.Fatal("expected error for invalid resource name, got nil") + invalidCases := []string{ + "ram_2101", // old format + "invalid", // completely wrong + "hw_version__ram", // empty group name + "hw_version_2101", // missing suffix + } + for _, input := range invalidCases { + if _, err := getFlavorGroupNameFromResource(input); err == nil { + t.Errorf("expected error for %q, got nil", input) + } + } +} + +func TestResourceNameRoundTrip(t *testing.T) { + // Test that ResourceNameFromFlavorGroup and getFlavorGroupNameFromResource are inverses + for _, groupName := range []string{"2101", "hana_1", "hana_medium_v2"} { + resourceName := ResourceNameFromFlavorGroup(groupName) + recovered, err := getFlavorGroupNameFromResource(resourceName) + if err != nil { + t.Fatalf("round-trip failed for %q: %v", groupName, err) + } + if recovered != groupName { + t.Errorf("round-trip mismatch: %q -> %q -> %q", groupName, resourceName, recovered) + } } } diff --git a/internal/scheduling/reservations/commitments/syncer.go b/internal/scheduling/reservations/commitments/syncer.go index ace9488b2..d6588a3a8 100644 --- a/internal/scheduling/reservations/commitments/syncer.go +++ b/internal/scheduling/reservations/commitments/syncer.go @@ -6,7 +6,6 @@ package commitments import ( "context" "fmt" - "strings" "time" "github.com/cobaltcore-dev/cortex/api/v1alpha1" @@ -90,12 +89,8 @@ func (s *Syncer) getCommitmentStates(ctx context.Context, log logr.Logger, flavo log.Info("skipping non-compute commitment", "id", id, "serviceType", commitment.ServiceType) continue } - if !strings.HasPrefix(commitment.ResourceName, commitmentResourceNamePrefix) { - log.Info("skipping non-RAM-flavor-group commitment", "id", id, "resourceName", commitment.ResourceName) - continue - } - // Extract flavor group name from resource name + // Extract flavor group name from resource name (validates format: hw_version__ram) flavorGroupName, err := getFlavorGroupNameFromResource(commitment.ResourceName) if err != nil { log.Info("skipping commitment with invalid resource name", diff --git a/internal/scheduling/reservations/commitments/syncer_test.go b/internal/scheduling/reservations/commitments/syncer_test.go index 4c438ea40..ef773e676 100644 --- a/internal/scheduling/reservations/commitments/syncer_test.go +++ b/internal/scheduling/reservations/commitments/syncer_test.go @@ -221,7 +221,7 @@ func TestSyncer_SyncReservations_InstanceCommitments(t *testing.T) { ID: 1, UUID: "12345-67890-abcdef", ServiceType: "compute", - ResourceName: "ram_test_group_v1", + ResourceName: "hw_version_test_group_v1_ram", AvailabilityZone: "az1", Amount: 2, // 2 multiples of smallest flavor (2 * 1024MB = 2048MB total) Unit: "", @@ -357,7 +357,7 @@ func TestSyncer_SyncReservations_UpdateExisting(t *testing.T) { ID: 1, UUID: "12345-67890-abcdef", ServiceType: "compute", - ResourceName: "ram_new_group_v1", + ResourceName: "hw_version_new_group_v1_ram", AvailabilityZone: "az1", Amount: 1, Unit: "", @@ -459,7 +459,7 @@ func TestSyncer_SyncReservations_UnitMismatch(t *testing.T) { ID: 1, UUID: "unit-mismatch-test-uuid", ServiceType: "compute", - ResourceName: "ram_test_group_v1", + ResourceName: "hw_version_test_group_v1_ram", AvailabilityZone: "az1", Amount: 2, Unit: "2048 MiB", // Mismatched unit - should be "1024 MiB" @@ -543,7 +543,7 @@ func TestSyncer_SyncReservations_UnitMatch(t *testing.T) { ID: 1, UUID: "unit-match-test-uuid", ServiceType: "compute", - ResourceName: "ram_test_group_v1", + ResourceName: "hw_version_test_group_v1_ram", AvailabilityZone: "az1", Amount: 2, Unit: "1024 MiB", // Correct unit matching smallest flavor @@ -623,7 +623,7 @@ func TestSyncer_SyncReservations_EmptyUUID(t *testing.T) { ID: 1, UUID: "", // Empty UUID ServiceType: "compute", - ResourceName: "ram_test_group_v1", + ResourceName: "hw_version_test_group_v1_ram", AvailabilityZone: "az1", Amount: 1, Unit: "", diff --git a/internal/scheduling/reservations/commitments/usage.go b/internal/scheduling/reservations/commitments/usage.go index b71d4e752..536440209 100644 --- a/internal/scheduling/reservations/commitments/usage.go +++ b/internal/scheduling/reservations/commitments/usage.go @@ -396,7 +396,7 @@ func (c *UsageCalculator) buildUsageResponse( if !FlavorGroupAcceptsCommitments(&groupData) { continue } - resourceName := liquid.ResourceName(commitmentResourceNamePrefix + flavorGroupName) + resourceName := liquid.ResourceName(ResourceNameFromFlavorGroup(flavorGroupName)) perAZ := make(map[liquid.AvailabilityZone]*liquid.AZResourceUsageReport) diff --git a/internal/scheduling/reservations/commitments/usage_test.go b/internal/scheduling/reservations/commitments/usage_test.go index 371667913..04b32fffa 100644 --- a/internal/scheduling/reservations/commitments/usage_test.go +++ b/internal/scheduling/reservations/commitments/usage_test.go @@ -53,7 +53,7 @@ func TestUsageCalculator_CalculateUsage(t *testing.T) { reservations: []*v1alpha1.Reservation{}, allAZs: []liquid.AvailabilityZone{"az-a"}, expectedUsage: map[string]uint64{ - "ram_hana_1": 0, + "hw_version_hana_1_ram": 0, }, }, { @@ -75,7 +75,7 @@ func TestUsageCalculator_CalculateUsage(t *testing.T) { }, allAZs: []liquid.AvailabilityZone{"az-a"}, expectedUsage: map[string]uint64{ - "ram_hana_1": 4, // 4096 MB / 1024 MB = 4 units + "hw_version_hana_1_ram": 4, // 4096 MB / 1024 MB = 4 units }, }, { @@ -92,7 +92,7 @@ func TestUsageCalculator_CalculateUsage(t *testing.T) { reservations: []*v1alpha1.Reservation{}, // No commitments allAZs: []liquid.AvailabilityZone{"az-a"}, expectedUsage: map[string]uint64{ - "ram_hana_1": 4, + "hw_version_hana_1_ram": 4, }, }, } @@ -584,9 +584,9 @@ func TestUsageCalculator_ExpiredAndFutureCommitments(t *testing.T) { } // Find the VM in subresources and check its commitment assignment - res, ok := report.Resources["ram_hana_1"] + res, ok := report.Resources["hw_version_hana_1_ram"] if !ok { - t.Fatal("Resource ram_hana_1 not found") + t.Fatal("Resource hw_version_hana_1_ram not found") } var foundCommitment any