Skip to content

Prevent ConstructorError when parsing YAML containing '=' scalars #2049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion kubernetes/utils/create_from_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,17 @@ def create_with(objects):
raise FailToCreateError(failures)
return k8s_objects

class Loader(yaml.loader.SafeLoader):
yaml_implicit_resolvers = yaml.loader.SafeLoader.yaml_implicit_resolvers.copy()
if "=" in yaml_implicit_resolvers:
yaml_implicit_resolvers.pop("=")

if yaml_objects:
yml_document_all = yaml_objects
return create_with(yml_document_all)
elif yaml_file:
with open(os.path.abspath(yaml_file)) as f:
yml_document_all = yaml.safe_load_all(f)
yml_document_all = yaml.load_all(f, Loader=Loader)
return create_with(yml_document_all)
else:
raise ValueError(
Expand Down