{"record":{"id":"daaa4fe11a5c6762","repo":"kubernetes/kops","slug":"failed-to-list-vpcs-v","errorCode":null,"errorMessage":"failed to list vpcs: %v","messagePattern":"failed to list vpcs: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/resources/digitalocean/resources.go","lineNumber":462,"sourceCode":"\t\tif response != nil && response.StatusCode == http.StatusNotFound {\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"failed to delete ssh key %s (ID %s): %s\", t.Name, t.ID, err)\n\t}\n\n\treturn nil\n}\n\nfunc listVPCs(cloud fi.Cloud, clusterName string) ([]*resources.Resource, error) {\n\tc := cloud.(do.DOCloud)\n\tvar resourceTrackers []*resources.Resource\n\n\tclusterName = do.SafeClusterName(clusterName)\n\tvpcName := \"vpc-\" + clusterName\n\n\tvpcs, err := c.GetAllVPCs()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to list vpcs: %v\", err)\n\t}\n\n\tfor _, vpc := range vpcs {\n\t\tif vpc.Name == vpcName {\n\t\t\tresourceTracker := &resources.Resource{\n\t\t\t\tName:    vpc.Name,\n\t\t\t\tID:      vpc.ID,\n\t\t\t\tType:    resourceTypeVPC,\n\t\t\t\tDeleter: deleteVPC,\n\t\t\t\tObj:     vpc,\n\t\t\t}\n\n\t\t\tresourceTrackers = append(resourceTrackers, resourceTracker)\n\t\t}\n\t}\n\n\treturn resourceTrackers, nil\n}","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/resources/digitalocean/resources.go#L444-L480","documentation":"listVPCs wraps any failure from the DigitalOcean API client's GetAllVPCs() call. The library throws it when the underlying godo VPC list request fails (auth, network, API error), aborting discovery of the cluster's 'vpc-<clustername>' VPC resource. The original API error is embedded via %v.","triggerScenarios":"c.GetAllVPCs() returns an error: invalid/expired DigitalOcean API token, network failure or timeout talking to api.digitalocean.com, DO API 5xx outage, or rate limiting (429) during kops cluster listing/deletion.","commonSituations":"Running 'kops delete cluster' or 'kops get' against a DigitalOcean cluster with a revoked DO_TOKEN, a misconfigured credentials file, corporate proxy blocking the API, or transient DO API incidents.","solutions":["Verify the DigitalOcean API token is valid and has read scope (doctl auth check or curl -H 'Authorization: Bearer <token>' https://api.digitalocean.com/v2/vpcs).","Inspect the wrapped inner error (%v output) for the real cause: 401 => bad token, 429 => rate limited, 5xx/timeout => DO outage; fix accordingly.","Check network/proxy connectivity from the machine running kops to api.digitalocean.com (DNS, firewall, HTTPS_PROXY settings).","If rate-limited, wait for the rate-limit window to reset and retry; if it's a transient DO incident, retry after api.status.digitalocean.com shows healthy."],"exampleFix":"// before\nvpcs, err := c.GetAllVPCs()\nif err != nil {\n\treturn nil, fmt.Errorf(\"failed to list vpcs: %v\", err)\n}\n// after\nvpcs, err := c.GetAllVPCs()\nif err != nil {\n\treturn nil, fmt.Errorf(\"failed to list vpcs: %w\", err) // preserve chain; callers can errors.Is/As the godo error\n}","handlingStrategy":"try-catch","validationCode":"// preflight: token must be set and callable\nif os.Getenv(\"DIGITALOCEAN_ACCESS_TOKEN\") == \"\" && doToken == \"\" {\n\treturn fmt.Errorf(\"DigitalOcean access token is not configured\")\n}\n// optionally: doctl auth check / GET /v2/vpcs?per_page=1 to confirm API reachability","typeGuard":"func isDOAPIError(err error) (code int, ok bool) {\n\tvar goe *godo.ErrorResponse\n\tif errors.As(err, &goe) {\n\t\treturn goe.Response.StatusCode, true\n\t}\n\treturn 0, false\n}","tryCatchPattern":"_, err := c.GetAllVPCs()\nif err != nil {\n\tvar goe *godo.ErrorResponse\n\tswitch {\n\tcase errors.As(err, &goe) && goe.Response.StatusCode == http.StatusUnauthorized:\n\t\t// refresh DO token\n\tcase errors.As(err, &goe) && goe.Response.StatusCode == http.StatusTooManyRequests:\n\t\t// back off and retry after rate-limit reset\n\tdefault:\n\t\t// transient: retry with backoff\n\t}\n\treturn fmt.Errorf(\"failed to list vpcs: %w\", err)\n}","preventionTips":["Set and periodically rotate a valid DigitalOcean API token with read scope","Check api.status.digitalocean.com before bulk cluster operations","Configure proxy/firewall to allow HTTPS to api.digitalocean.com","Add retry-with-backoff around DO API list calls for 429/5xx"],"tags":["digitalocean","api","network","authentication"],"backgroundTag":"cloud-api-request-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}