Skip to content

Commit b4119c2

Browse files
committed
pkg/cvo/updatepayload: Context around ValidateDirectory calls
These usually either succeed or give os.IsNotExist, but in some cases can return errors like [1]: Unable to download and prepare the update: stat /etc/cvo/updatepayloads/7WNaprXJNWTsPAepCHJ00Q/release-manifests/release-metadata: permission denied. To make it easier to debug those situations, this commit adds context to errors near ValidateDirectory calls, so it's more clear that the issue is the CVO's attempts to read /etc/cvo/... failing, and not an error with the version-... Pod, registry access, etc. Also while I'm in this space, I've replaced the old errors.Wrap in ImageForShortName with fmt.Errorf(...%w, ...), now that the Go standard libraries support error-wrapping like that. One fewer 3rd-party dependency call-site. [1]: https://issues.redhat.com/browse/OCPBUGS-52258
1 parent ff3778c commit b4119c2

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

pkg/cvo/updatepayload.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@ func (r *payloadRetriever) targetUpdatePayloadDir(ctx context.Context, update co
173173
if err := payload.ValidateDirectory(tdir); os.IsNotExist(err) {
174174
// the dirs don't exist, try fetching the payload to tdir.
175175
if err := r.fetchUpdatePayloadToDir(ctx, tdir, update); err != nil {
176-
return "", err
176+
return "", fmt.Errorf("fetching update payload: %s", err)
177177
}
178178
} else if err != nil {
179-
return "", err
179+
return "", fmt.Errorf("checking to see if %q already holds release-image content: %w", tdir, err)
180180
}
181181

182182
// now that payload has been loaded check validation.
183183
if err := payload.ValidateDirectory(tdir); err != nil {
184-
return "", err
184+
return "", fmt.Errorf("confirming the presence of release-image content in %q: %w", tdir, err)
185185
}
186186
return tdir, nil
187187
}

pkg/payload/image.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@ package payload
33
import (
44
"fmt"
55
"path/filepath"
6-
7-
"github.com/pkg/errors"
86
)
97

108
// ImageForShortName returns the image using the updatepayload embedded in
119
// the Operator.
1210
func ImageForShortName(name string) (string, error) {
1311
if err := ValidateDirectory(DefaultPayloadDir); err != nil {
14-
return "", err
12+
return "", fmt.Errorf("error validating %q as a release-image directory: %w", DefaultPayloadDir, err)
1513
}
1614

1715
releaseDir := filepath.Join(DefaultPayloadDir, ReleaseManifestDir)
1816

1917
imageRef, err := loadImageReferences(releaseDir)
2018
if err != nil {
21-
return "", errors.Wrapf(err, "error loading image references from %q", releaseDir)
19+
return "", fmt.Errorf("error loading image references from %q: %w", releaseDir, err)
2220
}
2321

2422
for _, tag := range imageRef.Spec.Tags {

0 commit comments

Comments
 (0)