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

empty metadata updates result in a vague error and update infinite loop #69

Open
iomarcovalente opened this issue Nov 21, 2023 · 0 comments
Labels

Comments

@iomarcovalente
Copy link

iomarcovalente commented Nov 21, 2023

Describe the bug

For the update action if the metadata file is not changed we get a vague error:
failed to update the lock: bootstrap-terragrunt-builds-lock! (err: exit status 1) retrying...
and the task is stuck in an infinite update loop, can't even abort the pipeline.

I found that if I do change the content of the file every time it will not error out.
So I can only assume that exit status 1 is probably git erroring out during one of the git commands, likely git commit

I suggest that the code is changed to cater for that scenario.

// Check if there are any changes
status, err := glh.git("status", "--porcelain")
if err != nil {
    return "", err
}

// If there are changes, commit them
if status != "" {
    commitMessage := glh.messagePrefix() + fmt.Sprintf("%s: %s", operation, lockName)
    _, err = glh.git("commit", lockPath, "-m", commitMessage)
    if err != nil {
        return "", err
    }
}

as above, I would very naively just run commit if there are changes but there might be other parts involved that I am not aware of.

Reproduction steps

Run the following pipeline (change the lock repo accordingly), twice, to test:

meta:
  # Secrets that are populated by the global credentials manager or var_sources
  secrets:
    github_private_key: &github_private_key ((github-private-key))

resources:
  - name: terragrunt-builds-locks
    type: pool
    source:
      uri: [email protected]:<<your-repo-here>>.git
      branch: main
      pool: bootstrap-terragrunt-builds
      private_key: *github_private_key

jobs:
  - name: claim-lock
    plan:
      - in_parallel:
          fail_fast: true
          steps:
            - get: terragrunt-builds-locks
              trigger: false
              params:
                depth: 10

      - task: create-lock-info
        output_mapping:
          output: bootstrap-terragrunt-builds-lock-info
        config:
          image_resource:
            type: docker-image
            source: {repository: busybox}
          platform: linux
          outputs:
            - name: output
          run:
            path: sh
            args:
            - -cex
            - |
              WORKDIR="${PWD}"
              # create a lock-info file that contains the lock name and
              # the lock metadata for the pool resource to consume
              echo "bootstrap-terragrunt-builds-lock" > ${WORKDIR}/output/name
              echo "TEST" > ${WORKDIR}/output/metadata

      - put: terragrunt-builds-locks-update
        resource: terragrunt-builds-locks
        params:
          update: bootstrap-terragrunt-builds-lock-info

      - put: terragrunt-builds-locks-claim
        resource: terragrunt-builds-locks
        params:
          claim: bootstrap-terragrunt-builds-lock

      - put: terragrunt-builds-locks-release
        resource: terragrunt-builds-locks
        params:
          release: terragrunt-builds-locks-claim

it will succeed the first time and fail the second time.

Expected behavior

to not fail if the metadata file content is not changing

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant