From 87a472aaaff2d851aa5e948e08dd1308bd377314 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Wed, 3 Jul 2019 15:16:37 +0200 Subject: [PATCH] runservice: add CacheGroup field to runconfig The cache group fields defines under which cache group the run cache data will belong. This is needed/useful for some next changes: * Make cache correctly work for user direct runs. Since the user direct runs all belong to the same run group (the user id) all the use direct runs will share the same caches. To distinguish between the different caches we need to use something in addition to the user id (the local repo uuid generated by the direct run start command) * Share the cache between multiple projects --- internal/services/runservice/action/action.go | 2 ++ internal/services/runservice/api/api.go | 2 ++ internal/services/runservice/scheduler.go | 7 ++++++- internal/services/runservice/types/types.go | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/services/runservice/action/action.go b/internal/services/runservice/action/action.go index 024a574..34c0609 100644 --- a/internal/services/runservice/action/action.go +++ b/internal/services/runservice/action/action.go @@ -135,6 +135,7 @@ type RunCreateRequest struct { Group string SetupErrors []string StaticEnvironment map[string]string + CacheGroup string // existing run fields RunID string @@ -210,6 +211,7 @@ func (h *ActionHandler) newRun(ctx context.Context, req *RunCreateRequest) (*typ StaticEnvironment: req.StaticEnvironment, Environment: req.Environment, Annotations: req.Annotations, + CacheGroup: req.CacheGroup, } run := genRun(rc) diff --git a/internal/services/runservice/api/api.go b/internal/services/runservice/api/api.go index 79bbf44..33f8219 100644 --- a/internal/services/runservice/api/api.go +++ b/internal/services/runservice/api/api.go @@ -515,6 +515,7 @@ type RunCreateRequest struct { Group string `json:"group"` SetupErrors []string `json:"setup_errors"` StaticEnvironment map[string]string `json:"static_environment"` + CacheGroup string `json:"cache_group"` // existing run fields RunID string `json:"run_id"` @@ -556,6 +557,7 @@ func (h *RunCreateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { Group: req.Group, SetupErrors: req.SetupErrors, StaticEnvironment: req.StaticEnvironment, + CacheGroup: req.CacheGroup, RunID: req.RunID, FromStart: req.FromStart, diff --git a/internal/services/runservice/scheduler.go b/internal/services/runservice/scheduler.go index a149ac1..23e9106 100644 --- a/internal/services/runservice/scheduler.go +++ b/internal/services/runservice/scheduler.go @@ -335,6 +335,11 @@ func (s *Runservice) genExecutorTask(ctx context.Context, r *types.Run, rt *type // run config Environment variables ovverride every other environment variable mergeEnv(environment, rc.Environment) + cachePrefix := store.OSTRootGroup(r.Group) + if rc.CacheGroup != "" { + cachePrefix = rc.CacheGroup + } + et := &types.ExecutorTask{ // The executorTask ID must be the same as the runTask ID so we can detect if // there's already an executorTask scheduled for that run task and we can get @@ -349,7 +354,7 @@ func (s *Runservice) genExecutorTask(ctx context.Context, r *types.Run, rt *type Shell: rct.Shell, User: rct.User, Steps: rct.Steps, - CachePrefix: store.OSTRootGroup(r.Group), + CachePrefix: cachePrefix, Status: types.ExecutorTaskStatus{ Phase: types.ExecutorTaskPhaseNotStarted, Steps: make([]*types.ExecutorTaskStepStatus, len(rct.Steps)), diff --git a/internal/services/runservice/types/types.go b/internal/services/runservice/types/types.go index d670824..3acda1f 100644 --- a/internal/services/runservice/types/types.go +++ b/internal/services/runservice/types/types.go @@ -306,6 +306,9 @@ type RunConfig struct { Environment map[string]string `json:"environment,omitempty"` Tasks map[string]*RunConfigTask `json:"tasks,omitempty"` + + // CacheGroup is the cache group where the run caches belongs + CacheGroup string `json:"cache_group,omitempty"` } func (rc *RunConfig) DeepCopy() *RunConfig {