genpolicy: ignore empty YAML as input

Kata CI's pod-sandbox-vcpus-allocation.yaml ends with "---", so the
empty YAML document following that line should be ignored.

To test this fix:

genpolicy -u -y pod-sandbox-vcpus-allocation.yaml

Fixes: #8895

Signed-off-by: Dan Mihai <dmihai@microsoft.com>
This commit is contained in:
Dan Mihai 2024-01-30 17:24:05 +00:00
parent befef119ff
commit 09ea0eed9d

View File

@ -368,8 +368,8 @@ impl AgentPolicy {
for document in serde_yaml::Deserializer::from_str(&yaml_contents) {
let doc_mapping = Value::deserialize(document)?;
if doc_mapping != Value::Null {
let yaml_string = serde_yaml::to_string(&doc_mapping)?;
let silent = config.silent_unsupported_fields;
let (mut resource, kind) = yaml::new_k8s_resource(&yaml_string, silent)?;
resource.init(config.use_cache, &doc_mapping, silent).await;
@ -391,6 +391,7 @@ impl AgentPolicy {
// YAML file.
resources.push(resource);
}
}
let settings = settings::Settings::new(&config.json_settings_path);