diff --git a/.changes/unreleased/Feature-20260629-093256.yaml b/.changes/unreleased/Feature-20260629-093256.yaml new file mode 100644 index 00000000..20f02db2 --- /dev/null +++ b/.changes/unreleased/Feature-20260629-093256.yaml @@ -0,0 +1,3 @@ +kind: Feature +body: Add Scope field on RunnerJobVariable so variables can be restricted to the init container or the main job container +time: 2026-06-29T09:32:56.728664-07:00 diff --git a/.changes/unreleased/Feature-20260629-093307.yaml b/.changes/unreleased/Feature-20260629-093307.yaml new file mode 100644 index 00000000..14289724 --- /dev/null +++ b/.changes/unreleased/Feature-20260629-093307.yaml @@ -0,0 +1,3 @@ +kind: Feature +body: Add InitCommands and InitImage fields on RunnerJob to support running an init container before the main job container +time: 2026-06-29T09:33:07.696442-07:00 diff --git a/job.go b/job.go index ae129287..94cc6633 100644 --- a/job.go +++ b/job.go @@ -71,10 +71,21 @@ type Runner struct { Status RunnerStatusTypeEnum `json:"status"` } +// RunnerJobVariableScope controls which container(s) on the job pod receive a +// variable. An empty value means the variable is available in both the init +// container and the main job container (the default). +type RunnerJobVariableScope string + +const ( + RunnerJobVariableScopeInit RunnerJobVariableScope = "init" + RunnerJobVariableScopeMain RunnerJobVariableScope = "main" +) + type RunnerJobVariable struct { - Key string `json:"key"` - Sensitive bool `json:"sensitive"` - Value string `json:"value"` + Key string `json:"key"` + Sensitive bool `json:"sensitive"` + Value string `json:"value"` + Scope RunnerJobVariableScope `json:"scope"` } type RunnerJobFile struct { @@ -83,13 +94,15 @@ type RunnerJobFile struct { } type RunnerJob struct { - Commands []string `json:"commands"` - Id ID `json:"id"` - Image string `json:"image"` - Outcome RunnerJobOutcomeEnum `json:"outcome"` - Status RunnerJobStatusEnum `json:"status"` - Variables []RunnerJobVariable `json:"variables"` - Files []RunnerJobFile `json:"files"` + Commands []string `json:"commands"` + Id ID `json:"id"` + Image string `json:"image"` + Outcome RunnerJobOutcomeEnum `json:"outcome"` + Status RunnerJobStatusEnum `json:"status"` + Variables []RunnerJobVariable `json:"variables"` + Files []RunnerJobFile `json:"files"` + InitCommands []string `json:"initCommands"` + InitImage string `json:"initImage"` } func (runnerJob *RunnerJob) Number() string { diff --git a/job_test.go b/job_test.go index c75d04f3..2eed7a01 100644 --- a/job_test.go +++ b/job_test.go @@ -58,7 +58,7 @@ func TestRunnerGetScale(t *testing.T) { func TestRunnerGetPendingJobs(t *testing.T) { // Arrange testRequest := autopilot.NewTestRequest( - `mutation RunnerGetPendingJob($id:ID!$token:ID){runnerGetPendingJob(runnerId: $id lastUpdateToken: $token){runnerJob{commands,id,image,outcome,status,variables{key,sensitive,value},files{name,contents}},lastUpdateToken,errors{message,path}}}`, + `mutation RunnerGetPendingJob($id:ID!$token:ID){runnerGetPendingJob(runnerId: $id lastUpdateToken: $token){runnerJob{commands,id,image,outcome,status,variables{key,sensitive,value,scope},files{name,contents},initCommands,initImage},lastUpdateToken,errors{message,path}}}`, `{"id":"1234567890", "token": "1234"}`, `{"data": { "runnerGetPendingJob": { @@ -75,9 +75,20 @@ func TestRunnerGetPendingJobs(t *testing.T) { "variables": [ { "key": "AWS_ACCESS_KEY", - "value": "XXXXXXX" + "value": "XXXXXXX", + "scope": "main" + }, + { + "key": "REPO_CLONE_URL", + "value": "https://token@example.com/repo.git", + "sensitive": true, + "scope": "init" } - ] + ], + "initCommands": [ + "/opslevel/clone-repo ." + ], + "initImage": "public.ecr.aws/opslevel/cli:v2022.02.25" }, "lastUpdateToken": "12344321", "errors": [] @@ -92,6 +103,10 @@ func TestRunnerGetPendingJobs(t *testing.T) { autopilot.Equals(t, "public.ecr.aws/opslevel/cli:v2022.02.25", result.Image) autopilot.Equals(t, "ls -al", result.Commands[1]) autopilot.Equals(t, ol.ID("12344321"), token) + autopilot.Equals(t, []string{"/opslevel/clone-repo ."}, result.InitCommands) + autopilot.Equals(t, "public.ecr.aws/opslevel/cli:v2022.02.25", result.InitImage) + autopilot.Equals(t, ol.RunnerJobVariableScopeMain, result.Variables[0].Scope) + autopilot.Equals(t, ol.RunnerJobVariableScopeInit, result.Variables[1].Scope) } func TestRunnerAppendJobLog(t *testing.T) {