kubernetes/kops · error
reading data: %w
Error message
reading data: %w
What it means
In kOps' VFS layer, AzureBlobPath.RenderTerraform writes a blob resource into generated Terraform output. Before doing so it slurps the blob contents from the io.Reader passed in; if that read fails (e.g. an underlying reader error), the read error is wrapped as "reading data: %w" so the original cause is preserved for the caller.
Source
Thrown at util/pkg/vfs/azureblob_terraform.go:37
import (
"fmt"
"io"
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
)
type terraformAzureBlobFile struct {
Name string `cty:"name"`
StorageContainerID string `cty:"storage_container_id"`
Type string `cty:"type"`
Source *terraformWriter.Literal `cty:"source"`
Provider *terraformWriter.Literal `cty:"provider"`
}
func (p *AzureBlobPath) RenderTerraform(w *terraformWriter.TerraformWriter, name string, data io.Reader, acl ACL) error {
bytes, err := io.ReadAll(data)
if err != nil {
return fmt.Errorf("reading data: %w", err)
}
w.EnsureTerraformProvider("azurerm", map[string]string{})
if p.account == "" {
return fmt.Errorf("Azure storage account is not set on path %q", p.Path())
}
if w.AzureStorageAccountID == "" {
return fmt.Errorf("Azure storage account ID is not set; it is required to render blob %q", p.Path())
}
source, err := w.AddFilePath("azurerm_storage_blob", name, "source", bytes, false)
if err != nil {
return fmt.Errorf("rendering Azure Blob file: %w", err)
}
tf := &terraformAzureBlobFile{
Name: p.key,View on GitHub (pinned to 4c8573c808)
Solutions
- Inspect the wrapped cause (%w) in the error chain with errors.Unwrap/ %v to see why the read failed
- Verify the source data exists and is readable before calling RenderTerraform
- Ensure the io.Reader is freshly opened and not already exhausted (check for io.EOF consumed earlier)
- Re-run the kops update command after fixing the input file
Example fix
// before
f, _ := os.Open(path)
defer f.Close()
p.RenderTerraform(w, name, f, acl)
// after
f, err := os.Open(path)
if err != nil {
return fmt.Errorf("opening blob source %q: %w", path, err)
}
defer f.Close()
if _, err := f.Stat(); err != nil {
return fmt.Errorf("blob source %q unreadable: %w", path, err)
}
return p.RenderTerraform(w, name, f, acl) Defensive patterns
Strategy: try-catch
Validate before calling
if f, ok := data.(*os.File); ok {
if _, err := f.Stat(); err != nil {
return fmt.Errorf("blob source unreadable: %w", err)
}
} Try / catch
err := p.RenderTerraform(w, name, data, acl)
if err != nil && strings.Contains(err.Error(), "reading data:") {
cause := errors.Unwrap(err)
log.Printf("blob data read failed: %v", cause)
// fix or re-open the source reader, then retry
} Prevention
- Open and verify (Stat/read a probe) the source before handing the reader to RenderTerraform
- Never reuse an already-consumed reader; create a fresh reader per render
- Wrap custom io.Reader implementations to surface errors early
When it happens
Trigger: Calling RenderTerraform on an *AzureBlobPath where the `data io.Reader` argument returns a non-nil error from io.ReadAll — e.g. a reader backed by a file that cannot be opened/read, a network-backed reader, or a reader already consumed/closed.
Common situations: The local file backing the VFS path was deleted or permission-denied before rendering; a bytes.Reader wrapped around a failed asset load; a custom io.Reader implementation erroring mid-read during `kops update cluster --target=terraform`.
Related errors
- Azure storage account is not set on path %q
- Azure storage account ID is not set; it is required to rende
- rendering Azure Blob file: %w
- reading data: %v
- rendering Azure Blob file: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/44cc7b0a7624cfb7.
Report an issue: GitHub.