Skip to content

Commit c42a1c0

Browse files
authored
PLT-1957: Fixed namespaces issue in cluster day2 (#676)
1 parent ef18255 commit c42a1c0

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

spectrocloud/cluster_common_namespaces.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)