-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from nolar/renames-and-moves
Move the modules around to cleanup the code
- Loading branch information
Showing
35 changed files
with
141 additions
and
99 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,42 @@ | ||
import logging | ||
|
||
import kubernetes | ||
import urllib3.exceptions | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class LoginError(Exception): | ||
""" Raised when the operator cannot login to the API. """ | ||
|
||
|
||
def login(): | ||
""" | ||
Login the the Kubernetes cluster, locally or remotely. | ||
""" | ||
|
||
# Configure the default client credentials for all possible environments. | ||
try: | ||
kubernetes.config.load_incluster_config() # cluster env vars | ||
logger.debug("configured in cluster with service account") | ||
except kubernetes.config.ConfigException as e1: | ||
try: | ||
kubernetes.config.load_kube_config() # developer's config files | ||
logger.debug("configured via kubeconfig file") | ||
except kubernetes.config.ConfigException as e2: | ||
raise LoginError(f"Cannot authenticate neither in-cluster, nor via kubeconfig.") | ||
|
||
# Make a sample API call to ensure the login is successful, | ||
# and convert some of the known exceptions to the CLI hints. | ||
try: | ||
api = kubernetes.client.CoreApi() | ||
api.get_api_versions() | ||
except urllib3.exceptions.HTTPError as e: | ||
raise LoginError("Cannot connect to the Kubernetes API. " | ||
"Please configure the cluster access.") | ||
except kubernetes.client.rest.ApiException as e: | ||
if e.status == 401: | ||
raise LoginError("Cannot authenticate to the Kubernetes API. " | ||
"Please login or configure the tokens.") | ||
else: | ||
raise |
File renamed without changes.
File renamed without changes.
File renamed 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,8 @@ | ||
""" | ||
Engines are things that run around the reactor (see `kopf.reactor`) | ||
to help it to function at full strength, but are not part of it. | ||
For example, all never-ending side-tasks for peering and k8s-event-posting. | ||
The reactor and engines exchange the state with each other (bi-directionally) | ||
via the provided synchronization objects, usually asyncio events & queues. | ||
""" |
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,5 @@ | ||
""" | ||
General-purpose helpers not related to the framework itself | ||
(neither to the reactor nor to the engines nor to the structs), | ||
which are used to prepare and control the runtime environment. | ||
""" |
File renamed 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
Oops, something went wrong.