report all resources

Signed-off-by: suigh <suigh@cn.ibm.com>
This commit is contained in:
suigh
2021-09-07 09:30:30 +08:00
parent 2fab616935
commit 80b5f416e7
2 changed files with 49 additions and 16 deletions

View File

@@ -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 {

View File

@@ -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{
{