Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
salt: use roles retrieved from Node objects
This allows to set `node-role.kubernetes.io/$ROLE` labels on a Node object, where `$ROLE` can be `bootstrap`, `etcd`, `master` and `node`, which will then determine the `highstate` of the node. Furthermore, it requires a `metalk8s.scality.com/version` label to select a MetalK8s version (actually, `saltenv`) to be used. It also removes the `node-role.kubernetes.io/master` Taint from the bootstrap Node, and replaces it with a `node-role.kubernetes.io/bootstrap` Taint, which is tolerated by CoreDNS and the UI. This is a special-case of the `node-role.kubernetes.io/master` Taint which would not permit such services to run on the node. See: #925 See: #925 See: #742 See: #742 See: #903 See: #903
- Loading branch information
Showing
19 changed files
with
189 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import os.path | ||
import logging | ||
|
||
try: | ||
import kubernetes.client | ||
import kubernetes.config | ||
HAS_DEPS = True | ||
except ImportError: | ||
HAS_DEPS = False | ||
|
||
|
||
VERSION_LABEL = 'metalk8s.scality.com/version' | ||
ROLE_LABEL_PREFIX = 'node-role.kubernetes.io/' | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
__virtualname__ = 'metalk8s_nodes' | ||
|
||
def __virtual__(): | ||
if HAS_DEPS: | ||
return __virtualname__ | ||
else: | ||
return False, 'Missing Kubernetes client library dependency' | ||
|
||
|
||
def node_info(node, ca_minion): | ||
result = { | ||
'roles': [], | ||
'version': None, | ||
} | ||
|
||
roles = set() | ||
|
||
if VERSION_LABEL in node.metadata.labels: | ||
result['version'] = node.metadata.labels[VERSION_LABEL] | ||
|
||
for (label, value) in node.metadata.labels.items(): | ||
if label.startswith(ROLE_LABEL_PREFIX): | ||
role = label[len(ROLE_LABEL_PREFIX):] | ||
if role: | ||
roles.add(role) | ||
|
||
if node.metadata.name == ca_minion: | ||
roles.add('ca') | ||
|
||
result['roles'] = list(roles) | ||
|
||
return result | ||
|
||
|
||
def ext_pillar(minion_id, pillar, kubeconfig): | ||
if not os.path.isfile(kubeconfig): | ||
log.warning( | ||
'%s: kubeconfig not found at %s', __virtualname__, kubeconfig) | ||
return {} | ||
|
||
ca_minion = None | ||
if 'metalk8s' in pillar: | ||
if 'ca' in pillar['metalk8s']: | ||
ca_minion = pillar['metalk8s']['ca'].get('minion', None) | ||
|
||
client = kubernetes.config.new_client_from_config( | ||
config_file=kubeconfig, | ||
) | ||
|
||
coreV1 = kubernetes.client.CoreV1Api(api_client=client) | ||
|
||
node_list = coreV1.list_node() | ||
|
||
pillar_nodes = dict( | ||
(node.metadata.name, node_info(node, ca_minion)) | ||
for node in node_list.items) | ||
|
||
return { | ||
'metalk8s': { | ||
'nodes': pillar_nodes, | ||
'node': pillar_nodes.get(minion_id, None), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Deploy bootstrap: | ||
test.succeed_without_changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Deploy CA: | ||
test.succeed_without_changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Deploy etcd member: | ||
test.succeed_without_changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Deploy control plane node: | ||
test.succeed_without_changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Deploy Salt minion: | ||
test.succeed_without_changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Deploy workload plane node: | ||
test.succeed_without_changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Deploy container image registry: | ||
test.succeed_without_changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Deploy package repository: | ||
test.succeed_without_changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Deploy Salt master: | ||
test.succeed_without_changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
metalk8s-@@VERSION: | ||
'metalk8s:node:version:@@VERSION': | ||
- match: pillar | ||
- metalk8s.roles.minion | ||
'I@metalk8s:node:version:@@VERSION and I@metalk8s:node:roles:bootstrap': | ||
- match: compound | ||
- metalk8s.roles.bootstrap | ||
- metalk8s.roles.salt-master | ||
- metalk8s.roles.registry | ||
- metalk8s.roles.repository | ||
'I@metalk8s:node:version:@@VERSION and I@metalk8s:node:roles:ca': | ||
- match: compound | ||
- metalk8s.roles.ca | ||
'I@metalk8s:node:version:@@VERSION and I@metalk8s:node:roles:etcd': | ||
- match: compound | ||
- metalk8s.roles.etcd | ||
'I@metalk8s:node:version:@@VERSION and I@metalk8s:node:roles:master': | ||
- match: compound | ||
- metalk8s.roles.master | ||
'I@metalk8s:node:version:@@VERSION and I@metalk8s:node:roles:node': | ||
- match: compound | ||
- metalk8s.roles.node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters