Skip to content

Commit

Permalink
Make toleration handling backwards compatible with Python 2.7 code en…
Browse files Browse the repository at this point in the history
…vs (#73)

* Make toleration handling backwards compatible with Python 2.7 code envs

* Update changelog and plugin version for release

* Stop using _is_none_or_blank due to python 2.7

* Use none as default value for publickeyname

Co-authored-by: Amandine Souilleux <[email protected]>

* Use None as default for more properties

* More default values to None when using _is_none_or_blank

* [sc-186714] fix issue with keeping the already added tolerations on GPU

* [sc-186714] remove files

---------

Co-authored-by: Amandine Souilleux <[email protected]>
Co-authored-by: Amandine Souilleux <[email protected]>
  • Loading branch information
3 people authored Jun 11, 2024
1 parent 2ec5949 commit 7ee292e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Version 1.4.2 - Bugfix release
- Fix clusters creation with GPU driver with Python 2 code environments

## Version 1.4.1 - Bugfix release
- Fix an issue when using the action to add a node pool with GPU

Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "eks-clusters",
"version": "1.4.1",
"version": "1.4.2",
"meta": {
"label": "EKS clusters",
"description": "Interact with Amazon Elastic Kubernetes Service clusters",
Expand Down
5 changes: 3 additions & 2 deletions python-lib/dku_kube/gpu_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ def add_gpu_driver_if_needed(cluster_id, kube_config_path, connection_info, tain
# Retrieve the tolerations on the daemonset currently deployed to the cluster.
if has_gpu_driver(kube_config_path):
cmd = ['kubectl', 'get', 'daemonset', 'nvidia-device-plugin-daemonset', '-n', 'kube-system', '-o', 'jsonpath="{.spec.template.spec.tolerations}"']
tolerations_json, err = run_with_timeout(cmd, env=env, timeout=5)
if _is_none_or_blank(tolerations_json):
cmd_result, err = run_with_timeout(cmd, env=env, timeout=5)
tolerations_json = cmd_result[1:-1]
if not _is_none_or_blank(tolerations_json):
tolerations.update(Toleration.from_json(tolerations_json))

# If there are any taints to patch the daemonset with in the node group(s) to create,
Expand Down
8 changes: 4 additions & 4 deletions python-lib/dku_utils/node_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get_node_pool_yaml(node_pool, networking_settings):
yaml['labels'] = node_pool['labels']
yaml['spot'] = node_pool.get('useSpotInstances', False)

sshPublicKeyName = node_pool.get('publicKeyName', '')
sshPublicKeyName = node_pool.get('publicKeyName', None)
if not _is_none_or_blank(sshPublicKeyName):
yaml['ssh'] = {
'allow': True,
Expand All @@ -93,11 +93,11 @@ def get_node_pool_yaml(node_pool, networking_settings):
}
yaml['privateNetworking'] = networking_settings.get('privateNetworking', False)

if node_pool.get('addPreBootstrapCommands', False) and not _is_none_or_blank(node_pool.get('preBootstrapCommands', '')):
if node_pool.get('addPreBootstrapCommands', False) and not _is_none_or_blank(node_pool.get('preBootstrapCommands', None)):
yaml['preBootstrapCommands'] = yaml.get('preBootstrapCommands', [])
yaml['preBootstrapCommands'] += [command.strip()\
for command in node_pool['preBootstrapCommands'].split('\n')\
if not _is_none_or_blank(command.strip())]
if not _is_none_or_blank(command)]

return yaml

Expand All @@ -106,7 +106,7 @@ def build_node_pool_taints_yaml(node_pool):
yaml_taints = []
if node_pool['taints']:
for taint in node_pool['taints']:
if not _is_none_or_blank(taint.get('key', '')):
if not _is_none_or_blank(taint.get('key', None)):
yaml_taints.append({
'key': taint['key'],
'value': taint.get('value', ''),
Expand Down
12 changes: 6 additions & 6 deletions python-lib/dku_utils/taints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

class Taint(dict):
def __init__(self, taint):
if not _is_none_or_blank(taint.get('key', '')):
if not _is_none_or_blank(taint.get('key', None)):
self['key'] = taint.get('key', '')

if not _is_none_or_blank(taint.get('value', '')):
if not _is_none_or_blank(taint.get('value', None)):
self['value'] = taint.get('value', '')

if not _is_none_or_blank(taint.get('effect', '')):
if not _is_none_or_blank(taint.get('effect', None)):
self['effect'] = taint.get('effect', '')

def __eq__(self, other):
Expand All @@ -23,19 +23,19 @@ def __hash__(self):

class Toleration(Taint):
def __init__(self, taint):
super().__init__(taint)
super(Toleration, self).__init__(taint)

if self.get('value', ''):
self['operator'] = 'Equal'
else:
self['operator'] = 'Exists'

def __eq__(self, other):
return super().__eq__(other) and self.get('operator', '') == other.get('operator', '')
return super(Toleration, self).__eq__(other) and self.get('operator', '') == other.get('operator', '')


def __hash__(self):
return hash((super().__hash__(), self.get('operator', '')))
return hash((super(Toleration, self).__hash__(), self.get('operator', '')))

def to_dict(self):
return {k: v for k, v in self.items()}
Expand Down
2 changes: 1 addition & 1 deletion python-runnables/add-node-pool/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def run(self, progress_callback):

# second step: add the stuff that has no equivalent command line arg, and run the
# eksctl command on the yaml config
if node_pool.get('addPreBootstrapCommands', False) and not _is_none_or_blank(node_pool.get("preBootstrapCommands", "")):
if node_pool.get('addPreBootstrapCommands', False) and not _is_none_or_blank(node_pool.get("preBootstrapCommands", None)):
# has to be added in the yaml, there is no command line flag for that
commands = node_pool.get("preBootstrapCommands", "")
for node_pool_dict in yaml_dict['managedNodeGroups']:
Expand Down

0 comments on commit 7ee292e

Please sign in to comment.