@@ -37,22 +37,28 @@ func toClusterNamespace(clusterRbacBinding interface{}) *models.V1ClusterNamespa
3737 return nil
3838 }
3939
40- gpu_limit , err := strconv .ParseInt (resourceAllocation ["gpu_limit" ].(string ), 10 , 32 )
41- if err != nil {
42- return nil
43- }
44- gpu_provider := "nvidia"
45- if provider , exists := resourceAllocation ["gpu_provider" ]; exists {
46- gpu_provider = provider .(string )
40+ var gpuConfig * models.V1GpuConfig
41+ if gpuLimitVal , exists := resourceAllocation ["gpu_limit" ]; exists && gpuLimitVal != nil {
42+ gpu_limit , err := strconv .ParseInt (gpuLimitVal .(string ), 10 , 32 )
43+ if err != nil {
44+ return nil
45+ }
46+
47+ gpu_provider := "nvidia"
48+ if provider , exists := resourceAllocation ["gpu_provider" ]; exists && provider != nil {
49+ gpu_provider = provider .(string )
50+ }
51+
52+ gpuConfig = & models.V1GpuConfig {
53+ Limit : int32 (gpu_limit ),
54+ Provider : & gpu_provider ,
55+ }
4756 }
4857
4958 resource_alloc := & models.V1ClusterNamespaceResourceAllocation {
5059 CPUCores : cpu_cores ,
5160 MemoryMiB : memory_MiB ,
52- GpuConfig : & models.V1GpuConfig {
53- Limit : int32 (gpu_limit ),
54- Provider : & gpu_provider ,
55- },
61+ GpuConfig : gpuConfig ,
5662 }
5763
5864 ns := & models.V1ClusterNamespaceResourceInputEntity {
@@ -78,11 +84,15 @@ func flattenClusterNamespaces(items []*models.V1ClusterNamespaceResource) []inte
7884 flattenResourceAllocation := make (map [string ]interface {})
7985 flattenResourceAllocation ["cpu_cores" ] = strconv .Itoa (int (math .Round (namespace .Spec .ResourceAllocation .CPUCores )))
8086 flattenResourceAllocation ["memory_MiB" ] = strconv .Itoa (int (math .Round (namespace .Spec .ResourceAllocation .MemoryMiB )))
81- flattenResourceAllocation ["gpu_limit" ] = strconv .Itoa (int (namespace .Spec .ResourceAllocation .GpuConfig .Limit ))
82- if namespace .Spec .ResourceAllocation .GpuConfig .Provider != nil {
83- flattenResourceAllocation ["gpu_provider" ] = * namespace .Spec .ResourceAllocation .GpuConfig .Provider
84- } else {
85- flattenResourceAllocation ["gpu_provider" ] = "nvidia"
87+
88+ // Only set GPU fields if GpuConfig exists and has meaningful values
89+ if namespace .Spec .ResourceAllocation .GpuConfig != nil && namespace .Spec .ResourceAllocation .GpuConfig .Limit > 0 {
90+ flattenResourceAllocation ["gpu_limit" ] = strconv .Itoa (int (namespace .Spec .ResourceAllocation .GpuConfig .Limit ))
91+ if namespace .Spec .ResourceAllocation .GpuConfig .Provider != nil {
92+ flattenResourceAllocation ["gpu_provider" ] = * namespace .Spec .ResourceAllocation .GpuConfig .Provider
93+ } else {
94+ flattenResourceAllocation ["gpu_provider" ] = "nvidia"
95+ }
8696 }
8797
8898 flattenNamespace ["resource_allocation" ] = flattenResourceAllocation
0 commit comments