-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kaiyuechen
committed
Sep 15, 2022
1 parent
0ebcef7
commit 7ef2bdf
Showing
10 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
13 changes: 13 additions & 0 deletions
13
examples/ensurance/evict-on-mem-usage-percent/elastic-pod-qos.yaml
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,13 @@ | ||
apiVersion: ensurance.crane.io/v1alpha1 | ||
kind: PodQOS | ||
metadata: | ||
name: all-elastic-pods | ||
spec: | ||
allowedActions: | ||
- eviction | ||
resourceQOS: | ||
cpuQOS: | ||
cpuPriority: 7 | ||
labelSelector: | ||
matchLabels: | ||
preemptible_job: "true" |
9 changes: 9 additions & 0 deletions
9
examples/ensurance/evict-on-mem-usage-percent/eviction-action.yaml
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,9 @@ | ||
apiVersion: ensurance.crane.io/v1alpha1 | ||
kind: AvoidanceAction | ||
metadata: | ||
name: eviction | ||
spec: | ||
coolDownSeconds: 300 | ||
description: evict low priority pods | ||
eviction: | ||
terminationGracePeriodSeconds: 30 |
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,56 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: low-pi6 | ||
labels: | ||
k8s-app: low | ||
preemptible_job: "true" | ||
spec: | ||
containers: | ||
- image: ccr.ccs.tencentyun.com/tkeimages/stress-ng:v0.12.09 | ||
command: | ||
- stress-ng | ||
- --vm-hang | ||
- "3600" | ||
- --vm | ||
- "2" | ||
- --vm-bytes | ||
- "2G" | ||
name: stress | ||
volumeMounts: | ||
- mountPath: /data | ||
name: data | ||
volumes: | ||
- hostPath: | ||
path: /data/dd | ||
type: DirectoryOrCreate | ||
name: data | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: low-pi2 | ||
labels: | ||
k8s-app: low | ||
preemptible_job: "true" | ||
spec: | ||
containers: | ||
- image: ccr.ccs.tencentyun.com/tkeimages/stress-ng:v0.12.09 | ||
command: | ||
- stress-ng | ||
- --vm-hang | ||
- "3600" | ||
- --vm | ||
- "2" | ||
- --vm-bytes | ||
- "3.5G" | ||
name: stress | ||
volumeMounts: | ||
- mountPath: /data | ||
name: data | ||
volumes: | ||
- hostPath: | ||
path: /data/dd | ||
type: DirectoryOrCreate | ||
name: data | ||
|
18 changes: 18 additions & 0 deletions
18
examples/ensurance/evict-on-mem-usage-percent/watermark.yaml
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,18 @@ | ||
apiVersion: ensurance.crane.io/v1alpha1 | ||
kind: NodeQOS | ||
metadata: | ||
name: eviction-on-high-mem-usage-percent | ||
spec: | ||
nodeQualityProbe: | ||
nodeLocalGet: | ||
localCacheTTLSeconds: 60 | ||
timeoutSeconds: 10 | ||
rules: | ||
- actionName: eviction | ||
avoidanceThreshold: 2 | ||
metricRule: | ||
name: memory_total_utilization | ||
value: 50 | ||
name: cpu-usage-percent | ||
restoreThreshold: 2 | ||
strategy: None |
2 changes: 1 addition & 1 deletion
2
...e/evict-on-mem-usage-total/waterline.yaml → ...e/evict-on-mem-usage-total/watermark.yaml
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
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,70 @@ | ||
package executor | ||
|
||
import ( | ||
"sync" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
"github.com/gocrane/crane/pkg/ensurance/executor/podinfo" | ||
"github.com/gocrane/crane/pkg/ensurance/executor/sort" | ||
"github.com/gocrane/crane/pkg/metrics" | ||
"github.com/gocrane/crane/pkg/utils" | ||
) | ||
|
||
func init() { | ||
registerMetricMap(memUsagePercent) | ||
} | ||
|
||
var memUsagePercent = metric{ | ||
Name: MemUsagePercent, | ||
ActionPriority: 5, | ||
Sortable: true, | ||
SortFunc: sort.MemUsageSort, | ||
|
||
Throttleable: false, | ||
ThrottleQuantified: false, | ||
ThrottleFunc: nil, | ||
RestoreFunc: nil, | ||
|
||
Evictable: true, | ||
EvictQuantified: true, | ||
EvictFunc: memUsagePercentEvictPod, | ||
} | ||
|
||
func memUsagePercentEvictPod(wg *sync.WaitGroup, ctx *ExecuteContext, index int, totalReleasedResource *ReleaseResource, EvictPods EvictPods) (errPodKeys []string, released ReleaseResource) { | ||
wg.Add(1) | ||
|
||
// Calculate release resources | ||
released = releaseMemUsagePercent(EvictPods[index]) | ||
totalReleasedResource.Add(released) | ||
|
||
go func(evictPod podinfo.PodContext) { | ||
defer wg.Done() | ||
|
||
pod, err := ctx.PodLister.Pods(evictPod.Key.Namespace).Get(evictPod.Key.Name) | ||
if err != nil { | ||
errPodKeys = append(errPodKeys, "not found ", evictPod.Key.String()) | ||
return | ||
} | ||
klog.Warningf("Evicting pod %v", evictPod.Key) | ||
err = utils.EvictPodWithGracePeriod(ctx.Client, pod, evictPod.DeletionGracePeriodSeconds) | ||
if err != nil { | ||
errPodKeys = append(errPodKeys, "evict failed ", evictPod.Key.String()) | ||
klog.Warningf("Failed to evict pod %s: %v", evictPod.Key.String(), err) | ||
return | ||
} | ||
metrics.ExecutorEvictCountsInc() | ||
|
||
klog.Warningf("Pod %s is evicted", klog.KObj(pod)) | ||
}(EvictPods[index]) | ||
return | ||
} | ||
|
||
func releaseMemUsagePercent(pod podinfo.PodContext) ReleaseResource { | ||
if pod.ActionType == podinfo.Evict { | ||
return ReleaseResource{ | ||
MemUsagePercent: pod.PodMemUsage, | ||
} | ||
} | ||
return ReleaseResource{} | ||
} |
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