kubernetes/kops · error
error fetching %s: %v
Error message
error fetching %s: %v
What it means
WriteToWithContext downloads an object with GetObject. A NoSuchKey AWS error is translated to os.ErrNotExist; any other failure is wrapped as "error fetching <path>: <underlying error>". Note NoSuchBucket/AccessDenied are NOT mapped to ErrNotExist and surface here.
Source
Thrown at util/pkg/vfs/s3fs.go:420
// WriteToWithContext implements io.WriterTo, but adds a context
func (p *S3Path) WriteToWithContext(ctx context.Context, out io.Writer) (int64, error) {
client, err := p.client(ctx)
if err != nil {
return 0, err
}
klog.V(4).Infof("Reading file %q", p)
request := &s3.GetObjectInput{}
request.Bucket = aws.String(p.bucket)
request.Key = aws.String(p.key)
response, err := client.GetObject(ctx, request)
if err != nil {
if AWSErrorCode(err) == "NoSuchKey" {
return 0, os.ErrNotExist
}
return 0, fmt.Errorf("error fetching %s: %v", p, err)
}
defer response.Body.Close()
n, err := io.Copy(out, response.Body)
if err != nil {
return n, fmt.Errorf("error reading %s: %v", p, err)
}
return n, nil
}
func (p *S3Path) ReadDir() ([]Path, error) {
ctx := context.TODO()
client, err := p.client(ctx)
if err != nil {
return nil, err
}
prefix := p.keyView on GitHub (pinned to 4c8573c808)
Solutions
- Read the wrapped AWS error: NoSuchBucket → fix the bucket name in KOPS_STATE_STORE; AccessDenied → grant s3:GetObject
- Check os.IsNotExist(err) first — missing keys are returned as os.ErrNotExist, not this error
- Verify bucket region matches the client region (wrong region gives AuthorizationHeaderMalformed/301)
- Ensure KMS key policy allows decryption if the bucket enforces SSE-KMS
Example fix
// before
data, err := vfs.Context.ReadFile(p)
if err != nil { return err } // conflates missing vs denied
// after
if _, err := vfs.Context.ReadFile(p); err != nil {
if errors.Is(err, os.ErrNotExist) { return createDefaults() }
return fmt.Errorf("reading state %s: %w", p, err)
} Defensive patterns
Strategy: try-catch
Validate before calling
// Probe bucket existence/permissions before reads
_, err := s3Client.HeadBucket(ctx, &s3.HeadBucketInput{Bucket: bucket})
if err != nil { return fmt.Errorf("state store bucket %s unusable: %w", bucket, err) } Try / catch
data, err := vfs.Context.ReadFile(p)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil, errStateNotFound // missing key path
}
if code := AWSErrorCode(errors.Unwrap(err)); code == "NoSuchBucket" || code == "AccessDenied" {
return nil, fmt.Errorf("state store misconfigured (%s): %w", code, err)
}
return nil, err
} Prevention
- Check errors.Is(err, os.ErrNotExist) first — the library already maps NoSuchKey
- Validate KOPS_STATE_STORE bucket name and region before cluster operations
- Grant s3:GetObject on the state prefix to the reading principal
- Confirm KMS key access when the bucket enforces SSE-KMS
When it happens
Trigger: Calling ReadFile/WriteTo on an S3Path when GetObject fails for reasons other than missing key: AccessDenied on the key; NoSuchBucket (wrong bucket name/region); KMS decryption failure; throttling; network errors.
Common situations: Pointing KOPS_STATE_STORE at a nonexistent or mistyped bucket; credentials lacking s3:GetObject; a cluster state file deleted by another process but versioning absent so GetObject 404s (that path returns ErrNotExist, not this); VPC endpoint misconfigurations.
Related errors
- failed to generate AWS IAM S3 access statements: %v
- unknown writeable path, can't apply IAM policy: %q
- checking if bucket was public: %w
- error removing %d files: %w
- error listing all versions of file %s: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/710132dfeabb73c5.
Report an issue: GitHub.