Skip to content

Commit

Permalink
Merge pull request #1274 from saschagrunert/sandbox-container-metadata
Browse files Browse the repository at this point in the history
Validate sandbox and container metadata
  • Loading branch information
k8s-ci-robot authored Oct 10, 2023
2 parents 41bda9e + 75c136c commit 60ee696
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmd/crictl/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ 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")
}

if config.Metadata.Name == "" {
return nil, fmt.Errorf("name is not in metadata %q", config.Metadata)
}

return &config, nil
}

Expand All @@ -166,6 +175,15 @@ 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")
}

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
}

Expand Down

0 comments on commit 60ee696

Please sign in to comment.