Skip to content

Commit

Permalink
[YUNIKORN-1984] output extra config
Browse files Browse the repository at this point in the history
Signed-off-by: PoAn Yang <[email protected]>
  • Loading branch information
FrankYang0529 committed Sep 29, 2023
1 parent 6e97aa7 commit 5dcfdb2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
7 changes: 7 additions & 0 deletions pkg/webservice/dao/config_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@

package dao

import "github.com/apache/yunikorn-core/pkg/common/configs"

type ValidateConfResponse struct {
Allowed bool `json:"allowed"` // no omitempty, a false value gives a quick way to understand the result.
Reason string `json:"reason,omitempty"`
}

type ConfigDAOInfo struct {
*configs.SchedulerConfig
Extra map[string]string `yaml:",omitempty" json:",omitempty"`
}
10 changes: 9 additions & 1 deletion pkg/webservice/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,17 @@ func getContainerHistory(w http.ResponseWriter, r *http.Request) {
func getClusterConfig(w http.ResponseWriter, r *http.Request) {
writeHeaders(w)

conf := configs.ConfigContext.Get(schedulerContext.GetPolicyGroup())
var marshalledConf []byte
var err error

// merge core config with extra config
schedulerConf := configs.ConfigContext.Get(schedulerContext.GetPolicyGroup())
extraConfig := configs.GetConfigMap()
conf := dao.ConfigDAOInfo{
SchedulerConfig: schedulerConf,
Extra: extraConfig,
}

// check if we have a request for json output
if r.Header.Get("Accept") == "application/json" {
marshalledConf, err = json.Marshal(&conf)
Expand Down
23 changes: 21 additions & 2 deletions pkg/webservice/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ const queueName = "root.default"
const nodeID = "node-1"
const instType = "itype-1"

var (
updatedExtraConf = map[string]string{
"log.level": "info",
"service.schedulingInterval": "1s",
"admissionController.accessControl.bypassAuth": "false",
}
)

// setup To take care of setting up config, cluster, partitions etc
func setup(t *testing.T, config string, partitionCount int) *scheduler.PartitionContext {
var err error
Expand Down Expand Up @@ -481,7 +489,7 @@ func TestGetConfigYAML(t *testing.T) {
resp := &MockResponseWriter{}
getClusterConfig(resp, req)
// yaml unmarshal handles the checksum add the end automatically in this implementation
conf := &configs.SchedulerConfig{}
conf := &dao.ConfigDAOInfo{}
err = yaml.Unmarshal(resp.outputBytes, conf)
assert.NilError(t, err, "failed to unmarshal config from response body")
assert.Equal(t, conf.Partitions[0].NodeSortPolicy.Type, "fair", "node sort policy set incorrectly, not fair")
Expand All @@ -492,13 +500,19 @@ func TestGetConfigYAML(t *testing.T) {
// change the config
err = schedulerContext.UpdateRMSchedulerConfig(rmID, []byte(updatedConf))
assert.NilError(t, err, "Error when updating clusterInfo from config")
configs.SetConfigMap(updatedExtraConf)

// check that we return yaml by default, unmarshal will error when we don't
req.Header.Set("Accept", "unknown")
getClusterConfig(resp, req)
err = yaml.Unmarshal(resp.outputBytes, conf)
assert.NilError(t, err, "failed to unmarshal config from response body (updated config)")
assert.Equal(t, conf.Partitions[0].NodeSortPolicy.Type, "binpacking", "node sort policy not updated")
assert.Assert(t, startConfSum != conf.Checksum, "checksums did not change in output")
assert.Assert(t, reflect.DeepEqual(conf.Extra, updatedExtraConf), "extra config did not change")

// reset extra config map
configs.SetConfigMap(map[string]string{})
}

func TestGetConfigJSON(t *testing.T) {
Expand All @@ -510,7 +524,7 @@ func TestGetConfigJSON(t *testing.T) {
resp := &MockResponseWriter{}
getClusterConfig(resp, req)

conf := &configs.SchedulerConfig{}
conf := &dao.ConfigDAOInfo{}
err := json.Unmarshal(resp.outputBytes, conf)
assert.NilError(t, err, "failed to unmarshal config from response body (json)")
startConfSum := conf.Checksum
Expand All @@ -519,12 +533,17 @@ func TestGetConfigJSON(t *testing.T) {
// change the config
err = schedulerContext.UpdateRMSchedulerConfig(rmID, []byte(updatedConf))
assert.NilError(t, err, "Error when updating clusterInfo from config")
configs.SetConfigMap(updatedExtraConf)

getClusterConfig(resp, req)
err = json.Unmarshal(resp.outputBytes, conf)
assert.NilError(t, err, "failed to unmarshal config from response body (json, updated config)")
assert.Assert(t, startConfSum != conf.Checksum, "checksums did not change in json output: %s, %s", startConfSum, conf.Checksum)
assert.Equal(t, conf.Partitions[0].NodeSortPolicy.Type, "binpacking", "node sort policy not updated (json)")
assert.Assert(t, reflect.DeepEqual(conf.Extra, updatedExtraConf), "extra config did not change")

// reset extra config map
configs.SetConfigMap(map[string]string{})
}

func TestBuildUpdateResponseSuccess(t *testing.T) {
Expand Down

0 comments on commit 5dcfdb2

Please sign in to comment.