diff --git a/cmd/crictl/util.go b/cmd/crictl/util.go index bf57a94907..6a1e685771 100644 --- a/cmd/crictl/util.go +++ b/cmd/crictl/util.go @@ -152,6 +152,13 @@ func loadContainerConfig(path string) (*pb.ContainerConfig, error) { if err := utilyaml.NewYAMLOrJSONDecoder(f, 4096).Decode(&config); err != nil { return nil, err } + + if config.Metadata == nil { + return nil, errors.New("metadata is not set") + } else if config.Metadata.Name == "" { + return nil, fmt.Errorf("name is not in metadata %q", config.Metadata) + } + return &config, nil } @@ -166,6 +173,13 @@ func loadPodSandboxConfig(path string) (*pb.PodSandboxConfig, error) { if err := utilyaml.NewYAMLOrJSONDecoder(f, 4096).Decode(&config); err != nil { return nil, err } + + if config.Metadata == nil { + return nil, errors.New("metadata is not set") + } else if config.Metadata.Name == "" || config.Metadata.Namespace == "" || config.Metadata.Uid == "" { + return nil, fmt.Errorf("name, namespace or uid is not in metadata %q", config.Metadata) + } + return &config, nil }