Skip to content

Commit

Permalink
Update SDK with new UpdateCommitment model (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
Digital-Falcon authored Jun 11, 2024
1 parent d49cdb4 commit e070bca
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 54 deletions.
15 changes: 4 additions & 11 deletions castai/resource_commitments_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,17 +507,10 @@ func mapCommitmentImportWithConfigToUpdateRequest(
c *commitmentWithConfig[castaiCommitment],
) sdk.CommitmentsAPIUpdateCommitmentJSONRequestBody {
req := sdk.CommitmentsAPIUpdateCommitmentJSONRequestBody{
AllowedUsage: c.Commitment.AllowedUsage,
EndDate: c.Commitment.EndDate,
GcpResourceCudContext: c.Commitment.GcpResourceCudContext,
AzureReservationContext: c.Commitment.AzureReservationContext,
Id: c.Commitment.Id,
Name: c.Commitment.Name,
Prioritization: c.Commitment.Prioritization,
Region: c.Commitment.Region,
StartDate: c.Commitment.StartDate,
Status: c.Commitment.Status,
ScalingStrategy: c.Commitment.ScalingStrategy,
AllowedUsage: c.Commitment.AllowedUsage,
Prioritization: c.Commitment.Prioritization,
Status: c.Commitment.Status,
ScalingStrategy: c.Commitment.ScalingStrategy,
}
if c.Config != nil {
if c.Config.AllowedUsage != nil {
Expand Down
50 changes: 8 additions & 42 deletions castai/resource_commitments_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1154,28 +1154,16 @@ func TestMapCommitmentImportWithConfigToUpdateRequest(t *testing.T) {
},
},
expected: sdk.CommitmentsAPIUpdateCommitmentJSONRequestBody{
AllowedUsage: lo.ToPtr[float32](0.7),
EndDate: lo.ToPtr(now.Add(365 * 24 * time.Hour)),
GcpResourceCudContext: &sdk.CastaiInventoryV1beta1GCPResourceCUD{
Cpu: lo.ToPtr("8"),
CudId: lo.ToPtr("123456"),
MemoryMb: lo.ToPtr("1024"),
Plan: lo.ToPtr[sdk.CastaiInventoryV1beta1GCPResourceCUDCUDPlan]("TWELVE_MONTHS"),
Status: lo.ToPtr("ACTIVE"),
Type: lo.ToPtr("COMPUTE_OPTIMIZED_C2D"),
},
Id: lo.ToPtr(id.String()),
Name: lo.ToPtr("test-cud-1"),
AllowedUsage: lo.ToPtr[float32](0.7),
Prioritization: lo.ToPtr(false),
Region: lo.ToPtr("us-central1"),
StartDate: lo.ToPtr(now.Add(-24 * time.Hour)),
Status: lo.ToPtr[sdk.CastaiInventoryV1beta1CommitmentStatus]("INACTIVE"),
},
},
"should map gcp cud import without config": {
input: &commitmentWithConfig[castaiCommitment]{
Commitment: castaiCommitment{
CastaiInventoryV1beta1Commitment: sdk.CastaiInventoryV1beta1Commitment{
AllowedUsage: lo.ToPtr[float32](0.7),
EndDate: lo.ToPtr(now.Add(365 * 24 * time.Hour)),
GcpResourceCudContext: testGCPCUDContext,
Id: lo.ToPtr(id.String()),
Expand All @@ -1186,19 +1174,7 @@ func TestMapCommitmentImportWithConfigToUpdateRequest(t *testing.T) {
},
},
expected: sdk.CommitmentsAPIUpdateCommitmentJSONRequestBody{
EndDate: lo.ToPtr(now.Add(365 * 24 * time.Hour)),
GcpResourceCudContext: &sdk.CastaiInventoryV1beta1GCPResourceCUD{
Cpu: lo.ToPtr("8"),
CudId: lo.ToPtr("123456"),
MemoryMb: lo.ToPtr("1024"),
Plan: lo.ToPtr[sdk.CastaiInventoryV1beta1GCPResourceCUDCUDPlan]("TWELVE_MONTHS"),
Status: lo.ToPtr("ACTIVE"),
Type: lo.ToPtr("COMPUTE_OPTIMIZED_C2D"),
},
Id: lo.ToPtr(id.String()),
Name: lo.ToPtr("test-cud-1"),
Region: lo.ToPtr("us-central1"),
StartDate: lo.ToPtr(now.Add(-24 * time.Hour)),
AllowedUsage: lo.ToPtr[float32](0.7),
},
},
"should map azure reservation import with config": {
Expand Down Expand Up @@ -1230,21 +1206,16 @@ func TestMapCommitmentImportWithConfigToUpdateRequest(t *testing.T) {
},
},
expected: sdk.CommitmentsAPIUpdateCommitmentJSONRequestBody{
AllowedUsage: lo.ToPtr[float32](0.7),
EndDate: lo.ToPtr(now.Add(365 * 24 * time.Hour)),
AzureReservationContext: testAzureReservationContext,
Id: lo.ToPtr(id.String()),
Name: lo.ToPtr("test-reservation-1"),
Prioritization: lo.ToPtr(false),
Region: lo.ToPtr("eastus"),
StartDate: lo.ToPtr(now.Add(-24 * time.Hour)),
Status: lo.ToPtr[sdk.CastaiInventoryV1beta1CommitmentStatus]("INACTIVE"),
AllowedUsage: lo.ToPtr[float32](0.7),
Prioritization: lo.ToPtr(false),
Status: lo.ToPtr[sdk.CastaiInventoryV1beta1CommitmentStatus]("INACTIVE"),
},
},
"should map azure reservation import without config": {
input: &commitmentWithConfig[castaiCommitment]{
Commitment: castaiCommitment{
CastaiInventoryV1beta1Commitment: sdk.CastaiInventoryV1beta1Commitment{
AllowedUsage: lo.ToPtr[float32](0.77),
EndDate: lo.ToPtr(now.Add(365 * 24 * time.Hour)),
AzureReservationContext: testAzureReservationContext,
Id: lo.ToPtr(id.String()),
Expand All @@ -1255,12 +1226,7 @@ func TestMapCommitmentImportWithConfigToUpdateRequest(t *testing.T) {
},
},
expected: sdk.CommitmentsAPIUpdateCommitmentJSONRequestBody{
EndDate: lo.ToPtr(now.Add(365 * 24 * time.Hour)),
AzureReservationContext: testAzureReservationContext,
Id: lo.ToPtr(id.String()),
Name: lo.ToPtr("test-reservation-1"),
Region: lo.ToPtr("eastus"),
StartDate: lo.ToPtr(now.Add(-24 * time.Hour)),
AllowedUsage: lo.ToPtr[float32](0.77),
},
},
}
Expand Down
21 changes: 20 additions & 1 deletion castai/sdk/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e070bca

Please sign in to comment.