Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set default runner image in global config #371

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/controllers/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"time"

"github.com/padok-team/burrito/internal/burrito"
"github.com/padok-team/burrito/internal/version"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
)

func buildControllersStartCmd(app *burrito.App) *cobra.Command {
Expand Down Expand Up @@ -41,5 +43,8 @@ func buildControllersStartCmd(app *burrito.App) *cobra.Command {
cmd.Flags().StringVar(&app.Config.Controller.HealthProbeBindAddress, "health-probe-bind-address", ":8081", "address to bind the metrics server embedded in the controllers")
cmd.Flags().StringVar(&app.Config.Controller.MetricsBindAddress, "metrics-bind-address", ":8080", "address to bind the health probe server embedded in the controllers")
cmd.Flags().IntVar(&app.Config.Controller.KubernetesWebhookPort, "kubernetes-webhook-port", 9443, "port used by the validating webhook server embedded in the controllers")
cmd.Flags().StringVar(&app.Config.Runner.Image.Repository, "runner-image-repository", "ghcr.io/padok-team/burrito-runner", "Repository of the image to use for the runner pods created by the controller")
cmd.Flags().StringVar(&app.Config.Runner.Image.Tag, "runner-image-tag", version.Version, "Tag of the image to use for the runner pods created by the controller")
cmd.Flags().StringVar(&app.Config.Runner.Image.PullPolicy, "runner-image-pull-policy", string(corev1.PullIfNotPresent), "Pull policy of the image to use for the runner pods created by the controller")
Comment on lines +46 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary to expose those options as CLI flags?
If I remember correctly, not every config option is exposed as a flag in Burrito

return cmd
}
6 changes: 6 additions & 0 deletions deploy/charts/burrito/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ TLS certificates
{{- $_ := set $config.datastore "certificateSecretName" .Values.datastore.tls.secretName }}
{{- end }}

{{/*
Runner
*/}}
{{ if eq .Values.config.burrito.runner.image.tag "" }}
{{- $_ := set $config.runner.image "tag" .Chart.AppVersion }}
{{- end }}

apiVersion: v1
kind: ConfigMap
Expand Down
5 changes: 5 additions & 0 deletions deploy/charts/burrito/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ config:
runner:
# -- Configmap name to store the SSH known hosts in the runner
sshKnownHostsConfigMapName: burrito-ssh-known-hosts
image:
# -- Default image to use for runners, can be overriden with spec.OverrideRunnerSpec in repositories and layer definitions
repository: ghcr.io/padok-team/burrito
tag: "" # By default use Chart's appVersion
pullPolicy: Always

hermitcrab:
# -- Enable/Disable Hermitcrab (terraform provider cache in cluster)
Expand Down
7 changes: 7 additions & 0 deletions internal/burrito/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,17 @@ type RunnerConfig struct {
Run string `mapstructure:"run"`
Repository RepositoryConfig `mapstructure:"repository"`
SSHKnownHostsConfigMapName string `mapstructure:"sshKnownHostsConfigMapName"`
Image ImageConfig `mapstructure:"image"`
RunnerBinaryPath string `mapstructure:"runnerBinaryPath"`
RepositoryPath string `mapstructure:"repositoryPath"`
}

type ImageConfig struct {
Repository string `mapstructure:"repository"`
Tag string `mapstructure:"tag"`
PullPolicy string `mapstructure:"pullPolicy"`
}

type Layer struct {
Name string `mapstructure:"name"`
Namespace string `mapstructure:"namespace"`
Expand Down
13 changes: 13 additions & 0 deletions internal/burrito/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func TestConfig_FromYamlFile(t *testing.T) {
Name: "test",
Namespace: "default",
},
Image: config.ImageConfig{
Repository: "test-repository",
Tag: "test-tag",
PullPolicy: "Always",
},
Repository: config.RepositoryConfig{
SSHPrivateKey: "private-key",
Username: "test",
Expand Down Expand Up @@ -130,6 +135,9 @@ func TestConfig_EnvVarOverrides(t *testing.T) {
setEnvVar(t, "BURRITO_RUNNER_REPOSITORY_USERNAME", "other-username", &envVarList)
setEnvVar(t, "BURRITO_RUNNER_REPOSITORY_PASSWORD", "other-password", &envVarList)
setEnvVar(t, "BURRITO_RUNNER_REPOSITORY_SSHPRIVATEKEY", "other-private-key", &envVarList)
setEnvVar(t, "BURRITO_RUNNER_IMAGE_REPOSITORY", "other-repository", &envVarList)
setEnvVar(t, "BURRITO_RUNNER_IMAGE_TAG", "other-tag", &envVarList)
setEnvVar(t, "BURRITO_RUNNER_IMAGE_PULLPOLICY", "Always", &envVarList)
// Controller
setEnvVar(t, "BURRITO_CONTROLLER_TYPES", "layer,repository", &envVarList)
setEnvVar(t, "BURRITO_CONTROLLER_NAMESPACES", "default,burrito,other", &envVarList)
Expand Down Expand Up @@ -176,6 +184,11 @@ func TestConfig_EnvVarOverrides(t *testing.T) {
Name: "other-layer",
Namespace: "other-namespace",
},
Image: config.ImageConfig{
Repository: "other-repository",
Tag: "other-tag",
PullPolicy: "Always",
},
Repository: config.RepositoryConfig{
SSHPrivateKey: "other-private-key",
Username: "other-username",
Expand Down
4 changes: 4 additions & 0 deletions internal/burrito/config/testdata/test-config-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ runner:
layer:
name: test
namespace: default
image:
repository: test-repository
tag: test-tag
pullPolicy: Always
repository:
sshPrivateKey: "private-key"
username: "test"
Expand Down
5 changes: 2 additions & 3 deletions internal/controllers/terraformrun/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

configv1alpha1 "github.com/padok-team/burrito/api/v1alpha1"
"github.com/padok-team/burrito/internal/burrito/config"
"github.com/padok-team/burrito/internal/version"
log "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -284,8 +283,8 @@ func defaultPodSpec(config *config.Config, layer *configv1alpha1.TerraformLayer,
Containers: []corev1.Container{
{
Name: "runner",
Image: fmt.Sprintf("ghcr.io/padok-team/burrito:%s", version.Version),
ImagePullPolicy: corev1.PullIfNotPresent,
Image: fmt.Sprintf("%s:%s", config.Runner.Image.Repository, config.Runner.Image.Tag),
ImagePullPolicy: corev1.PullPolicy(config.Runner.Image.PullPolicy),
Args: []string{"runner", "start"},
VolumeMounts: []corev1.VolumeMount{
{
Expand Down