Skip to content

Commit 235a7e0

Browse files
feat(runner): allow command+args override (#594)
Signed-off-by: Michael Todorovic <[email protected]>
1 parent 94235b4 commit 235a7e0

File tree

13 files changed

+140
-4
lines changed

13 files changed

+140
-4
lines changed

api/v1alpha1/common.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type OverrideRunnerSpec struct {
2626
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`
2727
Metadata MetadataOverride `json:"metadata,omitempty"`
2828
InitContainers []corev1.Container `json:"initContainers,omitempty"`
29+
Command []string `json:"command,omitempty"`
30+
Args []string `json:"args,omitempty"`
2931
ExtraInitArgs ExtraArgs `json:"extraInitArgs,omitempty"`
3032
ExtraPlanArgs ExtraArgs `json:"extraPlanArgs,omitempty"`
3133
ExtraApplyArgs ExtraArgs `json:"extraApplyArgs,omitempty"`
@@ -114,6 +116,8 @@ func GetOverrideRunnerSpec(repository *TerraformRepository, layer *TerraformLaye
114116
ServiceAccountName: chooseString(repository.Spec.OverrideRunnerSpec.ServiceAccountName, layer.Spec.OverrideRunnerSpec.ServiceAccountName),
115117
ImagePullSecrets: mergeImagePullSecrets(repository.Spec.OverrideRunnerSpec.ImagePullSecrets, layer.Spec.OverrideRunnerSpec.ImagePullSecrets),
116118
InitContainers: MergeInitContainers(repository.Spec.OverrideRunnerSpec.InitContainers, layer.Spec.OverrideRunnerSpec.InitContainers),
119+
Command: ChooseSlice(repository.Spec.OverrideRunnerSpec.Command, layer.Spec.OverrideRunnerSpec.Command),
120+
Args: ChooseSlice(repository.Spec.OverrideRunnerSpec.Args, layer.Spec.OverrideRunnerSpec.Args),
117121
ExtraInitArgs: overrideExtraArgs(repository.Spec.OverrideRunnerSpec.ExtraInitArgs, layer.Spec.OverrideRunnerSpec.ExtraInitArgs),
118122
ExtraPlanArgs: overrideExtraArgs(repository.Spec.OverrideRunnerSpec.ExtraPlanArgs, layer.Spec.OverrideRunnerSpec.ExtraPlanArgs),
119123
ExtraApplyArgs: overrideExtraArgs(repository.Spec.OverrideRunnerSpec.ExtraApplyArgs, layer.Spec.OverrideRunnerSpec.ExtraApplyArgs),
@@ -172,6 +176,13 @@ func chooseInt(a, b *int, d int) *int {
172176
return &d
173177
}
174178

179+
func ChooseSlice(a, b []string) []string {
180+
if len(b) > 0 {
181+
return b
182+
}
183+
return a
184+
}
185+
175186
func mergeImagePullSecrets(a, b []corev1.LocalObjectReference) []corev1.LocalObjectReference {
176187
result := []corev1.LocalObjectReference{}
177188
temp := map[string]string{}

api/v1alpha1/common_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,3 +2457,58 @@ func TestMergeInitContainers(t *testing.T) {
24572457
})
24582458
}
24592459
}
2460+
2461+
func TestChooseSlice(t *testing.T) {
2462+
tt := []struct {
2463+
name string
2464+
sliceA []string
2465+
sliceB []string
2466+
expected []string
2467+
}{
2468+
{
2469+
"EmptySlices",
2470+
[]string{},
2471+
[]string{},
2472+
[]string{},
2473+
},
2474+
{
2475+
"OnlySliceA",
2476+
[]string{"value1", "value2"},
2477+
[]string{},
2478+
[]string{"value1", "value2"},
2479+
},
2480+
{
2481+
"OnlySliceB",
2482+
[]string{},
2483+
[]string{"value3", "value4"},
2484+
[]string{"value3", "value4"},
2485+
},
2486+
{
2487+
"BothSlicesWithValues_ShouldPreferB",
2488+
[]string{"value1", "value2"},
2489+
[]string{"value3", "value4"},
2490+
[]string{"value3", "value4"},
2491+
},
2492+
{
2493+
"SliceAWithValues_SliceBEmpty",
2494+
[]string{"value1", "value2"},
2495+
[]string{},
2496+
[]string{"value1", "value2"},
2497+
},
2498+
{
2499+
"SliceAEmpty_SliceBWithValues",
2500+
[]string{},
2501+
[]string{"value3", "value4"},
2502+
[]string{"value3", "value4"},
2503+
},
2504+
}
2505+
2506+
for _, tc := range tt {
2507+
t.Run(tc.name, func(t *testing.T) {
2508+
result := configv1alpha1.ChooseSlice(tc.sliceA, tc.sliceB)
2509+
if !reflect.DeepEqual(result, tc.expected) {
2510+
t.Errorf("expected slice %v but got %v", tc.expected, result)
2511+
}
2512+
})
2513+
}
2514+
}

api/v1alpha1/zz_generated.deepcopy.go

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

deploy/charts/burrito/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ A Helm chart for handling a complete burrito deployment
3737
| config.burrito.datastore.storage.s3.bucket | string | `""` | S3 bucket name |
3838
| config.burrito.hermitcrab | object | `{}` | Provider cache custom configuration |
3939
| config.burrito.runner.sshKnownHostsConfigMapName | string | `"burrito-ssh-known-hosts"` | Configmap name to store the SSH known hosts in the runner |
40+
| config.burrito.runner.args | list | `["runner", "start"]` | Override the default args for the runner container |
41+
| config.burrito.runner.command | list | `["burrito"]` | Override the default command for the runner container |
4042
| config.burrito.server.addr | string | `":8080"` | Server exposed port |
4143
| config.burrito.server.webhook.github.secret | string | `""` | Secret to validate webhook payload, prefer override with the BURRITO_SERVER_WEBHOOK_GITHUB_SECRET environment variable |
4244
| config.burrito.server.webhook.gitlab.secret | string | `""` | Secret to validate webhook payload, Prefer override with the BURRITO_SERVER_WEBHOOK_GITLAB_SECRET environment variable |

deploy/charts/burrito/values-debug.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ config:
55
repository: burrito
66
tag: DEV_TAG
77
pullPolicy: Never
8+
# command: ["/usr/local/bin/dlv"]
9+
# args: ["--listen=0.0.0.0:2346", "--headless=true", "--accept-multiclient", "--api-version=2", "--log", "exec", "/usr/local/bin/burrito", "runner", "start"]
810
datastore:
911
storage:
1012
mock: true

deploy/charts/burrito/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ config:
8686
repository: ghcr.io/padok-team/burrito
8787
tag: "" # By default use Chart's appVersion
8888
pullPolicy: Always
89+
90+
# -- Command to run in the Burrito runner container
91+
command: ["burrito"]
92+
# -- Arguments to pass to the Burrito runner container
93+
args: ["runner", "start"]
8994

9095
hermitcrab:
9196
# -- Enable/Disable Hermitcrab (terraform provider cache in cluster)

docs/contributing.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,15 @@ First, being by installing dlv: `go install github.com/go-delve/delve/cmd/dlv@la
201201
202202
We'll rely on `deploy/charts/burrito/values-debug.yaml` to deploy the configuration to start the debugging session.
203203

204-
By default, the `controller` (that includes the runner) and `datastore` are commented in the Helm values. Indeed, starting the application with dlv server will hang until you connect with the dlv client so it has to be enabled only when you need it.
204+
By default, the different component debug configs are commented in the Helm values. Indeed, starting the application with dlv server will hang until you connect with the dlv client so it has to be enabled only when you need it.
205205

206206
```yaml
207+
# config:
208+
# burrito:
209+
# runner:
210+
# command: ["/usr/local/bin/dlv"]
211+
# args: ["--listen=0.0.0.0:2346", "--headless=true", "--accept-multiclient", "--api-version=2", "--log", "exec", "/usr/local/bin/burrito", "runner", "start"]
212+
207213
# controllers:
208214
# deployment:
209215
# mode: Debug
@@ -223,6 +229,12 @@ By default, the `controller` (that includes the runner) and `datastore` are comm
223229
# args: ["--listen=0.0.0.0:2348", "--headless=true", "--accept-multiclient", "--api-version=2", "--log", "exec", "/usr/local/bin/burrito", "server", "start"]
224230
```
225231

232+
!!! note
233+
The runner command+args override isn't under `runner.deployment` as other components as it's not a k8s deployment
234+
235+
!!! tip
236+
You can also launch burrito with the debug build and override command+args in `overrideRunnerSpec` in a specific layer you'd like to debug.
237+
226238
By default, we'll start the application with the usual command. If you want to debug the controller or the runner, uncomment the required block. This will open a port on the pod on which you'll connect from your computer.
227239
228240
`mode: Debug` is removing liveness and readiness probes: they won't be able to start as dlv will await for you to start the debugging session.
@@ -258,7 +270,7 @@ kubectl port-forward $(kubectl get pods -n burrito-system | awk '/burrito-contro
258270
- For the runner:
259271
260272
```bash
261-
kubectl port-forward -n burrito-project <layerName> 2346:2345
273+
kubectl port-forward -n burrito-project <layerName> 2346:2346
262274
```
263275
264276
It will listen on the same port than the controller so we're exposing it on port 2346 on your computer so you can debug the controller and the runner if needed.

docs/user-guide/override-runner.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ If the field is specified for a given `TerraformLayer` it will take precedence o
1313
Available overrides are:
1414

1515
| Fields |
16-
| :--------------------: |
16+
|:----------------------:|
1717
| `Affinity` |
18+
| `Args` |
19+
| `Command` |
1820
| `ImagePullSecrets` |
1921
| `Image` |
2022
| `InitContainers` |

internal/burrito/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ type RunnerConfig struct {
126126
Image ImageConfig `mapstructure:"image"`
127127
RunnerBinaryPath string `mapstructure:"runnerBinaryPath"`
128128
RepositoryPath string `mapstructure:"repositoryPath"`
129+
Args []string `mapstructure:"args"`
130+
Command []string `mapstructure:"command"`
129131
}
130132

131133
type ImageConfig struct {

internal/controllers/terraformrun/pod.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ func (r *Reconciler) getPod(run *configv1alpha1.TerraformRun, layer *configv1alp
263263

264264
defaultSpec.Tolerations = overrideSpec.Tolerations
265265
defaultSpec.Affinity = overrideSpec.Affinity
266+
defaultSpec.Containers[0].Args = configv1alpha1.ChooseSlice(defaultSpec.Containers[0].Args, overrideSpec.Args)
267+
defaultSpec.Containers[0].Command = configv1alpha1.ChooseSlice(defaultSpec.Containers[0].Command, overrideSpec.Command)
266268
defaultSpec.NodeSelector = overrideSpec.NodeSelector
267269
defaultSpec.Containers[0].Env = append(defaultSpec.Containers[0].Env, overrideSpec.Env...)
268270
defaultSpec.InitContainers = overrideSpec.InitContainers
@@ -369,7 +371,8 @@ func defaultPodSpec(config *config.Config, layer *configv1alpha1.TerraformLayer,
369371
Name: "runner",
370372
Image: fmt.Sprintf("%s:%s", config.Runner.Image.Repository, config.Runner.Image.Tag),
371373
ImagePullPolicy: corev1.PullPolicy(config.Runner.Image.PullPolicy),
372-
Args: []string{"runner", "start"},
374+
Args: config.Runner.Args,
375+
Command: config.Runner.Command,
373376
VolumeMounts: []corev1.VolumeMount{
374377
{
375378
MountPath: "/home/burrito/.ssh/known_hosts",

0 commit comments

Comments
 (0)