Skip to content

Commit dacec28

Browse files
committed
add elastic resource quota to volcano scheduling api
1 parent 21e2239 commit dacec28

File tree

17 files changed

+1149
-0
lines changed

17 files changed

+1149
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Copyright 2021 The Volcano Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package scheduling
18+
19+
import (
20+
v1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// +genclient
25+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
26+
27+
// Elastic Resource Quota
28+
type ElasticResourceQuota struct {
29+
metav1.TypeMeta `json:",inline"`
30+
// +optional
31+
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
32+
// Specification of the desired behavior of the ElasticResourceQuota.
33+
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status
34+
// +optional
35+
Spec ElasticResourceQuotaSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
36+
// The status of ElasticResourceQuota.
37+
// +optional
38+
Status ElasticResourceQuotaStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
39+
}
40+
41+
// ElasticResourceQuotaSpec represents the template of Elastic Resource Quota.
42+
type ElasticResourceQuotaSpec struct {
43+
// Max is the upper bound of elastic resource quota
44+
Max v1.ResourceList `json:"max,omitempty" protobuf:"bytes,1,opt,name=max"`
45+
// Min is the lower bound of elastic resource quota
46+
Min v1.ResourceList `json:"min,omitempty" protobuf:"bytes,2,opt,name=min"`
47+
// Reclaimable indicate whether the elastic quota can be reclaimed by other elastic resource quota
48+
Reclaimable bool `json:"reclaimable,omitempty" protobuf:"bytes,3,opt,name=reclaimable"`
49+
// HardwareTypes defines hardware types of elastic resource quota
50+
HardwareTypes []string `json:"hardwareTypes,omitempty" protobuf:"bytes,4,opt,name=hardwareTypes"`
51+
// namespace defines elastic resource quota belongs to one namespace
52+
Namespace string `json:"namespace,omitempty" protobuf:"bytes,5,opt,name=namespace"`
53+
}
54+
55+
// ElasticResourceQuotaStatus represents the status of Elastic Resource Quota.
56+
type ElasticResourceQuotaStatus struct {
57+
// IsLeaf defines whether elastic resource quota is leaf or not
58+
IsLeaf bool `json:"isLeaf,omitempty" protobuf:"bytes,1,opt,name=isLeaf"`
59+
// Used resource of elastic resource quota
60+
Used v1.ResourceList `json:"used,omitempty" protobuf:"bytes,2,opt,name=used"`
61+
// QueueName indicate bound queue
62+
QueueName string `json:"queueName,omitempty" protobuf:"bytes,3,opt,name=queueName"`
63+
}
64+
65+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
66+
// +kubebuilder:object:root=true
67+
68+
// ElasticResourceQuotaList is a collection of ElasticResourceQuota.
69+
type ElasticResourceQuotaList struct {
70+
metav1.TypeMeta `json:",inline"`
71+
// Standard list metadata
72+
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
73+
// +optional
74+
metav1.ListMeta `json:"metadata,omitempty"`
75+
76+
// items is the list of PodGroup
77+
Items []ElasticResourceQuota `json:"items"`
78+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
Copyright 2021 The Volcano Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
"os"
21+
"strings"
22+
23+
"k8s.io/klog"
24+
)
25+
26+
// QuotaTypeKey identify the type of quota in labels
27+
// which can be 'logical' or 'physical'.
28+
// soft means share the same nodes set with other quotas
29+
// hard specified a node set
30+
const QuotaTypeKey = "paddleflow.baidu.com/resource-isolation-type"
31+
const QuotaTypePhysical = "physical"
32+
const QuotaTypeLogical = "logical"
33+
34+
// QueueBindingElasticQuotaKey is a label key, which identify the name of elasticResourceQuota which binding current queue
35+
const QueueBindingElasticQuotaKey = "paddleflow.baidu.com/binding-elastic-resource-quota-name"
36+
37+
// ElasticQuotaParentKey is a label key, which indicate the parent Name for current elasticResourceQuota
38+
const ElasticQuotaParentKey = "paddleflow.baidu.com/elastic-resource-quota-parent"
39+
40+
var (
41+
// GlobalNodeManageEnabled
42+
GlobalNodeManageEnabled = true
43+
// QuotaManagedNodeKey indicate label of node, which is managed by quota
44+
QuotaManagedNodeKey string = "paddleflow.baidu.com/cluster-role"
45+
// QuotaLabelKey indicate node label key of quota
46+
QuotaLabelKey string = "paddleflow.baidu.com/quota"
47+
// QuotaHardwareTypeLabelKey label key of hardware type
48+
QuotaHardwareTypeLabelKey string = "paddleflow.baidu.com/hardware-type"
49+
// NodeScaleDown idle node state, which is one of type in labels[ResourceQuotaLabel]
50+
NodeScaleDown = "scale-down"
51+
// DefaultResourceQuota the name of default resourcequota
52+
DefaultResourceQuota = "default"
53+
// DefaultNamespace the key of default resourcequota in default namespace
54+
DefaultNamespace = "default"
55+
// resourceFieldFilter
56+
ResourceFieldFilter = map[string]bool{"hugepages-1Gi": true, "hugepages-2Mi": true, "ephemeral-storage": true, "pods": true}
57+
)
58+
59+
const (
60+
GlobalNodeManageEnabledEnv = "GLOBAL_NODE_MANAGE_ENABLE"
61+
ResourceQuotaNodeManageLabelKeyEnv = "RESOURCE_QUOTA_NODE_MANAGE_LABEL_KEY"
62+
ResourceQuotaLabelKeyEnv = "RESOURCE_QUOTA_LABEL_KEY"
63+
ResourceQuotaHardwareTypeLabelKeyEnv = "RESOURCE_QUOTA_HARDWARE_TYPE_LABEL_KEY"
64+
ResourceFieldFilterEnv = "RESOURCE_FIELD_FILTER"
65+
)
66+
67+
func ResourceQuotaConfigInit() {
68+
value := os.Getenv(GlobalNodeManageEnabledEnv)
69+
if value == "false" {
70+
GlobalNodeManageEnabled = false
71+
}
72+
rpnm := os.Getenv(ResourceQuotaNodeManageLabelKeyEnv)
73+
if len(rpnm) != 0 {
74+
QuotaManagedNodeKey = rpnm
75+
}
76+
rpLabelKey := os.Getenv(ResourceQuotaLabelKeyEnv)
77+
if len(rpLabelKey) != 0 {
78+
QuotaLabelKey = rpLabelKey
79+
}
80+
hardwareTypeLabelKey := os.Getenv(ResourceQuotaHardwareTypeLabelKeyEnv)
81+
if len(hardwareTypeLabelKey) != 0 {
82+
QuotaHardwareTypeLabelKey = hardwareTypeLabelKey
83+
}
84+
resourceFieldFilter := os.Getenv(ResourceFieldFilterEnv)
85+
if len(resourceFieldFilter) != 0 {
86+
fieldFilterList := strings.Split(resourceFieldFilter, ",")
87+
ResourceFieldFilter = map[string]bool{}
88+
for _, fieldFilter := range fieldFilterList {
89+
ResourceFieldFilter[fieldFilter] = true
90+
}
91+
}
92+
93+
// It is recommended to code according to the line-format when printing new variables
94+
klog.Infof("resourcequota config: GlobalNodeManageEnabled[%v], QuotaManagedNodeKey[%v], "+
95+
"QuotaLabelKey[%v], QuotaHardwareTypeLabelKey[%v], NodeScaleDown[%v], DefaultResourceQuota[%v], "+
96+
"ResourceFieldFilter[%v]",
97+
GlobalNodeManageEnabled, QuotaManagedNodeKey,
98+
QuotaLabelKey, QuotaHardwareTypeLabelKey, NodeScaleDown, DefaultResourceQuota,
99+
ResourceFieldFilter)
100+
}

pkg/apis/scheduling/v1beta1/register.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
5151
&PodGroupList{},
5252
&Queue{},
5353
&QueueList{},
54+
&ElasticResourceQuota{},
55+
&ElasticResourceQuotaList{},
5456
)
5557

5658
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
Copyright 2021 The Volcano Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
v1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// +genclient
25+
// +genclient:nonNamespaced
26+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
27+
// +kubebuilder:object:root=true
28+
// +kubebuilder:resource:path=elasticresourcequotas,scope=Cluster,shortName=equota;equota-v1beta1
29+
// +kubebuilder:subresource:status
30+
31+
// Elastic Resource Quota
32+
type ElasticResourceQuota struct {
33+
metav1.TypeMeta `json:",inline"`
34+
// +optional
35+
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
36+
// Specification of the desired behavior of the ElasticResourceQuota.
37+
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status
38+
// +optional
39+
Spec ElasticResourceQuotaSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
40+
// The status of ElasticResourceQuota.
41+
// +optional
42+
Status ElasticResourceQuotaStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
43+
}
44+
45+
// ElasticResourceQuotaSpec represents the template of Elastic Resource Quota.
46+
type ElasticResourceQuotaSpec struct {
47+
// Max is the upper bound of elastic resource quota
48+
Max v1.ResourceList `json:"max,omitempty" protobuf:"bytes,1,opt,name=max"`
49+
// Min is the lower bound of elastic resource quota
50+
Min v1.ResourceList `json:"min,omitempty" protobuf:"bytes,2,opt,name=min"`
51+
// Reclaimable indicate whether the elastic quota can be reclaimed by other elastic resource quota
52+
Reclaimable bool `json:"reclaimable,omitempty" protobuf:"bytes,3,opt,name=reclaimable"`
53+
// HardwareTypes defines hardware types of elastic resource quota
54+
HardwareTypes []string `json:"hardwareTypes,omitempty" protobuf:"bytes,4,opt,name=hardwareTypes"`
55+
// namespace defines elastic resource quota belongs to one namespace
56+
Namespace string `json:"namespace,omitempty" protobuf:"bytes,5,opt,name=namespace"`
57+
}
58+
59+
// ElasticResourceQuotaStatus represents the status of Elastic Resource Quota.
60+
type ElasticResourceQuotaStatus struct {
61+
// IsLeaf defines whether elastic resource quota is leaf or not
62+
IsLeaf bool `json:"isLeaf,omitempty" protobuf:"bytes,1,opt,name=isLeaf"`
63+
// Used resource of elastic resource quota
64+
Used v1.ResourceList `json:"used,omitempty" protobuf:"bytes,2,opt,name=used"`
65+
// QueueName indicate bound queue
66+
QueueName string `json:"queueName,omitempty" protobuf:"bytes,3,opt,name=queueName"`
67+
}
68+
69+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
70+
// +kubebuilder:object:root=true
71+
72+
// ElasticResourceQuotaList is a collection of ElasticResourceQuota.
73+
type ElasticResourceQuotaList struct {
74+
metav1.TypeMeta `json:",inline"`
75+
// Standard list metadata
76+
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
77+
// +optional
78+
metav1.ListMeta `json:"metadata,omitempty"`
79+
80+
// items is the list of PodGroup
81+
Items []ElasticResourceQuota `json:"items"`
82+
}

0 commit comments

Comments
 (0)