Skip to content

Commit 8251519

Browse files
committed
feat: added environment setup.
1 parent 01d060a commit 8251519

File tree

6 files changed

+32
-2
lines changed

6 files changed

+32
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ kind: Runner
3131
metadata:
3232
name: runner-sample
3333
spec:
34+
environment:
35+
- "bar=foo"
3436
concurrent: 1
3537
log_level: info
3638
gitlab_instance_url: https://gitlab.com

api/v1beta1/runner_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ type RunnerSpec struct {
4545
CheckInterval int `json:"check_interval,omitempty"`
4646

4747
ExecutorConfig KubernetesConfig `json:"executor_config,omitempty"`
48+
49+
// +kubebuilder:validation:Optional
50+
// Environment contains custom environment variables injected to build environment
51+
Environment []string `json:"environment,omitempty"`
4852
}
4953

5054
// RunnerStatus defines the observed state of Runner

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/gitlab.k8s.alekc.dev_runners.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ spec:
4242
concurrent:
4343
minimum: 1
4444
type: integer
45+
environment:
46+
description: Environment contains custom environment variables injected
47+
to build environment
48+
items:
49+
type: string
50+
type: array
4551
executor_config:
4652
properties:
4753
affinity:

controllers/runner_controller_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ var _ = Describe("Runner controller", func() {
134134
//
135135
tc.CheckRunner(createdRunner)
136136
},
137+
table.Entry("Should support setting of env var for build env", caseEnvironmentIsSpecified),
137138
table.Entry("Should have created a different registration on tag update", caseTagsChanged),
138139
table.Entry("Should have created a different registration on registration token update", caseRegistrationTokenChanged),
139140
table.Entry("Should have updated runner status with auth token", caseTestAuthToken),
@@ -211,6 +212,17 @@ func caseCheckDeployment(tc *testCase) {
211212
}
212213
}
213214

215+
func caseEnvironmentIsSpecified(tc *testCase) {
216+
ctx := context.Background()
217+
tc.Runner.Spec.Environment = []string{"foo=bar"}
218+
tc.CheckRunner = func(runner *v1beta1.Runner) {
219+
var deployment appsv1.Deployment
220+
Eventually(func() bool {
221+
return k8sClient.Get(ctx, nameSpacedDependencyName(runner), &deployment) == nil
222+
}, timeout, interval).Should(BeTrue())
223+
}
224+
}
225+
214226
// caseTagsChanged deals with situation when we change tags for an existing runner
215227
func caseTagsChanged(tc *testCase) {
216228
ctx := context.Background()

internal/generate/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ func ConfigText(runnerObject *v1beta1.Runner) (gitlabConfig, configHashKey strin
2121
URL: runnerObject.Spec.GitlabInstanceURL,
2222
},
2323
RunnerSettings: config.RunnerSettings{
24-
Executor: "kubernetes",
25-
Kubernetes: &runnerObject.Spec.ExecutorConfig,
24+
Environment: runnerObject.Spec.Environment,
25+
Executor: "kubernetes",
26+
Kubernetes: &runnerObject.Spec.ExecutorConfig,
2627
},
2728
}
2829
// set the namespace to the same one as the runner object if not declared otherwise

0 commit comments

Comments
 (0)