Skip to content

Commit

Permalink
OCPBUGS-45861: validate image property isn't nil before using
Browse files Browse the repository at this point in the history
even though we do not expect these two properties to be nil (Image and
Err) we better check them to avoid having panics if something changes in
the future.

this pr introduces the same guardrails used in two different parts of
the code: makes sure we have at least one of `Err` or `Image` properties
set.
  • Loading branch information
ricardomaraschini committed Jan 21, 2025
1 parent 4eee01a commit c3ac45e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/image/apiserver/importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,22 @@ func (imp *ImageStreamImporter) importImages(ctx context.Context, isi *imageapi.
cache[j] = digest.Image
}
for _, index := range ids[j] {
// we have seen the below state in our internal CI clusters. we think
// it's caused by outages in the upstream registry, but we're not sure
// exactly how we end up in this situation where neither error or image
// are set. to protect against that we throw a generic error when it
// happens.
// See https://issues.redhat.com/browse/OCPBUGS-35036 for details.
if digest.Image == nil && digest.Err == nil {
errMsg := fmt.Sprintf(
"unknown error while importing digest %q from repository %q with import mode %q, please try again.",
digest.Name,
repo.Name,
digest.ImportMode,
)
digest.Err = errors.New(errMsg)
klog.Infof("importImages: both digest image and error are nil! repo=%+v digest=%+v", repo, digest)
}
if digest.Err != nil {
setImageImportStatus(isi, index, "", digest.Err)
continue
Expand Down

0 comments on commit c3ac45e

Please sign in to comment.