You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@yunikorn.apache.org by ma...@apache.org on 2023/07/12 10:29:12 UTC

[yunikorn-core] branch master updated: [YUNIKORN-1575] [core] Ability to specify guaranteedResources via namespace annotations (#569)

This is an automated email from the ASF dual-hosted git repository.

mani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 1f1d67d7 [YUNIKORN-1575] [core] Ability to specify guaranteedResources via namespace annotations (#569)
1f1d67d7 is described below

commit 1f1d67d76a720a07488a61dc39a17eb0f04a0b28
Author: qzhu <qz...@cloudera.com>
AuthorDate: Wed Jul 12 15:58:52 2023 +0530

    [YUNIKORN-1575] [core] Ability to specify guaranteedResources via namespace annotations (#569)
    
    Closes: #569
    
    Signed-off-by: Manikandan R <ma...@gmail.com>
---
 pkg/scheduler/objects/queue.go      | 57 +++++++++++++++++++------
 pkg/scheduler/objects/queue_test.go | 85 ++++++++++++++++++++++++++++++++++---
 2 files changed, 124 insertions(+), 18 deletions(-)

diff --git a/pkg/scheduler/objects/queue.go b/pkg/scheduler/objects/queue.go
index 2f4fe591..e30d9bb6 100644
--- a/pkg/scheduler/objects/queue.go
+++ b/pkg/scheduler/objects/queue.go
@@ -681,29 +681,60 @@ func (sq *Queue) AddApplication(app *Application) {
 	// YUNIKORN-199: update the quota from the namespace
 	// get the tag with the quota
 	quota := app.GetTag(common.AppTagNamespaceResourceQuota)
-	if quota == "" {
+	// get the tag with the guaranteed resource
+	guaranteed := app.GetTag(common.AppTagNamespaceResourceGuaranteed)
+	if quota == "" && guaranteed == "" {
 		return
 	}
+
+	var quotaRes, guaranteedRes *resources.Resource
+	var quotaErr, guaranteedErr error
+
 	// need to set a quota: convert json string to resource
-	res, err := resources.NewResourceFromString(quota)
-	if err != nil {
-		log.Log(log.SchedQueue).Warn("application resource quota conversion failure",
-			zap.String("json quota string", quota),
-			zap.Error(err))
-		return
+	if quota != "" {
+		quotaRes, quotaErr = resources.NewResourceFromString(quota)
+		if quotaErr != nil {
+			log.Log(log.SchedQueue).Warn("application resource quota conversion failure",
+				zap.String("json quota string", quota),
+				zap.Error(quotaErr))
+		} else if !resources.StrictlyGreaterThanZero(quotaRes) {
+			log.Log(log.SchedQueue).Warn("Max resource quantities should be greater than zero: cannot set queue max resource",
+				zap.Stringer("maxResource", quotaRes))
+			quotaRes = nil // Skip setting quota if it has a value <= 0
+		}
 	}
-	if !resources.StrictlyGreaterThanZero(res) {
-		log.Log(log.SchedQueue).Warn("application resource quota has at least one 0 value: cannot set queue limit",
-			zap.Stringer("maxResource", res))
-		return
+
+	// need to set guaranteed resource: convert json string to resource
+	if guaranteed != "" {
+		guaranteedRes, guaranteedErr = resources.NewResourceFromString(guaranteed)
+		if guaranteedErr != nil {
+			log.Log(log.SchedQueue).Warn("application guaranteed resource conversion failure",
+				zap.String("json guaranteed string", guaranteed),
+				zap.Error(guaranteedErr))
+			if quotaErr != nil {
+				return
+			}
+		} else if !resources.StrictlyGreaterThanZero(guaranteedRes) {
+			log.Log(log.SchedQueue).Warn("Guaranteed resource quantities should be greater than zero: cannot set queue guaranteed resource",
+				zap.Stringer("guaranteedResource", guaranteedRes))
+			guaranteedRes = nil // Skip setting guaranteed resource if it has a value <= 0
+		}
 	}
+
 	// set the quota
 	if sq.isManaged {
-		log.Log(log.SchedQueue).Warn("Trying to set max resources set on a queue that is not an unmanaged leaf",
+		log.Log(log.SchedQueue).Warn("Trying to set max resources on a queue that is not an unmanaged leaf",
 			zap.String("queueName", sq.QueuePath))
 		return
 	}
-	sq.maxResource = res
+
+	if quotaRes != nil {
+		sq.maxResource = quotaRes
+	}
+
+	if guaranteedRes != nil {
+		sq.guaranteedResource = guaranteedRes
+	}
 }
 
 // RemoveApplication removes the app from the list of tracked applications. Make sure that the app
diff --git a/pkg/scheduler/objects/queue_test.go b/pkg/scheduler/objects/queue_test.go
index b23b8394..928ad054 100644
--- a/pkg/scheduler/objects/queue_test.go
+++ b/pkg/scheduler/objects/queue_test.go
@@ -381,7 +381,7 @@ func TestAddApplicationWithTag(t *testing.T) {
 	}
 	app = newApplication("app-2", "default", "root.leaf-un")
 	leafUn.AddApplication(app)
-	assert.Equal(t, len(leaf.applications), 1, "Application was not added to the Dynamic queue as expected")
+	assert.Equal(t, len(leafUn.applications), 1, "Application was not added to the Dynamic queue as expected")
 	if leafUn.GetMaxResource() != nil {
 		t.Errorf("Max resources should not be set on Dynamic queue got: %s", leafUn.GetMaxResource().String())
 	}
@@ -390,8 +390,13 @@ func TestAddApplicationWithTag(t *testing.T) {
 		map[string]resources.Quantity{
 			"first": 10,
 		})
+	guaranteedRes := resources.NewResourceFromMap(
+		map[string]resources.Quantity{
+			"first": 5,
+		})
 	tags := make(map[string]string)
 	tags[siCommon.AppTagNamespaceResourceQuota] = "{\"resources\":{\"first\":{\"value\":10}}}"
+	tags[siCommon.AppTagNamespaceResourceGuaranteed] = "{\"resources\":{\"first\":{\"value\":5}}}"
 	// add apps again now with the tag set
 	app = newApplicationWithTags("app-3", "default", "root.leaf-man", tags)
 	leaf.AddApplication(app)
@@ -399,21 +404,91 @@ func TestAddApplicationWithTag(t *testing.T) {
 	if leaf.GetMaxResource() != nil {
 		t.Errorf("Max resources should not be set on managed queue got: %s", leaf.GetMaxResource().String())
 	}
+	if leaf.GetGuaranteedResource() != nil {
+		t.Errorf("Guaranteed resources should not be set on managed queue got: %s", leaf.GetGuaranteedResource().String())
+	}
+
 	app = newApplicationWithTags("app-4", "default", "root.leaf-un", tags)
 	leafUn.AddApplication(app)
-	assert.Equal(t, len(leaf.applications), 2, "Application was not added to the Dynamic queue as expected")
+	assert.Equal(t, len(leafUn.applications), 2, "Application was not added to the Dynamic queue as expected")
 	if !resources.Equals(leafUn.GetMaxResource(), maxRes) {
 		t.Errorf("Max resources not set as expected: %s got: %v", maxRes.String(), leafUn.GetMaxResource())
 	}
+	if !resources.Equals(leafUn.GetGuaranteedResource(), guaranteedRes) {
+		t.Errorf("Guaranteed resources not set as expected: %s got: %v", guaranteedRes.String(), leafUn.GetGuaranteedResource())
+	}
 
-	// set to illegal limit (0 value)
+	// set max to illegal limit (0 value), but guarantee not 0
 	tags[siCommon.AppTagNamespaceResourceQuota] = "{\"resources\":{\"first\":{\"value\":0}}}"
-	app = newApplicationWithTags("app-4", "default", "root.leaf-un", tags)
+
+	app = newApplicationWithTags("app-5", "default", "root.leaf-un", tags)
+	leafUn.AddApplication(app)
+	assert.Equal(t, len(leafUn.applications), 3, "Application was not added to the Dynamic queue as expected")
+	if !resources.Equals(leafUn.GetMaxResource(), maxRes) {
+		t.Errorf("Max resources not set as expected: %s got: %v", maxRes.String(), leafUn.GetMaxResource())
+	}
+	if !resources.Equals(leafUn.GetGuaranteedResource(), guaranteedRes) {
+		t.Errorf("Guaranteed resources not set as expected: %s got: %v", guaranteedRes.String(), leafUn.GetGuaranteedResource())
+	}
+
+	// set guaranteed resource to illegal limit (0 value), but max resource not 0
+	tags[siCommon.AppTagNamespaceResourceGuaranteed] = "{\"resources\":{\"first\":{\"value\":0}}}"
+	tags[siCommon.AppTagNamespaceResourceQuota] = "{\"resources\":{\"first\":{\"value\":100}}}"
+
+	app = newApplicationWithTags("app-6", "default", "root.leaf-un", tags)
+	leafUn.AddApplication(app)
+	assert.Equal(t, len(leafUn.applications), 4, "Application was not added to the Dynamic queue as expected")
+	if !resources.Equals(leafUn.GetMaxResource(), resources.NewResourceFromMap(
+		map[string]resources.Quantity{
+			"first": 100,
+		})) {
+		t.Errorf("Max resources not set as expected: %s got: %v", resources.NewResourceFromMap(
+			map[string]resources.Quantity{
+				"first": 100,
+			}).String(), leafUn.GetMaxResource())
+	}
+	if !resources.Equals(leafUn.GetGuaranteedResource(), guaranteedRes) {
+		t.Errorf("Guaranteed resources not set as expected: %s got: %v", guaranteedRes.String(), leafUn.GetGuaranteedResource())
+	}
+
+	// set guaranteed resource tag to "", but max resource not ""
+	tags[siCommon.AppTagNamespaceResourceGuaranteed] = ""
+	tags[siCommon.AppTagNamespaceResourceQuota] = "{\"resources\":{\"first\":{\"value\":10}}}"
+	app = newApplicationWithTags("app-7", "default", "root.leaf-un", tags)
+	leafUn.AddApplication(app)
+	assert.Equal(t, len(leafUn.applications), 5, "Application was not added to the Dynamic queue as expected")
+	if !resources.Equals(leafUn.GetMaxResource(), maxRes) {
+		t.Errorf("Max resources not set as expected: %s got: %v", maxRes.String(), leafUn.GetMaxResource())
+	}
+	if !resources.Equals(leafUn.GetGuaranteedResource(), guaranteedRes) {
+		t.Errorf("Guaranteed resources not set as expected: %s got: %v", guaranteedRes.String(), leafUn.GetGuaranteedResource())
+	}
+
+	// set both to "" , the max resource and guaranteed resource will not update new value
+	tags[siCommon.AppTagNamespaceResourceGuaranteed] = ""
+	tags[siCommon.AppTagNamespaceResourceQuota] = ""
+	app = newApplicationWithTags("app-8", "default", "root.leaf-un", tags)
 	leafUn.AddApplication(app)
-	assert.Equal(t, len(leaf.applications), 2, "Application was not added to the Dynamic queue as expected")
+	assert.Equal(t, len(leafUn.applications), 6, "Application was not added to the Dynamic queue as expected")
 	if !resources.Equals(leafUn.GetMaxResource(), maxRes) {
 		t.Errorf("Max resources not set as expected: %s got: %v", maxRes.String(), leafUn.GetMaxResource())
 	}
+	if !resources.Equals(leafUn.GetGuaranteedResource(), guaranteedRes) {
+		t.Errorf("Guaranteed resources not set as expected: %s got: %v", guaranteedRes.String(), leafUn.GetGuaranteedResource())
+	}
+
+	// set both to 0 , the max resource and guaranteed resource will not update new value
+	tags[siCommon.AppTagNamespaceResourceGuaranteed] = "{\"resources\":{\"first\":{\"value\":0}}}"
+	tags[siCommon.AppTagNamespaceResourceQuota] = "{\"resources\":{\"first\":{\"value\":0}}}"
+	app = newApplicationWithTags("app-9", "default", "root.leaf-un", tags)
+	leafUn.AddApplication(app)
+	assert.Equal(t, len(leafUn.applications), 7, "Application was not added to the Dynamic queue as expected")
+	if !resources.Equals(leafUn.GetMaxResource(), maxRes) {
+		t.Errorf("Max resources not set as expected: %s got: %v", maxRes.String(), leafUn.GetMaxResource())
+	}
+	if !resources.Equals(leafUn.GetGuaranteedResource(), guaranteedRes) {
+		t.Errorf("Guaranteed resources not set as expected: %s got: %v", guaranteedRes.String(), leafUn.GetGuaranteedResource())
+	}
 }
 
 func TestRemoveApplication(t *testing.T) {


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@yunikorn.apache.org
For additional commands, e-mail: issues-help@yunikorn.apache.org