Merge pull request #2049 from juergenhoetzel/disable_equal_scalar_resolv

Prevent ConstructorError when parsing YAML containing '=' scalars
This commit is contained in:
Kubernetes Prow Robot 2023-05-24 12:42:50 -07:00 committed by GitHub
commit 9a2d5e4290
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -153,12 +153,17 @@ def create_from_yaml(
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(