From de9bd68ddd47c155ca6353def3d8e124f5eb778b Mon Sep 17 00:00:00 2001 From: dhruvsgarg Date: Thu, 11 Aug 2022 15:39:18 -0400 Subject: [PATCH] Updated spec for deploymentConfig This pr updates the agentKV field of deployementConfig spec to a simple map instead of a list of maps. --- api/computes_components.partials.yml | 6 ++---- cmd/deployer/app/resource_handler.go | 13 ++----------- pkg/openapi/controller/api_computes_service.go | 6 ++---- pkg/openapi/model_deployment_config.go | 3 ++- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/api/computes_components.partials.yml b/api/computes_components.partials.yml index 9a4828c26..2ab548484 100644 --- a/api/computes_components.partials.yml +++ b/api/computes_components.partials.yml @@ -77,9 +77,7 @@ DeploymentConfig: imageLoc: type: string agentKVs: - type: array - items: - $ref: '#/components/schemas/AgentKV' + $ref: '#/components/schemas/AgentKVs' required: - jobId - imageLoc @@ -88,7 +86,7 @@ DeploymentConfig: ######################################## # Config for agents in the deployment ######################################## -AgentKV: +AgentKVs: description: Config for agents in the deployment type: object additionalProperties: diff --git a/cmd/deployer/app/resource_handler.go b/cmd/deployer/app/resource_handler.go index 50408fa85..6427571c9 100644 --- a/cmd/deployer/app/resource_handler.go +++ b/cmd/deployer/app/resource_handler.go @@ -260,17 +260,8 @@ func (r *resourceHandler) deployResources(deploymentConfig openapi.DeploymentCon } } - for _, agentKV := range deploymentConfig.AgentKVs { - // the agentKV is a map but with just one key (taskId) and one value (taskKey) - // TODO fix the api spec to have a map with multiple key:value pairs - taskIds := make([]string, len(agentKV)) - i := 0 - for k := range agentKV { - taskIds[i] = k - i++ - } - taskId := taskIds[0] - taskKey := agentKV[taskIds[0]] + for taskId := range deploymentConfig.AgentKVs { + taskKey := deploymentConfig.AgentKVs[taskId] context := map[string]string{ "imageLoc": deploymentConfig.ImageLoc, diff --git a/pkg/openapi/controller/api_computes_service.go b/pkg/openapi/controller/api_computes_service.go index 757c682e8..2e9f7c463 100644 --- a/pkg/openapi/controller/api_computes_service.go +++ b/pkg/openapi/controller/api_computes_service.go @@ -126,11 +126,9 @@ func (s *ComputesApiService) GetDeploymentConfig(ctx context.Context, computeId deploymentConfig.JobId = jobId deploymentConfig.ImageLoc = imageLoc - agentKVs := []map[string]string{} + agentKVs := map[string]string{} for _, task := range jobTasks { - agent := make(map[string]string) - agent[task.TaskId] = task.Key - agentKVs = append(agentKVs, agent) + agentKVs[task.TaskId] = task.Key } deploymentConfig.AgentKVs = agentKVs diff --git a/pkg/openapi/model_deployment_config.go b/pkg/openapi/model_deployment_config.go index 092b2f252..f86f91151 100644 --- a/pkg/openapi/model_deployment_config.go +++ b/pkg/openapi/model_deployment_config.go @@ -31,7 +31,8 @@ type DeploymentConfig struct { ImageLoc string `json:"imageLoc"` - AgentKVs []map[string]string `json:"agentKVs"` + // Config for agents in the deployment + AgentKVs map[string]string `json:"agentKVs"` } // AssertDeploymentConfigRequired checks if the required fields are not zero-ed