Skip to content

Commit

Permalink
feat: added environment setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
alekc committed Jul 5, 2022
1 parent 01d060a commit 8251519
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ kind: Runner
metadata:
name: runner-sample
spec:
environment:
- "bar=foo"
concurrent: 1
log_level: info
gitlab_instance_url: https://gitlab.com
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/runner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ type RunnerSpec struct {
CheckInterval int `json:"check_interval,omitempty"`

ExecutorConfig KubernetesConfig `json:"executor_config,omitempty"`

// +kubebuilder:validation:Optional
// Environment contains custom environment variables injected to build environment
Environment []string `json:"environment,omitempty"`
}

// RunnerStatus defines the observed state of Runner
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions config/crd/bases/gitlab.k8s.alekc.dev_runners.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ spec:
concurrent:
minimum: 1
type: integer
environment:
description: Environment contains custom environment variables injected
to build environment
items:
type: string
type: array
executor_config:
properties:
affinity:
Expand Down
12 changes: 12 additions & 0 deletions controllers/runner_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ var _ = Describe("Runner controller", func() {
//
tc.CheckRunner(createdRunner)
},
table.Entry("Should support setting of env var for build env", caseEnvironmentIsSpecified),
table.Entry("Should have created a different registration on tag update", caseTagsChanged),
table.Entry("Should have created a different registration on registration token update", caseRegistrationTokenChanged),
table.Entry("Should have updated runner status with auth token", caseTestAuthToken),
Expand Down Expand Up @@ -211,6 +212,17 @@ func caseCheckDeployment(tc *testCase) {
}
}

func caseEnvironmentIsSpecified(tc *testCase) {
ctx := context.Background()
tc.Runner.Spec.Environment = []string{"foo=bar"}
tc.CheckRunner = func(runner *v1beta1.Runner) {
var deployment appsv1.Deployment
Eventually(func() bool {
return k8sClient.Get(ctx, nameSpacedDependencyName(runner), &deployment) == nil
}, timeout, interval).Should(BeTrue())
}
}

// caseTagsChanged deals with situation when we change tags for an existing runner
func caseTagsChanged(tc *testCase) {
ctx := context.Background()
Expand Down
5 changes: 3 additions & 2 deletions internal/generate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ func ConfigText(runnerObject *v1beta1.Runner) (gitlabConfig, configHashKey strin
URL: runnerObject.Spec.GitlabInstanceURL,
},
RunnerSettings: config.RunnerSettings{
Executor: "kubernetes",
Kubernetes: &runnerObject.Spec.ExecutorConfig,
Environment: runnerObject.Spec.Environment,
Executor: "kubernetes",
Kubernetes: &runnerObject.Spec.ExecutorConfig,
},
}
// set the namespace to the same one as the runner object if not declared otherwise
Expand Down

0 comments on commit 8251519

Please sign in to comment.