xorpaul/g10k

"branch => control_branch" module parameter is not working

pmuller opened this issue · 2 comments

Test environment

  • configuration:
$ cat config.yaml 
cachedir: ./cache
sources:
  control:
    remote: https://github.com/pmuller/puppet-control-dummy.git
    basedir: ./build

r10k works as expected

$ r10k deploy -c config.yaml environment -p -v
INFO	 -> Using Puppetfile 'build/bar/Puppetfile'
INFO	 -> Using Puppetfile 'build/develop/Puppetfile'
INFO	 -> Using Puppetfile 'build/foo/Puppetfile'
INFO	 -> Using Puppetfile 'build/master/Puppetfile'
INFO	 -> Deploying environment build/bar
INFO	 -> Environment bar is now at 6525d012383d951fb9c17df2dd01db8010d50a79
INFO	 -> Deploying Puppetfile content build/bar/modules/dummy
INFO	 -> Deploying environment build/develop
INFO	 -> Environment develop is now at 6525d012383d951fb9c17df2dd01db8010d50a79
INFO	 -> Deploying Puppetfile content build/develop/modules/dummy
INFO	 -> Deploying environment build/foo
INFO	 -> Environment foo is now at 6525d012383d951fb9c17df2dd01db8010d50a79
INFO	 -> Deploying Puppetfile content build/foo/modules/dummy
INFO	 -> Deploying environment build/master
INFO	 -> Environment master is now at 6525d012383d951fb9c17df2dd01db8010d50a79
INFO	 -> Deploying Puppetfile content build/master/modules/dummy
$ for BRANCH in master develop foo bar; do cat build/$BRANCH/modules/dummy/manifests/init.pp; done
class dummy {
  notice "master"
}
class dummy {
  notice "master"
}
class dummy {
  notice "foo"
}
class dummy {
  notice "master"
}

g10k doesn't honor the control_branch parameter

$ ./g10k -config config.yaml -verbose
2019/03/29 12:58:34 Executing git clone --mirror https://github.com/pmuller/puppet-control-dummy.git ./cache/environments/control.git took 2.12764s
2019/03/29 12:58:34 Executing git --git-dir ./cache/environments/control.git branch took 0.00266s
2019/03/29 12:58:34 Executing git --git-dir ./cache/environments/control.git rev-parse --verify 'master^{object}' took 0.00261s
Need to sync ./build/master/
2019/03/29 12:58:34 Executing git --git-dir ./cache/environments/control.git rev-parse --verify 'foo^{object}' took 0.00321s
Need to sync ./build/foo/
2019/03/29 12:58:34 Executing git --git-dir ./cache/environments/control.git rev-parse --verify 'develop^{object}' took 0.00431s
Need to sync ./build/develop/
2019/03/29 12:58:34 Executing git --git-dir ./cache/environments/control.git rev-parse --verify 'bar^{object}' took 0.00675s
Need to sync ./build/bar/
2019/03/29 12:58:34 syncToModuleDir(): Executing git --git-dir ./cache/environments/control.git archive master took 0.00325s
2019/03/29 12:58:34 syncToModuleDir(): Executing git --git-dir ./cache/environments/control.git archive foo took 0.00476s
2019/03/29 12:58:34 syncToModuleDir(): Executing git --git-dir ./cache/environments/control.git archive develop took 0.00505s
2019/03/29 12:58:34 Executing git --git-dir ./cache/environments/control.git rev-parse --verify 'master^{object}' took 0.00516s
2019/03/29 12:58:34 syncToModuleDir(): Executing git --git-dir ./cache/environments/control.git archive bar took 0.00420s
2019/03/29 12:58:34 Executing git --git-dir ./cache/environments/control.git rev-parse --verify 'foo^{object}' took 0.00610s
2019/03/29 12:58:34 Executing git --git-dir ./cache/environments/control.git rev-parse --verify 'develop^{object}' took 0.00753s
2019/03/29 12:58:34 Executing git --git-dir ./cache/environments/control.git rev-parse --verify 'bar^{object}' took 0.00402s
2019/03/29 12:58:36 Executing git clone --mirror https://github.com/pmuller/puppet-module-dummy.git ./cache/modules/https-__github.com_pmuller_puppet-module-dummy.git took 2.09338s
2019/03/29 12:58:36 Executing git --git-dir ./cache/modules/https-__github.com_pmuller_puppet-module-dummy.git rev-parse --verify 'master^{object}' took 0.01016s
Need to sync ./build/master/modules/dummy/
2019/03/29 12:58:36 Executing git --git-dir ./cache/modules/https-__github.com_pmuller_puppet-module-dummy.git rev-parse --verify 'master^{object}' took 0.01166s
Need to sync ./build/foo/modules/dummy/
2019/03/29 12:58:36 Executing git --git-dir ./cache/modules/https-__github.com_pmuller_puppet-module-dummy.git rev-parse --verify 'master^{object}' took 0.01253s
Need to sync ./build/bar/modules/dummy/
2019/03/29 12:58:36 Executing git --git-dir ./cache/modules/https-__github.com_pmuller_puppet-module-dummy.git rev-parse --verify 'master^{object}' took 0.01043s
Need to sync ./build/develop/modules/dummy/
2019/03/29 12:58:36 syncToModuleDir(): Executing git --git-dir ./cache/modules/https-__github.com_pmuller_puppet-module-dummy.git archive master took 0.00553s
2019/03/29 12:58:36 Executing git --git-dir ./cache/modules/https-__github.com_pmuller_puppet-module-dummy.git rev-parse --verify 'master^{object}' took 0.00501s
2019/03/29 12:58:36 syncToModuleDir(): Executing git --git-dir ./cache/modules/https-__github.com_pmuller_puppet-module-dummy.git archive master took 0.00730s
2019/03/29 12:58:36 syncToModuleDir(): Executing git --git-dir ./cache/modules/https-__github.com_pmuller_puppet-module-dummy.git archive master took 0.01136s
2019/03/29 12:58:36 syncToModuleDir(): Executing git --git-dir ./cache/modules/https-__github.com_pmuller_puppet-module-dummy.git archive master took 0.00813s
2019/03/29 12:58:36 Executing git --git-dir ./cache/modules/https-__github.com_pmuller_puppet-module-dummy.git rev-parse --verify 'master^{object}' took 0.00329s
2019/03/29 12:58:36 Executing git --git-dir ./cache/modules/https-__github.com_pmuller_puppet-module-dummy.git rev-parse --verify 'master^{object}' took 0.00375s
2019/03/29 12:58:36 Executing git --git-dir ./cache/modules/https-__github.com_pmuller_puppet-module-dummy.git rev-parse --verify 'master^{object}' took 0.00538s
Synced config.yaml with 12 git repositories and 0 Forge modules in 4.3s with git (2.1s sync, I/O 0.0s) and Forge (0.0s query+download, I/O 0.0s) using 50 resolv and 20 extract workers
$ for BRANCH in master develop foo bar; do cat build/$BRANCH/modules/dummy/manifests/init.pp; done
class dummy {
  notice "master"
}
class dummy {
  notice "master"
}
class dummy {
  notice "master"
}
class dummy {
  notice "master"
}

I found the bug.
gitModule.link (the :control_repo feature) was correctly set, but
gitModule.branch was also set to the string :control_branch.

This combined with the order of the conditions here:

g10k/puppetfile.go

Lines 319 to 327 in a6d6d70

if len(gitModule.branch) > 0 {
tree = gitModule.branch
} else if len(gitModule.commit) > 0 {
tree = gitModule.commit
} else if len(gitModule.tag) > 0 {
tree = gitModule.tag
} else if len(gitModule.ref) > 0 {
tree = gitModule.ref
} else if gitModule.link {
means that the :control_branch feature was completely skipped.

I've also released a version including this fix https://github.com/xorpaul/g10k/releases/tag/v0.5.9

Please test it.

I confirm it pass my test case perfectly. Thank a lot! :)