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

(CODEMGMT-1294) Resync repos with unresolvable refs #1239

Merged

Conversation

jarretlavallee
Copy link

@jarretlavallee jarretlavallee commented Nov 2, 2021

Prior to this commit, if the git repo did not have a valid HEAD or the
ref was not resolvable, r10k would raise an error and fail. This commit
changes the behavior to do a forceful resync of the git repo.
This commit updates the status method for stateful git repos to return
:mismatched when the repo.head is nil. This commit updates the resolve
method for rugged base repositories to catch Rugged::OdbError, which
would have resulted in object not found - no match for id messages.
This condition would occur when the local repo was out of sync with the
upstream repo and a local commit could not be found in the upstream
repo. Since this condition indicates that the repo has diverged from the
upstream repository, this change forces a full resync of the git repo to
ensure it is in sync.

Prior to this commit, if the git repo did not have a valid HEAD or the
ref was not resolvable, r10k would raise an error and fail. This commit
changes the behavior to do a forceful resync of the git repo.
This commit updates the `status` method for stateful git repos to return
:mismatched when the repo.head is nil. This commit updates the resolve
method for rugged base repositories to catch `Rugged::OdbError`, which
would have resulted in `object not found - no match for id` messages.
This condition would occur when the local repo was out of sync with the
upstream repo and a local commit could not be found in the upstream
repo. Since this condition indicates that the repo has diverged from the
upstream repository, this change forces a full resync of the git repo to
ensure it is in sync.
@jarretlavallee jarretlavallee requested a review from a team November 2, 2021 19:22
@jarretlavallee
Copy link
Author

A simple repo:

# /etc/puppetlabs/r10k/r10k.yaml
:cachedir: '/var/cache/r10k'
git:
  provider: rugged
:sources:
  :local:
    remote: file:///opt/repos/r10k
    basedir: '/etc/puppetlabs/code/environments'
# mkdir -p /opt/repos/
# git clone https://github.com/puppetlabs/control-repo.git /opt/repos/r10k
# /opt/puppetlabs/puppet/bin/r10k deploy environment -v -p
# GIT_SEQUENCE_EDITOR='sed -i ''0,/^pick/!{s/^pick/fixup/}''' git rebase -i HEAD~2
# rm -rf /var/cache/r10k/
# /opt/puppetlabs/puppet/bin/r10k deploy environment -v debug2 -p 

With this PR, debug2 shows the Unable to resolve HEAD: object not found - no match for id and the repo is forcefully resynced: [2021-11-02 13:44:01 - DEBUG] Replacing /etc/puppetlabs/code/environments/main and checking out main

# GIT_SEQUENCE_EDITOR='sed -i ''0,/^pick/!{s/^pick/fixup/}''' git rebase -i HEAD~2
[detached HEAD 4b3b92b] Rename winscript.ps1 to win.ps1
Successfully rebased and updated refs/heads/main.
# rm -rf /var/cache/r10k/
# /opt/puppetlabs/puppet/bin/r10k deploy environment -v debug2 -p 
...
[2021-11-02 13:44:01 - DEBUG] Fetching 'file:///opt/repos/r10k' to determine current branches.
[2021-11-02 13:44:01 - DEBUG1] Creating new git cache for "file:///opt/repos/r10k"
[2021-11-02 13:44:01 - DEBUG1] Cloning 'file:///opt/repos/r10k' into /var/cache/r10k/file----opt-repos-r10k
[2021-11-02 13:44:01 - DEBUG1] Fetching remote 'origin' at /var/cache/r10k/file----opt-repos-r10k
[2021-11-02 13:44:01 - DEBUG2] Transferred 918 objects (139041 bytes) from 'origin' into /var/cache/r10k/file----opt-repos-r10k'
[2021-11-02 13:44:01 - DEBUG2] Unable to resolve HEAD: object not found - no match for id (aa9fbf40c0fa901a1a68053340a8d8b80b28177c) 
[2021-11-02 13:44:01 - INFO] Deploying environment /etc/puppetlabs/code/environments/main
[2021-11-02 13:44:01 - DEBUG2] Unable to resolve HEAD: object not found - no match for id (aa9fbf40c0fa901a1a68053340a8d8b80b28177c) 
[2021-11-02 13:44:01 - DEBUG] Replacing /etc/puppetlabs/code/environments/main and checking out main
[2021-11-02 13:44:01 - DEBUG1] Cloning 'file:///opt/repos/r10k' into /etc/puppetlabs/code/environments/main
[2021-11-02 13:44:01 - DEBUG2] Checking out ref '4b3b92bfa1c2829c14b5625a095afcc9b212a615' (resolved to SHA '4b3b92bfa1c2829c14b5625a095afcc9b212a615') in repository /etc/puppetlabs/code/environments/main
[2021-11-02 13:44:01 - INFO] Environment main is now at 4b3b92bfa1c2829c14b5625a095afcc9b212a615
[2021-11-02 13:44:01 - INFO] Using Puppetfile '/etc/puppetlabs/code/environments/main/Puppetfile'
[2021-11-02 13:44:01 - DEBUG] Using moduledir '/etc/puppetlabs/code/environments/main/modules'
[2021-11-02 13:44:01 - DEBUG] Purging unmanaged Puppetfile content for environment 'main'...
[2021-11-02 13:44:01 - DEBUG1] No unmanaged contents in , nothing to purge
[2021-11-02 13:44:01 - DEBUG] Purging unmanaged environments for deployment...
[2021-11-02 13:44:01 - DEBUG1] Fetching remote 'origin' at /var/cache/r10k/file----opt-repos-r10k
[2021-11-02 13:44:01 - DEBUG2] Transferred 0 objects (0 bytes) from 'origin' into /var/cache/r10k/file----opt-repos-r10k'
[2021-11-02 13:44:01 - DEBUG1] Source local in /etc/puppetlabs/code/environments manages contents ["main"]
[2021-11-02 13:44:01 - DEBUG1] No unmanaged contents in /etc/puppetlabs/code/environments, nothing to purge

@justinstoller justinstoller merged commit c80c3c2 into puppetlabs:main Nov 3, 2021
@jarretlavallee jarretlavallee deleted the CODEMGMT_1294_id_not_found branch November 3, 2021 16:08
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.

2 participants