Skip to content

Commit

Permalink
salt: Handle pillar '_errors' in 'metalk8s:nodes'
Browse files Browse the repository at this point in the history
The `metalk8s.minions_by_role` method now checks for those errors and
raises a `CommandExecutionError` if there are some.
The apiserver-proxy configuration template now handles more cases to
ensure we only generate the configuration if there are master nodes or
we explicitely are bootstrapping.
  • Loading branch information
gdemonet committed May 18, 2020
1 parent f2738cd commit e3c97e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
6 changes: 6 additions & 0 deletions salt/_modules/metalk8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ def minions_by_role(role, nodes=None):
Defaults to `pillar.metalk8s.nodes`.
'''
nodes = nodes or __pillar__['metalk8s']['nodes']
if '_errors' in nodes:
raise CommandExecutionError(
"Can't retrieve minions by role because of errors in pillar "
"'metalk8s:nodes': %s",
', '.join(nodes['_errors']),
)

return [
node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,28 @@ events {
}

{%- if pillar.get('apiserver_ip') %}
{%- set masters_request = {'ip': pillar.apiserver_ip} %}
{%- set apiservers = [pillar.apiserver_ip] %}
{%- elif '_errors' in pillar.metalk8s.nodes %}
{%- if pillar.get('is_bootstrap', false) %}
{%- set apiservers = ["127.0.0.1"] %}
{%- else %}
{{ raise("Errors in 'metalk8s:nodes' pillar: "
~ (pillar.metalk8s.nodes._errors | tojson) ) }}
{%- endif %}
{%- else %}
{%- set master_minions = salt['metalk8s.minions_by_role']('master') %}
{%- set masters_request = salt['mine.get'](
tgt=master_minions | join(','),
fun='control_plane_ip',
tgt_type='list',
)
{%- set masters = salt['metalk8s.minions_by_role']('master') %}
{%- if not masters %}
{{ raise("No master nodes in pillar 'metalk8s:nodes', "
~ "can't deploy apiserver-proxy") }}
{%- else %}
{%- set master_ips = salt['mine.get'](
tgt=master_minions | join(','),
fun='control_plane_ip',
tgt_type='list',
)
%}
{%- endif %}
{%- if not masters_request %}
{# In this case, we're (likely) bootstrapping #}
{%- set apiservers = ['127.0.0.1'] %}
{%- else %}
{%- set apiservers = masters_request.values() | sort %}
{%- set apiservers = master_ips.values() | sort %}
{%- endif %}
{%- endif %}

stream {
Expand Down

0 comments on commit e3c97e1

Please sign in to comment.