Skip to content

Commit

Permalink
scheduler: fix initializing built-in quota objects (#1917)
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph <joseph.t.lee@outlook.com>
  • Loading branch information
eahydra committed Feb 26, 2024
1 parent 47fdecb commit 5afff95
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions pkg/scheduler/plugins/elasticquota/plugin_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,15 @@ func (g *Plugin) migratePods(out, in string) {

// createDefaultQuotaIfNotPresent create DefaultQuotaGroup's CRD
func (g *Plugin) createDefaultQuotaIfNotPresent() {
eq, _ := g.client.SchedulingV1alpha1().ElasticQuotas(g.pluginArgs.QuotaGroupNamespace).Get(context.TODO(), extension.DefaultQuotaName, metav1.GetOptions{ResourceVersion: "0"})
if eq != nil {
eq, err := g.client.SchedulingV1alpha1().ElasticQuotas(g.pluginArgs.QuotaGroupNamespace).Get(context.TODO(), extension.DefaultQuotaName, metav1.GetOptions{ResourceVersion: "0"})
if err == nil && eq != nil {
klog.Infof("DefaultQuota already exists, skip create it.")
return
}
if err != nil && !errors.IsNotFound(err) {
klog.Errorf("failed to get DefaultQuota, err: %v", err)
return
}

defaultElasticQuota := &schedulerv1alpha1.ElasticQuota{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -170,7 +174,7 @@ func (g *Plugin) createDefaultQuotaIfNotPresent() {
Max: g.pluginArgs.DefaultQuotaGroupMax.DeepCopy(),
},
}
_, err := g.client.SchedulingV1alpha1().ElasticQuotas(g.pluginArgs.QuotaGroupNamespace).
_, err = g.client.SchedulingV1alpha1().ElasticQuotas(g.pluginArgs.QuotaGroupNamespace).
Create(context.TODO(), defaultElasticQuota, metav1.CreateOptions{})
if err != nil {
klog.Errorf("create default group fail, err:%v", err.Error())
Expand All @@ -182,11 +186,15 @@ func (g *Plugin) createDefaultQuotaIfNotPresent() {
// defaultQuotaInfo and systemQuotaInfo are created once the groupQuotaManager is created, but we also want to see
// the used/request of the two quotaGroups, so we create the two quota's CRD if not present.
func (g *Plugin) createSystemQuotaIfNotPresent() {
eq, _ := g.client.SchedulingV1alpha1().ElasticQuotas(g.pluginArgs.QuotaGroupNamespace).Get(context.TODO(), extension.SystemQuotaName, metav1.GetOptions{ResourceVersion: "0"})
if eq != nil {
eq, err := g.client.SchedulingV1alpha1().ElasticQuotas(g.pluginArgs.QuotaGroupNamespace).Get(context.TODO(), extension.SystemQuotaName, metav1.GetOptions{ResourceVersion: "0"})
if err == nil && eq != nil {
klog.Infof("SystemQuota already exists, skip create it.")
return
}
if err != nil && !errors.IsNotFound(err) {
klog.Errorf("failed to get SystemQuota, err: %v", err)
return
}

systemElasticQuota := &schedulerv1alpha1.ElasticQuota{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -198,7 +206,7 @@ func (g *Plugin) createSystemQuotaIfNotPresent() {
Max: g.pluginArgs.SystemQuotaGroupMax.DeepCopy(),
},
}
_, err := g.client.SchedulingV1alpha1().ElasticQuotas(g.pluginArgs.QuotaGroupNamespace).
_, err = g.client.SchedulingV1alpha1().ElasticQuotas(g.pluginArgs.QuotaGroupNamespace).
Create(context.TODO(), systemElasticQuota, metav1.CreateOptions{})
if err != nil {
klog.Errorf("create system group fail, err:%v", err.Error())
Expand All @@ -209,11 +217,16 @@ func (g *Plugin) createSystemQuotaIfNotPresent() {

// createRootQuotaIfNotPresent create RootQuotaGroup's CRD
func (g *Plugin) createRootQuotaIfNotPresent() {
eq, _ := g.client.SchedulingV1alpha1().ElasticQuotas(g.pluginArgs.QuotaGroupNamespace).Get(context.TODO(), extension.RootQuotaName, metav1.GetOptions{ResourceVersion: "0"})
if eq != nil {
eq, err := g.client.SchedulingV1alpha1().ElasticQuotas(g.pluginArgs.QuotaGroupNamespace).Get(context.TODO(), extension.RootQuotaName, metav1.GetOptions{ResourceVersion: "0"})
if err == nil && eq != nil {
klog.Infof("RootQuota already exists, skip create it.")
return
}
if err != nil && !errors.IsNotFound(err) {
klog.Errorf("failed to get RootQuota, err: %v", err)
return
}

rootElasticQuota := &schedulerv1alpha1.ElasticQuota{
ObjectMeta: metav1.ObjectMeta{
Name: extension.RootQuotaName,
Expand All @@ -225,7 +238,7 @@ func (g *Plugin) createRootQuotaIfNotPresent() {
rootElasticQuota.Labels[extension.LabelQuotaIsParent] = "true"
rootElasticQuota.Labels[extension.LabelAllowLentResource] = "false"
rootElasticQuota.Labels[extension.LabelQuotaParent] = ""
_, err := g.client.SchedulingV1alpha1().ElasticQuotas(g.pluginArgs.QuotaGroupNamespace).
_, err = g.client.SchedulingV1alpha1().ElasticQuotas(g.pluginArgs.QuotaGroupNamespace).
Create(context.TODO(), rootElasticQuota, metav1.CreateOptions{})
if err != nil {
klog.Errorf("create root group fail, err:%v", err.Error())
Expand Down

0 comments on commit 5afff95

Please sign in to comment.