Skip to content
Merged
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
42 changes: 26 additions & 16 deletions spectrocloud/cluster_common_namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,28 @@ func toClusterNamespace(clusterRbacBinding interface{}) *models.V1ClusterNamespa
return nil
}

gpu_limit, err := strconv.ParseInt(resourceAllocation["gpu_limit"].(string), 10, 32)
if err != nil {
return nil
}
gpu_provider := "nvidia"
if provider, exists := resourceAllocation["gpu_provider"]; exists {
gpu_provider = provider.(string)
var gpuConfig *models.V1GpuConfig
if gpuLimitVal, exists := resourceAllocation["gpu_limit"]; exists && gpuLimitVal != nil {
gpu_limit, err := strconv.ParseInt(gpuLimitVal.(string), 10, 32)
if err != nil {
return nil
}

gpu_provider := "nvidia"
if provider, exists := resourceAllocation["gpu_provider"]; exists && provider != nil {
gpu_provider = provider.(string)
}

gpuConfig = &models.V1GpuConfig{
Limit: int32(gpu_limit),
Provider: &gpu_provider,
}
}

resource_alloc := &models.V1ClusterNamespaceResourceAllocation{
CPUCores: cpu_cores,
MemoryMiB: memory_MiB,
GpuConfig: &models.V1GpuConfig{
Limit: int32(gpu_limit),
Provider: &gpu_provider,
},
GpuConfig: gpuConfig,
}

ns := &models.V1ClusterNamespaceResourceInputEntity{
Expand All @@ -78,11 +84,15 @@ func flattenClusterNamespaces(items []*models.V1ClusterNamespaceResource) []inte
flattenResourceAllocation := make(map[string]interface{})
flattenResourceAllocation["cpu_cores"] = strconv.Itoa(int(math.Round(namespace.Spec.ResourceAllocation.CPUCores)))
flattenResourceAllocation["memory_MiB"] = strconv.Itoa(int(math.Round(namespace.Spec.ResourceAllocation.MemoryMiB)))
flattenResourceAllocation["gpu_limit"] = strconv.Itoa(int(namespace.Spec.ResourceAllocation.GpuConfig.Limit))
if namespace.Spec.ResourceAllocation.GpuConfig.Provider != nil {
flattenResourceAllocation["gpu_provider"] = *namespace.Spec.ResourceAllocation.GpuConfig.Provider
} else {
flattenResourceAllocation["gpu_provider"] = "nvidia"

// Only set GPU fields if GpuConfig exists and has meaningful values
if namespace.Spec.ResourceAllocation.GpuConfig != nil && namespace.Spec.ResourceAllocation.GpuConfig.Limit > 0 {
flattenResourceAllocation["gpu_limit"] = strconv.Itoa(int(namespace.Spec.ResourceAllocation.GpuConfig.Limit))
if namespace.Spec.ResourceAllocation.GpuConfig.Provider != nil {
flattenResourceAllocation["gpu_provider"] = *namespace.Spec.ResourceAllocation.GpuConfig.Provider
} else {
flattenResourceAllocation["gpu_provider"] = "nvidia"
}
}

flattenNamespace["resource_allocation"] = flattenResourceAllocation
Expand Down