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

change listen attributes to be hash of addresses and ports to listen to #378

Merged
merged 4 commits into from
Oct 14, 2015

Conversation

b-dean
Copy link
Contributor

@b-dean b-dean commented Jul 24, 2015

This should fix the issue that was going on w/ PR #372
The attributes node['apache']['listen'] will be a hash indexed by address where the values are ports to listen to.

For example:

{
  "apache": {
    "listen": {
      "*": ["80", "443"],
      "127.0.0.1": [ "12345" ]
    }
  }
}

would create this ports.conf:

Listen *:80
Listen *:443
Listen 127.0.0.1:12345

Which was impossible with the older listen_ports and listen_addresses attributes.

@b-dean
Copy link
Contributor Author

b-dean commented Jul 27, 2015

FWIW, the travis failures were failing before my PR.

@martinb3
Copy link
Contributor

I would love to see this made backwards-compatible, checking for the old attribute if it exists & using the older behavior, and emitting a warning that the user should upgrade.

@b-dean
Copy link
Contributor Author

b-dean commented Jul 27, 2015

I believe the changes I made to the ports.conf.erb makes it still use the old attributes the same way they worked before.

It doesn't give a message about them being deprecated or anything like that though.

@b-dean
Copy link
Contributor Author

b-dean commented Jul 27, 2015

@martinb3, is there some preferred place to have it give a warning about deprecated attributes? I'm guessing that the right place would not be inside the ports.conf.erb while it's running the template.

@b-dean
Copy link
Contributor Author

b-dean commented Aug 4, 2015

I had been doing the conversion of node['apache']['listen_addresses'] and node['apache']['listen_ports'] to the new node['apache']['listen'] directly in the ports.conf.erb template. I moved it out to a helper method where it's easier to see whats going on and we can have a warning message about the deprecated attributes.

This should fix the issue that was going on w/ PR sous-chefs#372
The attributes `node['apache']['listen']` will be a hash indexed by address where the values are ports to listen to.

For example:

```json
{
  "apache": {
    "listen": {
      "*": ["80", "443"],
      "127.0.0.1": [ "12345" ]
    }
  }
}
```

would create this ports.conf:

```
Listen *:80
Listen *:443
Listen 127.0.0.1:12345
```

Which was impossible with the older listen_ports and listen_addresses attributes.
@b-dean
Copy link
Contributor Author

b-dean commented Oct 14, 2015

Realized I needed to use a Chef::Mixin::DeepMerge.deep_merge in my helper method. Also rebased to the latest master.

@b-dean
Copy link
Contributor Author

b-dean commented Oct 14, 2015

Build failing because of berkshelf nonsense. @svanzoest, @drpebcak, looks like it might be time to go to berkshelf 4.

drpebcak added a commit that referenced this pull request Oct 14, 2015
change listen attributes to be hash of addresses and ports to listen to
@drpebcak drpebcak merged commit 3d6c471 into sous-chefs:master Oct 14, 2015
@drpebcak
Copy link
Contributor

Looks good to me! Thanks!

We'll have to look into the berkshelf thing...

@jharbott
Copy link

jharbott commented Feb 9, 2016

Sorry for jumping in late here, but somehow I didn't notice the updates to my original PR that triggered this work.

Using a hash for the adresses makes using the listen attribute rather complicated, so I'm wondering whether this could get amended to using a flat array of "addr:port" combinations.

The use case I'm having is that a recipe wants httpd to listen on addr:port in addition to whatever some other recipes may have configured. Now instead of being able to simply set listen += ["addr:port"], the code will first have to check whether the listen hash already has a key with value addr and depending on that either create a new key-value pair or just add port to the existing list.

I would also vote to get rid of setting listen = {'*' => '80'} as a default, since overriding this default turns out to be pretty complicated if one doesn't know whether it might have been set by a cookbook or not. I'll come up with a new PR for that, but would like to know your ideas regarding this anyway.

@b-dean
Copy link
Contributor Author

b-dean commented Feb 9, 2016

@jrosenboom that seems fine to me. My original need here was just to be able to have it listen on more than every address on every port. An array of addr:port should work too.

The only downside I can think of is that arrays don't merge across node attribute levels the same way hashes do. So the apache2 cookbook couldn't have an attributes file with

default["apache"]["listen"] = [ "*:80" ]

and then later someone in some foo::bar recipe does:

node.normal["apache"]["listen"] += [ "127.0.0.1:1234" ]

because then the normal level wouldn't have the "*:80" so it wouldn't listen there anymore. Arrays are super obnoxious in Chef. So ... maybe it wouldn't work so well.

jharbott pushed a commit to x-ion-de/apache2 that referenced this pull request Feb 10, 2016
This PR amends the logic introduced in
sous-chefs#378 to use an array
as attribute instead of a hash, as this will simplify using this
cookbook in other recipes.

E.g., if a recipe wants httpd to listen on `addr:port`, it is much easier to
just set

    node.set['apache2']['listen'] += ['addr:port']

instead of first having to check whether the listen hash does have the
key `addr` already and then either add it or update the port list.
jharbott pushed a commit to x-ion-de/apache2 that referenced this pull request Feb 10, 2016
This PR amends the logic introduced in
sous-chefs#378 to use an array
as attribute instead of a hash, as this will simplify using this
cookbook in other recipes.

E.g., if a recipe wants httpd to listen on `addr:port`, it is much easier to
just set

    node.set['apache2']['listen'] += ['addr:port']

instead of first having to check whether the listen hash does have the
key `addr` already and then either add it or update the port list.
@lock
Copy link

lock bot commented Jul 24, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants