-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webhook: fix OnQuotaAdd/Update/Delete when quota namespace annotation…
… changed Signed-off-by: chuanyun.lcy <chuanyun.lcy@alibaba-inc.com>
- Loading branch information
chuanyun.lcy
committed
Jan 30, 2024
1 parent
cb3703b
commit a495c85
Showing
6 changed files
with
138 additions
and
5 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,59 @@ | ||
package elasticquota | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
|
||
"github.com/koordinator-sh/koordinator/apis/extension" | ||
) | ||
|
||
func TestQuotaHandler(t *testing.T) { | ||
client := fake.NewClientBuilder().Build() | ||
topology := NewQuotaTopology(client) | ||
|
||
parentQuota := MakeQuota("parentQuota").Namespace("kube-system").Max(MakeResourceList().CPU(120).Mem(1048576).Obj()). | ||
Min(MakeResourceList().CPU(120).Mem(1048576).Obj()).IsParent(true).Obj() | ||
|
||
topology.OnQuotaAdd(parentQuota) | ||
|
||
// check parent quota info | ||
quotaInfo := topology.getQuotaInfo(parentQuota.Name, parentQuota.Namespace) | ||
assert.NotNil(t, quotaInfo) | ||
assert.Equal(t, parentQuota.Name, quotaInfo.Name) | ||
assert.Equal(t, extension.RootQuotaName, quotaInfo.ParentName) | ||
|
||
childQuota := MakeQuota("childQuota").Namespace("kube-system").Max(MakeResourceList().CPU(120).Mem(1048576).Obj()). | ||
Min(MakeResourceList().CPU(120).Mem(1048576).Obj()).IsParent(false).ParentName(parentQuota.Name).Annotations( | ||
map[string]string{extension.AnnotationQuotaNamespaces: `["namespace1"]`}, | ||
).Obj() | ||
topology.OnQuotaAdd(childQuota) | ||
|
||
// check child quota info | ||
quotaInfo = topology.getQuotaInfo(childQuota.Name, childQuota.Namespace) | ||
assert.NotNil(t, quotaInfo) | ||
assert.Equal(t, childQuota.Name, quotaInfo.Name) | ||
assert.Equal(t, parentQuota.Name, quotaInfo.ParentName) | ||
// get quota by namespace | ||
quotaInfo = topology.getQuotaInfo("", "namespace1") | ||
assert.NotNil(t, quotaInfo) | ||
assert.Equal(t, childQuota.Name, quotaInfo.Name) | ||
|
||
// update quota info | ||
newChildQuota := childQuota.DeepCopy() | ||
newChildQuota.Annotations[extension.AnnotationQuotaNamespaces] = `["namespace2"]` | ||
topology.OnQuotaUpdate(childQuota, newChildQuota) | ||
quotaInfo = topology.getQuotaInfo("", "namespace1") | ||
assert.Nil(t, quotaInfo) | ||
quotaInfo = topology.getQuotaInfo("", "namespace2") | ||
assert.NotNil(t, quotaInfo) | ||
assert.Equal(t, childQuota.Name, quotaInfo.Name) | ||
|
||
// delete quota | ||
topology.OnQuotaDelete(newChildQuota) | ||
quotaInfo = topology.getQuotaInfo(childQuota.Name, childQuota.Namespace) | ||
assert.Nil(t, quotaInfo) | ||
quotaInfo = topology.getQuotaInfo("", "namespace2") | ||
assert.Nil(t, quotaInfo) | ||
} |
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