Skip to content

Commit

Permalink
webhook: fix webhook for root quota creation (koordinator-sh#1916)
Browse files Browse the repository at this point in the history
Signed-off-by: chuanyun.lcy <chuanyun.lcy@alibaba-inc.com>
Co-authored-by: chuanyun.lcy <chuanyun.lcy@alibaba-inc.com>
  • Loading branch information
shaloulcy and chuanyun.lcy committed Feb 26, 2024
1 parent 873fffb commit 17c9493
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 13 additions & 0 deletions pkg/webhook/elasticquota/mutating/mutating_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ func TestElasticQuotaMutatingHandler_Handle(t *testing.T) {
},
allowed: true,
},
{
name: "create root quota",
request: admission.Request{
AdmissionRequest: admissionv1.AdmissionRequest{
Resource: gvr("elasticquotas"),
Operation: admissionv1.Create,
Object: runtime.RawExtension{
Raw: []byte(`{"metadata":{"name":"koordinator-root-quota"}}`),
},
},
},
allowed: true,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion pkg/webhook/elasticquota/quota_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,18 @@ func (qt *quotaTopology) ValidDeleteQuota(quota *v1alpha1.ElasticQuota) error {

// fillQuotaDefaultInformation fills quota with default information if not configure
func (qt *quotaTopology) fillQuotaDefaultInformation(quota *v1alpha1.ElasticQuota) error {
if quota.Name == extension.RootQuotaName {
return nil
}

if quota.Labels == nil {
quota.Labels = make(map[string]string)
}
if quota.Annotations == nil {
quota.Annotations = make(map[string]string)
}

if parentName, exist := quota.Labels[extension.LabelQuotaParent]; (!exist || len(parentName) == 0) && quota.Name != extension.RootQuotaName {
if parentName, exist := quota.Labels[extension.LabelQuotaParent]; !exist || len(parentName) == 0 {
quota.Labels[extension.LabelQuotaParent] = extension.RootQuotaName
klog.V(5).Infof("fill quota %v parent as root", quota.Name)
}
Expand Down

0 comments on commit 17c9493

Please sign in to comment.