Skip to content

Commit

Permalink
Merge pull request stolostron#342 from qiujian16/remove-cpu-worker
Browse files Browse the repository at this point in the history
Remove cpu_worker/socket etc
  • Loading branch information
openshift-merge-robot authored May 7, 2021
2 parents fc8b57a + 508669c commit 3614814
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 28 deletions.
13 changes: 1 addition & 12 deletions pkg/controllers/clusterinfo/capacity_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ import (
)

const (
resourceCore clusterv1.ResourceName = "core"
resourceSocket clusterv1.ResourceName = "socket"
resourceCoreWorker clusterv1.ResourceName = "core_worker"
resourceSocketWorker clusterv1.ResourceName = "socket_worker"
resourceCPUWorker clusterv1.ResourceName = "cpu_worker"
)

type CapacityReconciler struct {
Expand Down Expand Up @@ -62,25 +60,16 @@ func (r *CapacityReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
}

nodes := clusterInfo.Status.NodeList
cpuWorkerCapacity := *resource.NewQuantity(int64(0), resource.DecimalSI)
socketTotalCapacity := *resource.NewQuantity(int64(0), resource.DecimalSI)
socketWorkerCapacity := *resource.NewQuantity(int64(0), resource.DecimalSI)
coreTotalCapacity := *resource.NewQuantity(int64(0), resource.DecimalSI)
coreWorkerCapacity := *resource.NewQuantity(int64(0), resource.DecimalSI)
for _, node := range nodes {
socketTotalCapacity.Add(node.Capacity[resourceSocket])
coreTotalCapacity.Add(node.Capacity[resourceCore])
if isWorker(node) {
cpuWorkerCapacity.Add(node.Capacity[clusterv1.ResourceCPU])
coreWorkerCapacity.Add(node.Capacity[clusterv1.ResourceCPU])
socketWorkerCapacity.Add(node.Capacity[resourceSocket])
coreWorkerCapacity.Add(node.Capacity[resourceCore])
}
}
capacity[resourceCPUWorker] = cpuWorkerCapacity
capacity[resourceSocketWorker] = socketWorkerCapacity
capacity[resourceCoreWorker] = coreWorkerCapacity
capacity[resourceSocket] = socketTotalCapacity
capacity[resourceCore] = coreTotalCapacity

if apiequality.Semantic.DeepEqual(capacity, cluster.Status.Capacity) {
return ctrl.Result{}, nil
Expand Down
5 changes: 2 additions & 3 deletions pkg/controllers/clusterinfo/capacity_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ func TestCapacityReconcile(t *testing.T) {
name: "UpdateManagedClusterCapacity",
existingCluster: newCluster(ManagedClusterName, map[clusterv1.ResourceName]int64{"cpu": 1}),
existinClusterInfo: newClusterInfo(ManagedClusterName, map[string]bool{"node1": false}, 2),
expectedCapacity: newCapacity(map[clusterv1.ResourceName]int64{"cpu": 1, "cpu_worker": 0, "socket": 2, "socket_worker": 0, "core": 2, "core_worker": 0}),
expectedCapacity: newCapacity(map[clusterv1.ResourceName]int64{"cpu": 1, "socket_worker": 0, "core_worker": 0}),
},
{
name: "UpdateManagedClusterCapacityWithWorker",
existingCluster: newCluster(ManagedClusterName, map[clusterv1.ResourceName]int64{"cpu": 1}),
existinClusterInfo: newClusterInfo(ManagedClusterName, map[string]bool{"node1": false, "node2": true}, 2),
expectedCapacity: newCapacity(map[clusterv1.ResourceName]int64{"cpu": 1, "cpu_worker": 2, "socket": 4, "socket_worker": 2, "core": 4, "core_worker": 2}),
expectedCapacity: newCapacity(map[clusterv1.ResourceName]int64{"cpu": 1, "socket_worker": 2, "core_worker": 2}),
},
}

Expand Down Expand Up @@ -113,7 +113,6 @@ func newClusterInfo(name string, resources map[string]bool, val int64) *clusterv
Capacity: clusterv1beta1.ResourceList{
"cpu": *resource.NewQuantity(val, resource.DecimalSI),
"socket": *resource.NewQuantity(val, resource.DecimalSI),
"core": *resource.NewQuantity(val, resource.DecimalSI),
},
}
if isworker {
Expand Down
8 changes: 0 additions & 8 deletions pkg/klusterlet/nodecollector/nodecollecter.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,12 @@ func (r *resourceCollector) updateCapcityByPrometheus(ctx context.Context, nodes
return nodes
}

cores, err := r.queryResource(ctx, apiClient, "machine_cpu_cores")
if err != nil {
klog.Errorf("failed to query resource: %v", err)
}

sockets, err := r.queryResource(ctx, apiClient, "machine_cpu_sockets")
if err != nil {
klog.Errorf("failed to query resource: %v", err)
}

for index := range nodes {
if capacity, ok := cores[nodes[index].Name]; ok {
nodes[index].Capacity[resourceCore] = *capacity
}
if capacity, ok := sockets[nodes[index].Name]; ok {
nodes[index].Capacity[resourceSocket] = *capacity
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/klusterlet/nodecollector/nodecollector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestReconcile(t *testing.T) {
},
},
expectedNodeList: []clusterv1beta1.NodeStatus{
newResourceStatus("node1", map[clusterapiv1.ResourceName]int64{"cpu": 1, "core": 1, "socket": 1}, true),
newResourceStatus("node1", map[clusterapiv1.ResourceName]int64{"cpu": 1, "socket": 1}, true),
},
},
{
Expand All @@ -174,8 +174,8 @@ func TestReconcile(t *testing.T) {
},
},
expectedNodeList: []clusterv1beta1.NodeStatus{
newResourceStatus("node1", map[clusterapiv1.ResourceName]int64{"cpu": 2, "core": 2, "socket": 2}, true),
newResourceStatus("node2", map[clusterapiv1.ResourceName]int64{"cpu": 1, "core": 1, "socket": 1}, false),
newResourceStatus("node1", map[clusterapiv1.ResourceName]int64{"cpu": 2, "socket": 2}, true),
newResourceStatus("node2", map[clusterapiv1.ResourceName]int64{"cpu": 1, "socket": 1}, false),
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/managedcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var _ = ginkgo.Describe("Testing ManagedCluster", func() {
}

capacity := cluster.Status.Capacity
if _, ok := capacity["cpu_worker"]; !ok {
return fmt.Errorf("Expect cpu_worker to be set, but got %v", capacity)
if _, ok := capacity["core_worker"]; !ok {
return fmt.Errorf("Expect core_worker to be set, but got %v", capacity)
}
return nil
}, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred())
Expand Down

0 comments on commit 3614814

Please sign in to comment.