Skip to content

Commit 39fde76

Browse files
committed
preinstall pv
1 parent 19b8464 commit 39fde76

File tree

7 files changed

+113
-16
lines changed

7 files changed

+113
-16
lines changed

pkg/server/handler/clusters/cluster.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,25 @@ spec:
8181
- name: Service
8282
`
8383

84+
const RecommendationRulePVsName = "persistentvolumes-rule"
85+
const RecommendationRulePVsYAML = `
86+
apiVersion: analysis.crane.io/v1alpha1
87+
kind: RecommendationRule
88+
metadata:
89+
name: persistentvolumes-rule
90+
labels:
91+
analysis.crane.io/recommendation-rule-preinstall: "true"
92+
spec:
93+
runInterval: 24h # 每24h运行一次
94+
resourceSelectors: # 资源的信息
95+
- kind: PersistentVolume
96+
apiVersion: v1
97+
namespaceSelector:
98+
any: true # 扫描所有namespace
99+
recommenders:
100+
- name: Volume
101+
`
102+
84103
type AddClustersRequest struct {
85104
Clusters []*store.Cluster `json:"clusters"`
86105
}
@@ -195,6 +214,12 @@ func (ch *ClusterHandler) AddClusters(c *gin.Context) {
195214
ginwrapper.WriteResponse(c, err, nil)
196215
return
197216
}
217+
218+
err = ch.upsertRecommendationRule(RecommendationRulePVsName, RecommendationRulePVsYAML)
219+
if err != nil {
220+
ginwrapper.WriteResponse(c, err, nil)
221+
return
222+
}
198223
} else if err != nil {
199224
ginwrapper.WriteResponse(c, err, nil)
200225
return

site/.DS_Store

6 KB
Binary file not shown.

site/content/en/docs/Tutorials/Recommendation/pv-recommendation.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,60 @@
11
---
2-
title: "PV 推荐"
3-
description: "PV 推荐功能介绍"
4-
weight: 15
2+
title: "PV Recommendation"
3+
description: "Introduce for PV Recommendation"
4+
weight: 17
55
---
66

7-
Service 推荐通过扫描集群中 Service 的运行状况,帮助用户找到闲置的 Kubernetes Service
7+
PV 推荐通过扫描集群中 PV 的运行状况,帮助用户找到闲置的 Kubernetes PV
88

99
## 动机
1010

11-
通常在 Kubernetes 中我们会使用 Service + Workload 来自动创建和管理负载均衡并 将负载均衡挂载到应用上,在日常的运营中难免会出现空闲和低利用率的负载均衡,浪费了大量成本,Service 推荐尝试帮助用户找到这部分 Service 来实现成本优化。
11+
通常在 Kubernetes 中我们会使用 PV + Workload 来自动创建和管理存储卷并将存储卷挂载到应用上,在日常的运营中难免会出现空闲或者空跑的存储卷,浪费了大量成本, PV 推荐尝试帮助用户找到这部分 PV 来实现成本优化。
1212

1313
## 推荐示例
1414

1515
```yaml
16-
16+
apiVersion: analysis.crane.io/v1alpha1
17+
kind: Recommendation
18+
metadata:
19+
annotations:
20+
analysis.crane.io/last-start-time: "2023-06-14 08:55:25"
21+
analysis.crane.io/message: Success
22+
analysis.crane.io/run-number: "653"
23+
labels:
24+
analysis.crane.io/recommendation-rule-name: persistentvolumes-rule
25+
analysis.crane.io/recommendation-rule-recommender: Volume
26+
analysis.crane.io/recommendation-rule-uid: 39d30abe-4c7f-4e65-b961-b00ec7776b45
27+
analysis.crane.io/recommendation-target-kind: PersistentVolume
28+
analysis.crane.io/recommendation-target-name: pvc-6ce24277-24e9-4fcf-8e8a-f9bdb5694134
29+
analysis.crane.io/recommendation-target-namespace: ""
30+
analysis.crane.io/recommendation-target-version: v1
31+
name: persistentvolumes-rule-volume-5r9zn
32+
namespace: crane-system
33+
ownerReferences:
34+
- apiVersion: analysis.crane.io/v1alpha1
35+
blockOwnerDeletion: false
36+
controller: false
37+
kind: RecommendationRule
38+
name: persistentvolumes-rule
39+
uid: 39d30abe-4c7f-4e65-b961-b00ec7776b45
40+
spec:
41+
adoptionType: StatusAndAnnotation
42+
completionStrategy:
43+
completionStrategyType: Once
44+
targetRef:
45+
apiVersion: v1
46+
kind: PersistentVolume
47+
name: pvc-6ce24277-24e9-4fcf-8e8a-f9bdb5694134
48+
type: Volume
49+
status:
50+
action: Delete
51+
description: It is an Orphan Volumes
52+
lastUpdateTime: "2023-06-14T08:55:25Z"
1753
```
1854
1955
在该示例中:
2056
21-
- 推荐的 TargetRef 指向了 PV:
57+
- 推荐的 TargetRef 指向了 PV: pvc-6ce24277-24e9-4fcf-8e8a-f9bdb5694134
2258
- 推荐类型为 PV 推荐
2359
- action 是 Delete,这里只是给出建议
2460

site/content/en/docs/Tutorials/Recommendation/service-recommendation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: "闲置节点推荐"
3-
description: "闲置节点推荐功能介绍"
4-
weight: 15
2+
title: "Service Recommendation"
3+
description: "Introduce for Service Recommendation"
4+
weight: 16
55
---
66

77
Service 推荐通过扫描集群中 Service 的运行状况,帮助用户找到闲置的 Kubernetes Service。

site/content/zh/docs/Tutorials/Recommendation/pv-recommendation.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "PV 推荐"
33
description: "PV 推荐功能介绍"
4-
weight: 15
4+
weight: 17
55
---
66

77
PV 推荐通过扫描集群中 PV 的运行状况,帮助用户找到闲置的 Kubernetes PV。
@@ -13,12 +13,48 @@ PV 推荐通过扫描集群中 PV 的运行状况,帮助用户找到闲置的
1313
## 推荐示例
1414

1515
```yaml
16-
16+
apiVersion: analysis.crane.io/v1alpha1
17+
kind: Recommendation
18+
metadata:
19+
annotations:
20+
analysis.crane.io/last-start-time: "2023-06-14 08:55:25"
21+
analysis.crane.io/message: Success
22+
analysis.crane.io/run-number: "653"
23+
labels:
24+
analysis.crane.io/recommendation-rule-name: persistentvolumes-rule
25+
analysis.crane.io/recommendation-rule-recommender: Volume
26+
analysis.crane.io/recommendation-rule-uid: 39d30abe-4c7f-4e65-b961-b00ec7776b45
27+
analysis.crane.io/recommendation-target-kind: PersistentVolume
28+
analysis.crane.io/recommendation-target-name: pvc-6ce24277-24e9-4fcf-8e8a-f9bdb5694134
29+
analysis.crane.io/recommendation-target-namespace: ""
30+
analysis.crane.io/recommendation-target-version: v1
31+
name: persistentvolumes-rule-volume-5r9zn
32+
namespace: crane-system
33+
ownerReferences:
34+
- apiVersion: analysis.crane.io/v1alpha1
35+
blockOwnerDeletion: false
36+
controller: false
37+
kind: RecommendationRule
38+
name: persistentvolumes-rule
39+
uid: 39d30abe-4c7f-4e65-b961-b00ec7776b45
40+
spec:
41+
adoptionType: StatusAndAnnotation
42+
completionStrategy:
43+
completionStrategyType: Once
44+
targetRef:
45+
apiVersion: v1
46+
kind: PersistentVolume
47+
name: pvc-6ce24277-24e9-4fcf-8e8a-f9bdb5694134
48+
type: Volume
49+
status:
50+
action: Delete
51+
description: It is an Orphan Volumes
52+
lastUpdateTime: "2023-06-14T08:55:25Z"
1753
```
1854
1955
在该示例中:
2056
21-
- 推荐的 TargetRef 指向了 PV:
57+
- 推荐的 TargetRef 指向了 PV: pvc-6ce24277-24e9-4fcf-8e8a-f9bdb5694134
2258
- 推荐类型为 PV 推荐
2359
- action 是 Delete,这里只是给出建议
2460

site/content/zh/docs/Tutorials/Recommendation/service-recommendation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: "闲置节点推荐"
3-
description: "闲置节点推荐功能介绍"
4-
weight: 15
2+
title: "Service 推荐"
3+
description: "Service 推荐功能介绍"
4+
weight: 16
55
---
66

77
Service 推荐通过扫描集群中 Service 的运行状况,帮助用户找到闲置的 Kubernetes Service。

site/training.zip

1.58 MB
Binary file not shown.

0 commit comments

Comments
 (0)