Troubleshoot the Go Library
This page covers the errors that the resource package of the Go library returns at runtime. They occur when code reads a part of a definition that the definition does not have, or when a pod cannot be tied to a component instance. For validation errors in a definition, refer to Troubleshoot Definitions. For how to use the library, refer to Use the Go Library.
Accessor Errors
The message of DefinitionNotFoundError names the missing part. It has one of the following forms, with the name of the component in place of <name>:
component <name> does not have spec definitioncomponent <name> does not have pod template spec definitioncomponent <name> does not have pod spec definitioncomponent <name> does not have pod metadata definitioncomponent <name> does not have fragmented pod spec definitioncomponent <name> does not have scale definitioncomponent <name> does not have status definitioncomponent <name> does not have suspendDefinition
What Each Method Returns
When a component does not define a part, the result depends on which method you call:
- The read methods of a component return
niland no error when the component does not define the part. These areGetPodTemplateSpec,GetPodSpec,GetPodMetadata,GetFragmentedPodSpec,GetScale, andGetStatus. If a read method returnsniland you expected data, the component does not define that part. Check the definition of the component. - The update methods of a component return the error. These are
UpdatePodTemplateSpec,UpdatePodSpec,UpdatePodMetadata, andUpdateFragmentedPodSpec. Calling one on a component without the matching part returnsDefinitionNotFoundError. - The suspend methods
SuspendandResumedo nothing when the component has nosuspendDefinition.
To avoid the error, check what a component defines before you call a method:
The example controller uses HasPodDefinition() before it reads or changes the pods of a component. The check is true for any of the three pod patterns, but each update method works only with its own pattern. For example, UpdatePodTemplateSpec returns DefinitionNotFoundError for a component that uses podSpecPath. Call the update method that matches the pattern of the component.
To handle the errors in your own code, match them with errors.As: