-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: stormgbs <[email protected]>
- Loading branch information
Showing
18 changed files
with
1,119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Copyright 2022 The Koordinator Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package reason | ||
|
||
const ( | ||
UpdateCPU = "UpdateCPU" | ||
UpdateMemory = "UpdateMemory" | ||
UpdateCgroups = "UpdateCgroups" // update cgroups excluding the options already stated above | ||
UpdateSystemConfig = "UpdateSystemConfig" | ||
UpdateResctrlSchemata = "UpdateResctrlSchemata" // update resctrl l3 cat schemata | ||
UpdateResctrlTasks = "UpdateResctrlTasks" // update resctrl tasks | ||
|
||
EvictPodByNodeMemoryUsage = "EvictPodByNodeMemoryUsage" | ||
EvictPodByBECPUSatisfaction = "EvictPodByBECPUSatisfaction" | ||
|
||
AdjustBEByNodeCPUUsage = "AdjustBEByNodeCPUUsage" | ||
|
||
EvictPodSuccess = "evictPodSuccess" | ||
EvictPodFail = "evictPodFail" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
Copyright 2022 The Koordinator Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package testutil | ||
|
||
import ( | ||
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
apiext "github.com/koordinator-sh/koordinator/apis/extension" | ||
) | ||
|
||
type FakeRecorder struct { | ||
eventReason string | ||
} | ||
|
||
func (f *FakeRecorder) Event(object runtime.Object, eventType, reason, message string) { | ||
f.eventReason = reason | ||
fmt.Printf("send event:eventType:%s,reason:%s,message:%s", eventType, reason, message) | ||
} | ||
|
||
func (f *FakeRecorder) Eventf(object runtime.Object, eventType, reason, messageFmt string, args ...interface{}) { | ||
f.eventReason = reason | ||
fmt.Printf("send event:eventType:%s,reason:%s,message:%s", eventType, reason, messageFmt) | ||
} | ||
|
||
func (f *FakeRecorder) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventType, reason, messageFmt string, args ...interface{}) { | ||
f.Eventf(object, eventType, reason, messageFmt, args...) | ||
} | ||
|
||
func MockTestNode(cpu, memory string) *corev1.Node { | ||
return &corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-node", | ||
Namespace: "default", | ||
}, | ||
Status: corev1.NodeStatus{ | ||
Allocatable: corev1.ResourceList{ | ||
corev1.ResourceCPU: resource.MustParse(cpu), | ||
corev1.ResourceMemory: resource.MustParse(memory), | ||
}, | ||
Capacity: corev1.ResourceList{ | ||
corev1.ResourceCPU: resource.MustParse(cpu), | ||
corev1.ResourceMemory: resource.MustParse(memory), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func MockTestPod(qosClass apiext.QoSClass, name string) *corev1.Pod { | ||
return &corev1.Pod{ | ||
TypeMeta: metav1.TypeMeta{Kind: "Pod"}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
UID: types.UID(name), | ||
Labels: map[string]string{ | ||
apiext.LabelPodQoS: string(qosClass), | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
Copyright 2022 The Koordinator Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package types | ||
|
||
const ( | ||
DefaultCFSPeriod = 100000 | ||
DefaultMemUnlimit = 9223372036854771712 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2022 The Koordinator Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package utils | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/klog/v2" | ||
|
||
"github.com/koordinator-sh/koordinator/pkg/util" | ||
"github.com/koordinator-sh/koordinator/pkg/util/runtime" | ||
) | ||
|
||
// KillContainers kills containers inside the pod | ||
func KillContainers(pod *corev1.Pod, message string) { | ||
for _, container := range pod.Spec.Containers { | ||
containerID, containerStatus, err := util.FindContainerIdAndStatusByName(&pod.Status, container.Name) | ||
if err != nil { | ||
klog.Errorf("failed to find container id and status, error: %v", err) | ||
return | ||
} | ||
|
||
if containerStatus == nil || containerStatus.State.Running == nil { | ||
return | ||
} | ||
|
||
if containerID != "" { | ||
runtimeType, _, _ := util.ParseContainerId(containerStatus.ContainerID) | ||
runtimeHandler, err := runtime.GetRuntimeHandler(runtimeType) | ||
if err != nil || runtimeHandler == nil { | ||
klog.Errorf("%s, kill container(%s) error! GetRuntimeHandler fail! error: %v", message, containerStatus.ContainerID, err) | ||
continue | ||
} | ||
if err := runtimeHandler.StopContainer(containerID, 0); err != nil { | ||
klog.Errorf("%s, stop container error! error: %v", message, err) | ||
} | ||
} else { | ||
klog.Warningf("%s, get container ID failed, pod %s/%s containerName %s status: %v", message, pod.Namespace, pod.Name, container.Name, pod.Status.ContainerStatuses) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright 2022 The Koordinator Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package utils | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer" | ||
"github.com/koordinator-sh/koordinator/pkg/util" | ||
) | ||
|
||
func GetPodMetas(pods []*corev1.Pod) []*statesinformer.PodMeta { | ||
podMetas := make([]*statesinformer.PodMeta, len(pods)) | ||
|
||
for index, pod := range pods { | ||
cgroupDir := util.GetPodKubeRelativePath(pod) | ||
podMeta := &statesinformer.PodMeta{CgroupDir: cgroupDir, Pod: pod.DeepCopy()} | ||
podMetas[index] = podMeta | ||
} | ||
|
||
return podMetas | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.