-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
salt: Add retry on DynamicClient creation to avoid flaky
- Loading branch information
1 parent
909f4d6
commit d6ed6fd
Showing
9 changed files
with
120 additions
and
66 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
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,38 @@ | ||
"""Utility methods for MetalK8s Kubernetes modules. | ||
""" | ||
|
||
import time | ||
|
||
MISSING_DEPS = [] | ||
|
||
try: | ||
import kubernetes | ||
except ImportError: | ||
MISSING_DEPS.append("kubernetes") | ||
|
||
__virtualname__ = "metalk8s_kubernetes" | ||
|
||
|
||
def __virtual__(): | ||
if MISSING_DEPS: | ||
error_msg = "Missing dependencies: {}".format(", ".join(MISSING_DEPS)) | ||
return False, error_msg | ||
|
||
return __virtualname__ | ||
|
||
|
||
def get_client(kubeconfig, context, attempts=5): | ||
""" | ||
Simple wrapper to retry on DynamicClient creation since it | ||
may fail from time to time | ||
""" | ||
while True: | ||
try: | ||
return kubernetes.dynamic.DynamicClient( | ||
kubernetes.config.new_client_from_config(kubeconfig, context) | ||
) | ||
except Exception: # pylint: disable=broad-except | ||
if attempts < 0: | ||
raise | ||
attempts -= 1 | ||
time.sleep(5) |
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