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

refactor(naming): reserve 'pkg' as name of packaging dict #137

Merged
merged 1 commit into from
Jun 13, 2019
Merged

refactor(naming): reserve 'pkg' as name of packaging dict #137

merged 1 commit into from
Jun 13, 2019

Conversation

noelmcloughlin
Copy link
Member

@noelmcloughlin noelmcloughlin commented Jun 5, 2019

prometheus on centos needs a repo setup. I've studied how best to incorporate this into this formula and the result is here. My method involved introducing a pkg dictionary to collect packaging related details. That provided the model on which to propose handling package repos. The problem is that "pkg" variable is already in use.

pkg: template

This PR is to reclaim "pkg" variable as dict. Let me know if you like the approach.

    pkg:
      name: template
      use_upstream_repo: True
      use_upstream_archive: False
      archive: {}
      repo:
        managed: {}

The followup PR will be to to add repo support to both template and then prometheus formulas.

@baby-gnu
Copy link
Contributor

baby-gnu commented Jun 6, 2019

So if I understand, imagine I have a main program and plugins, I could have something like:

program:
  pkg:
    name: the-program
    use_upstream_repo: true
    repo:
      name: deb {{ repo.official }}/debian-{{ repo.release }}/ {{ grains.oscodename }} main
      humanname: Something Debian Repository
      
  plugins:
    an-external-plugin:
      pkg:
        name: a-cool-plugin
        use_upstream_repo: true
        repo:
          name: deb https://example.net/repo/a-cool-plugin/ {{ grains.oscodename }} stable
          humanname: Debian reposiory for a cool plugin
          key_url: https://example.net/repo/a-cool-plugin/project/gpg_key.pub
          gpgcheck: 1

Actually, I found several formulas using pkg_repo, pkgrepo or simply repo to avoid an extra level in the hash, for example:

program:
  pkg: something
  use_upstream_repo: true
  repo:
    name: deb {{ repo.official }}/debian-{{ repo.release }}/ {{ grains.oscodename }} main
    humanname: Something Debian Repository
    
  plugins:
    an-external-plugin:
      pkg: a-cool-plugin
      use_upstream_repo: true
      repo:
        name: deb https://example.net/repo/a-cool-plugin/ {{ grains.oscodename }} stable
        humanname: Debian reposiory for a cool plugin
        key_url: https://example.net/repo/a-cool-plugin/project/gpg_key.pub
        gpgcheck: 1

I like your proposal because it produce meanful program.pkg.name, program.pkg.use_upstream_repo and program.pkg.repo, we see use_upstream_repo and repo as something related to the package. The package related stuffs are located under program.pkg.

The cons would be the additional level, let see if the SaltStack community prefer the flatter one.

@baby-gnu
Copy link
Contributor

baby-gnu commented Jun 6, 2019

If this is to be merged, this is a breaking changes and should be announce in the commit message.

@daks
Copy link
Member

daks commented Jun 6, 2019

@noelmcloughlin not sure I completely understand the problem, but if I do, my comment is: if a formula manages package installation, it should have default values to indicate for example repo, package name, etc. Then those values are populated in the jinja files (osmap...), then they can be override with the lookup pillar dict.
Am I understanding it correctly?

@noelmcloughlin
Copy link
Member Author

noelmcloughlin commented Jun 6, 2019

Hi @baby-gnu
Exactly - I'm really glad you understood the intention.

My 1st implementation in cloudfoundry-formula looks like your examples. I added an extra (perhaps superfluous) level.

  pkg:
    repo:
       managed:
         humanname: cloudfoundry-cli
         name: cloudfoundry-cli
         comments:
           - installed by salt
          gpgcheck: 1

My related "pkg:archive" implementation (the extra level was to allow archive.extracted detect format_type correctly) further illustrates that making pkg a dict feels important.

  pkg:
      archive:
        source: https://packages.cloudfoundry.org/stable?release=linux64-binary&version=6.44.1&source=github-rel
        extracted:
          name: /usr/local/bin
          source: /tmp/cloudfoundry/cf-cli.tgz
          source_hash: b986a55fef4bd6f580d7a070f4592362309fe009ffdd9489b9d3b871aed07aa3
          trim_output: True
          enforce_toplevel: False

Good point about breaking change - I'll update the commit message.

@noelmcloughlin
Copy link
Member Author

Then those values are populated in the jinja files (osmap...), then they can be override with the lookup pillar dict.

Hi @daks, yes that correct. The intention of this PR was small breaking change to convert pkg to dict since its useful implementation detail to support upcoming archive/repo support features.

@baby-gnu
Copy link
Contributor

baby-gnu commented Jun 6, 2019

Hello @noelmcloughlinx

The extra sublevel maybe superfluous, but we should make sure to be able to use format_kwargs as proposed in #134, which means only store under template.pkg.repo things understandable by pkgrepo.managed.

For me, use_upstream_repo & co. are better placed under template.pkg:

  • I prefer to read template.pkg.use_upstream_repo than template.pkg.repo.use_upstream_repo
  • I prefer to have the repository information under template.pkg.repo than template.pkg.repo.managed because I don't understand why managed is related to repository data. It's only a mirror of SaltStack state pkgrepo.managed

My related "pkg:archive" implementation (the extra level was to allow archive.extracted detect format_type correctly) further illustrates that making pkg a dict feels important

I don't get the point about archive.extracted and format_type.

Why

  pkg:
      archive:
        source: https://packages.cloudfoundry.org/stable?release=linux64-binary&version=6.44.1&source=github-rel
        extracted:
          name: /usr/local/bin
          source: /tmp/cloudfoundry/cf-cli.tgz
          source_hash: b986a55fef4bd6f580d7a070f4592362309fe009ffdd9489b9d3b871aed07aa3
          trim_output: True
          enforce_toplevel: False

is better than

  pkg:
      archive:
        name: /usr/local/bin
        source: https://packages.cloudfoundry.org/stable?release=linux64-binary&version=6.44.1&source=github-rel
        source_hash: b986a55fef4bd6f580d7a070f4592362309fe009ffdd9489b9d3b871aed07aa3
        archive_format: tar
        trim_output: True
        enforce_toplevel: False

For me, it avoid managing /tmp/cloudfoundry/cf-cli.tgz.

Regards.

@daks
Copy link
Member

daks commented Jun 6, 2019

Then those values are populated in the jinja files (osmap...), then they can be override with the lookup pillar dict.

Hi @daks, yes that correct. The intention of this PR was small breaking change to convert pkg to dict since its useful implementation detail to support upcoming archive/repo support features.

OK. Does it needs to be done in template-formula or simply adapted in needed formulas? I mean template-formula has a few useful pillar key/values but those are only 'indicative' and could/should be adapted in every formula.

@noelmcloughlin
Copy link
Member Author

Then those values are populated in the jinja files (osmap...), then they can be override with the lookup pillar dict.

Hi @daks, yes that correct. The intention of this PR was small breaking change to convert pkg to dict since its useful implementation detail to support upcoming archive/repo support features.

OK. Does it needs to be done in template-formula or simply adapted in needed formulas? I mean template-formula has a few useful pillar key/values but those are only 'indicative' and could/should be adapted in every formula.

It should be done here template formula in my opinion - i.e. change pkg to dict.

@baby-gnu
Copy link
Contributor

baby-gnu commented Jun 6, 2019

@daks OK. Does it needs to be done in template-formula or simply adapted in needed formulas?

We want to make template-formula the “go-to resource for all formula development” (#21), so this should be done here.

Regards.

@noelmcloughlin
Copy link
Member Author

noelmcloughlin commented Jun 6, 2019

We want to make template-formula the “go-to resource for all formula development” (#21), so this should be done here.

Thanks @baby-gnu @daks this was the item related to this PR.

Adapt template-formula to not be too focussed on pkg:
Must also consider archives, tarball releases, GitHub repos, etc.

This PR is an enabler only.

@noelmcloughlin
Copy link
Member Author

Here are derived implementations based on this pkg dict ...
saltstack-formulas/grafana-formula#3
saltstack-formulas/prometheus-formula#4

@noelmcloughlin
Copy link
Member Author

Hi @baby-gnu
I agree with your analysis here and will include in upcoming PR.

Thanks for reviewing!!

BREAKING CHANGE: the parameter `pkg` is now a dictionary. References
 to `template.pkg` should be changed to `template.pkg.name`.
@myii
Copy link
Member

myii commented Jun 12, 2019

Related issue: #135.

Copy link
Contributor

@baby-gnu baby-gnu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with this pull request.

The failed build is not related to the changes here.

@noelmcloughlin
Copy link
Member Author

Thanks @baby-gnu @daks for the review - appreciated.

@noelmcloughlin noelmcloughlin merged commit def40ce into saltstack-formulas:master Jun 13, 2019
@saltstack-formulas-travis

🎉 This PR is included in version 3.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

5 participants