Skip to content

Commit

Permalink
fix(runner): run wasn't initialized leading to panic
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan-pad committed Apr 24, 2024
1 parent 45528ab commit 53da2ce
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/burrito/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type RepositoryConfig struct {
type RunnerConfig struct {
Action string `mapstructure:"action"`
Layer Layer `mapstructure:"layer"`
RunID string `mapstructure:"id"`
Run string `mapstructure:"run"`
Repository RepositoryConfig `mapstructure:"repository"`
SSHKnownHostsConfigMapName string `mapstructure:"sshKnownHostsConfigMapName"`
RunnerBinaryPath string `mapstructure:"runnerBinaryPath"`
Expand Down
12 changes: 8 additions & 4 deletions internal/controllers/terraformrun/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (r *Reconciler) ensureHermitcrabSecret(tenantNamespace string) error {
}

func (r *Reconciler) getPod(run *configv1alpha1.TerraformRun, layer *configv1alpha1.TerraformLayer, repository *configv1alpha1.TerraformRepository) corev1.Pod {
defaultSpec := defaultPodSpec(r.Config, layer, repository)
defaultSpec := defaultPodSpec(r.Config, layer, repository, run)

if r.Config.Hermitcrab.Enabled {
err := r.ensureHermitcrabSecret(layer.Namespace)
Expand Down Expand Up @@ -226,7 +226,7 @@ func mergeMaps(a, b map[string]string) map[string]string {
return result
}

func defaultPodSpec(config *config.Config, layer *configv1alpha1.TerraformLayer, repository *configv1alpha1.TerraformRepository) corev1.PodSpec {
func defaultPodSpec(config *config.Config, layer *configv1alpha1.TerraformLayer, repository *configv1alpha1.TerraformRepository, run *configv1alpha1.TerraformRun) corev1.PodSpec {
return corev1.PodSpec{
Volumes: []corev1.Volume{
{
Expand Down Expand Up @@ -294,11 +294,15 @@ func defaultPodSpec(config *config.Config, layer *configv1alpha1.TerraformLayer,
},
{
Name: "BURRITO_RUNNER_LAYER_NAME",
Value: layer.GetObjectMeta().GetName(),
Value: layer.Name,
},
{
Name: "BURRITO_RUNNER_LAYER_NAMESPACE",
Value: layer.GetObjectMeta().GetNamespace(),
Value: layer.Namespace,
},
{
Name: "BURRITO_RUNNER_RUN",
Value: run.Name,
},
{
Name: "SSH_KNOWN_HOSTS",
Expand Down
14 changes: 12 additions & 2 deletions internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (r *Runner) Exec() error {
return err
}

func (r *Runner) getLayerAndRepository() error {
func (r *Runner) getResources() error {
layer := &configv1alpha1.TerraformLayer{}
log.Infof("getting layer %s/%s", r.config.Runner.Layer.Namespace, r.config.Runner.Layer.Name)
err := r.client.Get(context.TODO(), types.NamespacedName{
Expand All @@ -118,6 +118,16 @@ func (r *Runner) getLayerAndRepository() error {
}
log.Infof("successfully retrieved layer")
r.layer = layer
r.run = &configv1alpha1.TerraformRun{}
log.Infof("getting run %s/%s", layer.Namespace, layer.Status.LastRun.Name)
err = r.client.Get(context.TODO(), types.NamespacedName{
Namespace: layer.Namespace,
Name: r.config.Runner.Run,
}, r.run)
if err != nil {
return err
}
log.Infof("successfully retrieved run")
repository := &configv1alpha1.TerraformRepository{}
log.Infof("getting repo %s/%s", layer.Spec.Repository.Namespace, layer.Spec.Repository.Name)
err = r.client.Get(context.TODO(), types.NamespacedName{
Expand Down Expand Up @@ -175,7 +185,7 @@ func (r *Runner) init() error {
return err
}
r.client = cl
err = r.getLayerAndRepository()
err = r.getResources()
if err != nil {
log.Errorf("error getting kubernetes resources: %s", err)
return err
Expand Down

0 comments on commit 53da2ce

Please sign in to comment.