diff --git a/pkg/webservice/dao/config_info.go b/pkg/webservice/dao/config_info.go index a0c5c1283..44dbb3bcb 100644 --- a/pkg/webservice/dao/config_info.go +++ b/pkg/webservice/dao/config_info.go @@ -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"` +} diff --git a/pkg/webservice/handlers.go b/pkg/webservice/handlers.go index dd51f49e9..34d177f8f 100644 --- a/pkg/webservice/handlers.go +++ b/pkg/webservice/handlers.go @@ -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) diff --git a/pkg/webservice/handlers_test.go b/pkg/webservice/handlers_test.go index d7f8eedc3..0ab38ed2b 100644 --- a/pkg/webservice/handlers_test.go +++ b/pkg/webservice/handlers_test.go @@ -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 @@ -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") @@ -492,6 +500,8 @@ 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) @@ -499,6 +509,10 @@ func TestGetConfigYAML(t *testing.T) { 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) { @@ -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 @@ -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) {