Skip to content

Commit

Permalink
feat(runner): expose imagepullpolicy as a config option
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan-pad committed Apr 25, 2024
1 parent 53da2ce commit d3bbdae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
9 changes: 9 additions & 0 deletions api/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
type OverrideRunnerSpec struct {
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
Image string `json:"image,omitempty"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
Expand Down Expand Up @@ -94,6 +95,7 @@ func GetOverrideRunnerSpec(repository *TerraformRepository, layer *TerraformLaye
Resources: mergeResources(repository.Spec.OverrideRunnerSpec.Resources, layer.Spec.OverrideRunnerSpec.Resources),
EnvFrom: mergeEnvFrom(repository.Spec.OverrideRunnerSpec.EnvFrom, layer.Spec.OverrideRunnerSpec.EnvFrom),
Image: chooseString(repository.Spec.OverrideRunnerSpec.Image, layer.Spec.OverrideRunnerSpec.Image),
ImagePullPolicy: chooseImagePullPolicy(repository.Spec.OverrideRunnerSpec.ImagePullPolicy, layer.Spec.OverrideRunnerSpec.ImagePullPolicy),
ServiceAccountName: chooseString(repository.Spec.OverrideRunnerSpec.ServiceAccountName, layer.Spec.OverrideRunnerSpec.ServiceAccountName),
ImagePullSecrets: mergeImagePullSecrets(repository.Spec.OverrideRunnerSpec.ImagePullSecrets, layer.Spec.OverrideRunnerSpec.ImagePullSecrets),
}
Expand Down Expand Up @@ -143,6 +145,13 @@ func chooseString(a, b string) string {
return a
}

func chooseImagePullPolicy(a, b corev1.PullPolicy) corev1.PullPolicy {
if b != "" {
return b
}
return a
}

func chooseInt(a, b *int, d int) *int {
if b != nil {
return b
Expand Down
6 changes: 6 additions & 0 deletions deploy/charts/burrito/templates/rbac-runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ rules:
verbs:
- get
- patch
- apiGroups:
- config.terraform.padok.cloud
resources:
- terraformruns
verbs:
- get
- apiGroups:
- config.terraform.padok.cloud
resources:
Expand Down
8 changes: 5 additions & 3 deletions internal/controllers/terraformrun/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func (r *Reconciler) getPod(run *configv1alpha1.TerraformRun, layer *configv1alp
defaultSpec.Containers[0].Resources = overrideSpec.Resources
defaultSpec.Containers[0].EnvFrom = append(defaultSpec.Containers[0].EnvFrom, overrideSpec.EnvFrom...)
defaultSpec.ImagePullSecrets = append(defaultSpec.ImagePullSecrets, overrideSpec.ImagePullSecrets...)
defaultSpec.Containers[0].ImagePullPolicy = overrideSpec.ImagePullPolicy

if len(overrideSpec.ServiceAccountName) > 0 {
defaultSpec.ServiceAccountName = overrideSpec.ServiceAccountName
Expand Down Expand Up @@ -261,9 +262,10 @@ func defaultPodSpec(config *config.Config, layer *configv1alpha1.TerraformLayer,
ServiceAccountName: "burrito-runner",
Containers: []corev1.Container{
{
Name: "runner",
Image: fmt.Sprintf("ghcr.io/padok-team/burrito:%s", version.Version),
Args: []string{"runner", "start"},
Name: "runner",
Image: fmt.Sprintf("ghcr.io/padok-team/burrito:%s", version.Version),
ImagePullPolicy: corev1.PullIfNotPresent,
Args: []string{"runner", "start"},
VolumeMounts: []corev1.VolumeMount{
{
MountPath: "/home/burrito/.ssh/known_hosts",
Expand Down

0 comments on commit d3bbdae

Please sign in to comment.