diff --git a/pkg/spoke/managedcluster/joining_controller.go b/pkg/spoke/managedcluster/joining_controller.go index b99941178..e0f158121 100644 --- a/pkg/spoke/managedcluster/joining_controller.go +++ b/pkg/spoke/managedcluster/joining_controller.go @@ -128,25 +128,30 @@ func (c *managedClusterJoiningController) getClusterResources() (capacity, alloc return nil, nil, err } - cpuCapacity := *resource.NewQuantity(int64(0), resource.DecimalSI) - memoryCapacity := *resource.NewQuantity(int64(0), resource.BinarySI) - cpuAllocatable := *resource.NewQuantity(int64(0), resource.DecimalSI) - memoryAllocatable := *resource.NewQuantity(int64(0), resource.BinarySI) + capacityList := make(map[clusterv1.ResourceName]resource.Quantity) + allocatableList := make(map[clusterv1.ResourceName]resource.Quantity) + for _, node := range nodes { - cpuCapacity.Add(*node.Status.Capacity.Cpu()) - memoryCapacity.Add(*node.Status.Capacity.Memory()) - cpuAllocatable.Add(*node.Status.Allocatable.Cpu()) - memoryAllocatable.Add(*node.Status.Allocatable.Memory()) + for key, value := range node.Status.Capacity { + if capacity, exist := capacityList[clusterv1.ResourceName(key)]; exist { + capacity.Add(value) + capacityList[clusterv1.ResourceName(key)] = capacity + } else { + capacityList[clusterv1.ResourceName(key)] = value + } + } + + for key, value := range node.Status.Allocatable { + if allocatable, exist := allocatableList[clusterv1.ResourceName(key)]; exist { + allocatable.Add(value) + allocatableList[clusterv1.ResourceName(key)] = allocatable + } else { + allocatableList[clusterv1.ResourceName(key)] = value + } + } } - return clusterv1.ResourceList{ - clusterv1.ResourceCPU: cpuCapacity, - clusterv1.ResourceMemory: formatQuantityToMi(memoryCapacity), - }, - clusterv1.ResourceList{ - clusterv1.ResourceCPU: cpuAllocatable, - clusterv1.ResourceMemory: formatQuantityToMi(memoryAllocatable), - }, nil + return capacityList, allocatableList, nil } func formatQuantityToMi(q resource.Quantity) resource.Quantity { diff --git a/test/e2e/loopback_test.go b/test/e2e/loopback_test.go index d8f805d2b..ca899e54f 100644 --- a/test/e2e/loopback_test.go +++ b/test/e2e/loopback_test.go @@ -425,6 +425,34 @@ var _ = ginkgo.Describe("Loopback registration [development]", func() { }) gomega.Expect(err).ToNot(gomega.HaveOccurred()) + // make sure the cpu and memory are still in the status, for compatibility + ginkgo.By("Make sure cpu and memory exist in status") + err = wait.Poll(1*time.Second, 30*time.Second, func() (bool, error) { + managedCluster, err := managedClusters.Get(context.TODO(), clusterName, metav1.GetOptions{}) + if err != nil { + return false, err + } + + if _, exist := managedCluster.Status.Allocatable[clusterv1.ResourceCPU]; !exist { + return false, fmt.Errorf("Resource %v doesn't exist in Allocatable", clusterv1.ResourceCPU) + } + + if _, exist := managedCluster.Status.Allocatable[clusterv1.ResourceMemory]; !exist { + return false, fmt.Errorf("Resource %v doesn't exist in Allocatable", clusterv1.ResourceMemory) + } + + if _, exist := managedCluster.Status.Capacity[clusterv1.ResourceCPU]; !exist { + return false, fmt.Errorf("Resource %v doesn't exist in Capacity", clusterv1.ResourceCPU) + } + + if _, exist := managedCluster.Status.Capacity[clusterv1.ResourceMemory]; !exist { + return false, fmt.Errorf("Resource %v doesn't exist in Capacity", clusterv1.ResourceMemory) + } + + return true, nil + }) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + ginkgo.By("Make sure ClusterClaims are synced") clusterClaims := []clusterv1.ManagedClusterClaim{ {