{"record":{"id":"d81876196e45190f","repo":"kubernetes/kops","slug":"t-is-not-a-compute-backendservice","errorCode":null,"errorMessage":"%T is not a *compute.BackendService","messagePattern":"%T is not a \\*compute\\.BackendService","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/resources/gce/gce.go","lineNumber":1163,"sourceCode":"\t}\n\n\treturn bs, nil\n}\n\nfunc (d *clusterDiscoveryGCE) listHealthchecks() ([]*resources.Resource, error) {\n\tc := d.gceCloud\n\t// TODO: cache, for efficiency, if needed.\n\t// Find relevant healthchecks by finding all the backend services relevant to this\n\t// cluster, then selecting all the healthchecks they use.\n\tbackendServices, err := d.listBackendServices()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\thcs := make(map[string]struct{})\n\tfor _, bs := range backendServices {\n\t\tbsObj, ok := bs.Obj.(*compute.BackendService)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"%T is not a *compute.BackendService\", bs)\n\t\t}\n\t\tfor _, hc := range bsObj.HealthChecks {\n\t\t\thcs[hc] = struct{}{}\n\t\t}\n\t}\n\tvar hcResources []*resources.Resource\n\tfor hc := range hcs {\n\t\thcResources = append(hcResources, &resources.Resource{\n\t\t\tName: gce.LastComponent(hc),\n\t\t\tID:   gce.LastComponent(hc),\n\t\t\tType: typeHealthcheck,\n\t\t\tDeleter: func(cloud fi.Cloud, r *resources.Resource) error {\n\t\t\t\top, err := c.Compute().RegionHealthChecks().Delete(c.Project(), c.Region(), gce.LastComponent(hc))\n\t\t\t\tif err != nil {\n\t\t\t\t\tif gce.IsNotFound(err) {\n\t\t\t\t\t\tklog.Infof(\"Healthcheck not found, assuming deleted: %q\", r.Name)\n\t\t\t\t\t\treturn nil\n\t\t\t\t\t}","sourceCodeStart":1145,"sourceCodeEnd":1181,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/resources/gce/gce.go#L1145-L1181","documentation":"A defensive type assertion in listHealthchecks: a Resource's Obj field was expected to be a *compute.BackendService but held a different type. This indicates an internal inconsistency — listBackendServices returned resources whose payloads are not regional backend services — rather than a user or API failure.","triggerScenarios":"bs.Obj.(*compute.BackendService) fails because the resource tracker was populated with a different compute object type (e.g. a global backend service or a changed API type) — essentially only reachable if the resource list construction in listBackendServices drifts from this consumer's assumption.","commonSituations":"Mixing global vs regional backend service resources; a refactor or vendored cloud-library version change altering the concrete type stored in Resource.Obj; custom code reusing these list functions with other resource kinds.","solutions":["Confirm listBackendServices only inserts results from RegionBackendServices().List.","Check the vendored gce cloud provider library version matches what kops expects (type may differ across versions).","Extend the guard to log which resource produced the wrong type to speed diagnosis.","This is an internal invariant violation — file/inspect kops code rather than changing cloud config."],"exampleFix":"// before\nbsObj, ok := bs.Obj.(*compute.BackendService)\nif !ok {\n\treturn nil, fmt.Errorf(\"%T is not a *compute.BackendService\", bs)\n}\n// after\nbsObj, ok := bs.Obj.(*compute.BackendService)\nif !ok {\n\treturn nil, fmt.Errorf(\"resource %q: %T is not a *compute.BackendService\", bs.ID, bs.Obj)\n}","handlingStrategy":"type-guard","validationCode":"// verify the resource list source before consuming\nif producedByRegionList(backendServices) == false {\n\treturn fmt.Errorf(\"backend services list was not built from RegionBackendServices\")\n}","typeGuard":"func asBackendService(r *resources.Resource) (*compute.BackendService, bool) {\n\tbs, ok := r.Obj.(*compute.BackendService)\n\treturn bs, ok\n}","tryCatchPattern":"bsObj, ok := bs.Obj.(*compute.BackendService)\nif !ok {\n\tklog.Warningf(\"skipping resource %q: %T is not a *compute.BackendService\", bs.ID, bs.Obj)\n\tcontinue\n}","preventionTips":["Keep the gce cloud library version in sync with what kops pins.","Only feed listBackendServices output into listHealthchecks.","Add a log of the concrete type when the assertion fails to spot drift early."],"tags":["gce","type-assertion","backend-service","internal-invariant"],"backgroundTag":"type-assertion-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"}