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

fix(templates): prevent nil panic #1194

Merged
merged 1 commit into from
Sep 26, 2024
Merged

fix(templates): prevent nil panic #1194

merged 1 commit into from
Sep 26, 2024

Conversation

wass3rw3rk
Copy link
Member

@wass3rw3rk wass3rw3rk commented Sep 26, 2024

when referencing a template that defines a global environment, but the base pipeline doesn't, pipeline.Environment will be nil as its zero value. when the template is parsed and attempting to set the global environment we currently cause a assignment to entry in nil map error. this fix initializes an empty environment.

test case:

.vela.yml:

version: "1"

metadata:
  render_inline: true

templates:
  - name: nil-panic
    source: .nil-panic.yml
    format: go
    type: file
    vars:
      foo: bar

.nil-panic.yml:

metadata:
  template: true

environment:
  foo: "bar"

stages:
  vendor:
    steps:
      - name: test
        image: alpine
        commands:
          - echo hello

workaround is to define environment: {} at the top level in the base pipeline .vela.yml

@wass3rw3rk wass3rw3rk requested a review from a team as a code owner September 26, 2024 19:09
Copy link

codecov bot commented Sep 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.05%. Comparing base (2960513) to head (ab73c2b).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1194   +/-   ##
=======================================
  Coverage   53.04%   53.05%           
=======================================
  Files         559      559           
  Lines       19743    19747    +4     
=======================================
+ Hits        10473    10477    +4     
  Misses       8701     8701           
  Partials      569      569           
Files with missing lines Coverage Δ
compiler/native/parse.go 87.09% <100.00%> (+0.57%) ⬆️

@wass3rw3rk wass3rw3rk merged commit 609f960 into main Sep 26, 2024
13 of 16 checks passed
@wass3rw3rk wass3rw3rk deleted the fix/templates/nil-panic branch September 26, 2024 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants