This repository has been archived by the owner on Mar 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 185
Support file-ish objects in config loading #208
Merged
k8s-ci-robot
merged 7 commits into
kubernetes-client:master
from
ryphon:207-config-as-string
Sep 9, 2020
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f65f06b
commiting changes to branch
ryphon aac4e35
correcting tests
ryphon f85a41f
renaming functions and setting to internal
ryphon bfa9681
supporting 2.7, reading works fine, writing reqs unicode
ryphon 49cbb1d
replace inside the parens
ryphon 9f4775f
trying to fix pycodestyle problems
ryphon 0559445
unused io import, pre-setting pycodestyle
ryphon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import json | ||
import logging | ||
import os | ||
import io | ||
import platform | ||
import subprocess | ||
import tempfile | ||
|
@@ -667,19 +668,31 @@ def __init__(self, paths): | |
self.paths = [] | ||
self.config_files = {} | ||
self.config_merged = None | ||
|
||
for path in paths.split(ENV_KUBECONFIG_PATH_SEPARATOR): | ||
if path: | ||
path = os.path.expanduser(path) | ||
if os.path.exists(path): | ||
self.paths.append(path) | ||
self.load_config(path) | ||
self.config_saved = copy.deepcopy(self.config_files) | ||
if hasattr(paths, 'read'): | ||
self.load_config_from_fileish(paths) | ||
else: | ||
for path in paths.split(ENV_KUBECONFIG_PATH_SEPARATOR): | ||
if path: | ||
path = os.path.expanduser(path) | ||
if os.path.exists(path): | ||
self.paths.append(path) | ||
self.load_config(path) | ||
self.config_saved = copy.deepcopy(self.config_files) | ||
|
||
@property | ||
def config(self): | ||
return self.config_merged | ||
|
||
def load_config_from_fileish(self, string): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does renaming the method to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a great point, will get that in shortly. |
||
if hasattr(string, 'getvalue'): | ||
config = yaml.safe_load(string.getvalue()) | ||
else: | ||
config = yaml.safe_load(string.read()) | ||
|
||
if self.config_merged is None: | ||
self.config_merged = copy.deepcopy(config) | ||
# doesn't need to do any further merging | ||
|
||
def load_config(self, path): | ||
with open(path) as f: | ||
config = yaml.safe_load(f) | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about pushing the code path for paths to a separate internal function (say
_load_config_from_file_path
) as well? I think readability will increase that way.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this as well, will get this in shortly as well!