1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

Merge pull request #1558 from marquiz/devel/error-wrap

Wrap nested errors
This commit is contained in:
Kubernetes Prow Robot 2024-01-23 19:37:18 +01:00 committed by GitHub
commit c677736e4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 20 additions and 20 deletions

View file

@ -251,7 +251,7 @@ func (m *nfdMaster) Run() error {
if !m.config.NoPublish {
err := m.updateMasterNode()
if err != nil {
return fmt.Errorf("failed to update master node: %v", err)
return fmt.Errorf("failed to update master node: %w", err)
}
}
@ -368,7 +368,7 @@ func (m *nfdMaster) runGrpcServer(errChan chan<- error) {
// Create server listening for TCP connections
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", m.args.Port))
if err != nil {
errChan <- fmt.Errorf("failed to listen: %v", err)
errChan <- fmt.Errorf("failed to listen: %w", err)
return
}
@ -414,7 +414,7 @@ func (m *nfdMaster) runGrpcServer(errChan chan<- error) {
case err := <-grpcErr:
if err != nil {
errChan <- fmt.Errorf("gRPC server exited with an error: %v", err)
errChan <- fmt.Errorf("gRPC server exited with an error: %w", err)
}
klog.InfoS("gRPC server stopped")
}
@ -552,7 +552,7 @@ func (m *nfdMaster) updateMasterNode() error {
"/metadata/annotations")
err = m.apihelper.PatchNode(cli, node.Name, p)
if err != nil {
return fmt.Errorf("failed to patch node annotations: %v", err)
return fmt.Errorf("failed to patch node annotations: %w", err)
}
return nil
@ -951,7 +951,7 @@ func (m *nfdMaster) setTaints(cli *kubernetes.Clientset, taints []corev1.Taint,
if len(patches) > 0 {
err = m.apihelper.PatchNode(cli, node.Name, patches)
if err != nil {
return fmt.Errorf("error while patching node object: %v", err)
return fmt.Errorf("error while patching node object: %w", err)
}
klog.V(1).InfoS("patched node annotations for taints", "nodeName", nodeName)
}
@ -1112,13 +1112,13 @@ func (m *nfdMaster) updateNodeObject(cli *kubernetes.Clientset, nodeName string,
statusPatches := m.createExtendedResourcePatches(node, extendedResources)
err = m.apihelper.PatchNodeStatus(cli, node.Name, statusPatches)
if err != nil {
return fmt.Errorf("error while patching extended resources: %v", err)
return fmt.Errorf("error while patching extended resources: %w", err)
}
// Patch the node object in the apiserver
err = m.apihelper.PatchNode(cli, node.Name, patches)
if err != nil {
return fmt.Errorf("error while patching node object: %v", err)
return fmt.Errorf("error while patching node object: %w", err)
}
if len(patches) > 0 || len(statusPatches) > 0 {
@ -1235,7 +1235,7 @@ func (m *nfdMaster) configure(filepath string, overrides string) error {
// Parse config overrides
if err := yaml.Unmarshal([]byte(overrides), c); err != nil {
return fmt.Errorf("failed to parse -options: %s", err)
return fmt.Errorf("failed to parse -options: %w", err)
}
if m.args.Overrides.NoPublish != nil {
c.NoPublish = *m.args.Overrides.NoPublish

View file

@ -153,7 +153,7 @@ func (resMon *PodResourcesScanner) Scan() (ScanResponse, error) {
hasDevice := hasDevice(podResource)
isWatchable, isIntegralGuaranteed, err := resMon.isWatchable(podResource.GetNamespace(), podResource.GetName(), hasDevice)
if err != nil {
return ScanResponse{}, fmt.Errorf("checking if pod in a namespace is watchable, namespace:%v, pod name %v: %v", podResource.GetNamespace(), podResource.GetName(), err)
return ScanResponse{}, fmt.Errorf("checking if pod in a namespace is watchable, namespace:%v, pod name %v: %w", podResource.GetNamespace(), podResource.GetName(), err)
}
if !isWatchable {
continue

View file

@ -67,7 +67,7 @@ func (w *FsWatcher) reset(names ...string) error {
func (w *FsWatcher) initWatcher() error {
if w.Watcher != nil {
if err := w.Watcher.Close(); err != nil {
return fmt.Errorf("failed to close fsnotify watcher: %v", err)
return fmt.Errorf("failed to close fsnotify watcher: %w", err)
}
}
w.paths = make(map[string]struct{})
@ -75,7 +75,7 @@ func (w *FsWatcher) initWatcher() error {
watcher, err := fsnotify.NewWatcher()
if err != nil {
w.Watcher = nil
return fmt.Errorf("failed to create fsnotify watcher: %v", err)
return fmt.Errorf("failed to create fsnotify watcher: %w", err)
}
w.Watcher = watcher

View file

@ -52,7 +52,7 @@ func MergeKlogConfiguration(klogArgs map[string]*utils.KlogFlagVal, klogConfig K
v = a.DefValue()
}
if err := a.SetFromConfig(v); err != nil {
return fmt.Errorf("failed to set logger option klog.%s = %v: %v", k, v, err)
return fmt.Errorf("failed to set logger option klog.%s = %v: %w", k, v, err)
}
}
}

View file

@ -47,12 +47,12 @@ func (c *TlsConfig) UpdateConfig(certFile, keyFile, caFile string) error {
// Load cert for authenticating this server
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
return fmt.Errorf("failed to load server certificate: %v", err)
return fmt.Errorf("failed to load server certificate: %w", err)
}
// Load CA cert for client cert verification
caCert, err := os.ReadFile(caFile)
if err != nil {
return fmt.Errorf("failed to read root certificate file: %v", err)
return fmt.Errorf("failed to read root certificate file: %w", err)
}
caPool := x509.NewCertPool()
if ok := caPool.AppendCertsFromPEM(caCert); !ok {

View file

@ -69,7 +69,7 @@ func discoverSSTBF() (bool, error) {
effectiveBaseFreq, err := strconv.Atoi(strings.TrimSpace(string(data)))
if err != nil {
return false, fmt.Errorf("non-integer value of %q: %v", filePath, err)
return false, fmt.Errorf("non-integer value of %q: %w", filePath, err)
}
// Sanity check: Return an error (we don't have enough information to

View file

@ -291,7 +291,7 @@ func getFeaturesFromHooks() (map[string]string, map[string]string, error) {
klog.InfoS("hook directory does not exist", "path", hookDir)
return features, labels, nil
}
return features, labels, fmt.Errorf("unable to access %v: %v", hookDir, err)
return features, labels, fmt.Errorf("unable to access %v: %w", hookDir, err)
}
if len(files) > 0 {
klog.InfoS("hooks are DEPRECATED since v0.12.0 and support will be removed in a future release; use feature files instead")
@ -382,7 +382,7 @@ func getFeaturesFromFiles() (map[string]string, map[string]string, error) {
klog.InfoS("features directory does not exist", "path", featureFilesDir)
return features, labels, nil
}
return features, labels, fmt.Errorf("unable to access %v: %v", featureFilesDir, err)
return features, labels, fmt.Errorf("unable to access %v: %w", featureFilesDir, err)
}
for _, file := range files {

View file

@ -36,7 +36,7 @@ var optionalDevAttrs = []string{"sriov_totalvfs", "iommu_group/type", "iommu/int
func readSinglePciAttribute(devPath string, attrName string) (string, error) {
data, err := os.ReadFile(filepath.Join(devPath, attrName))
if err != nil {
return "", fmt.Errorf("failed to read device attribute %s: %v", attrName, err)
return "", fmt.Errorf("failed to read device attribute %s: %w", attrName, err)
}
// Strip whitespace and '0x' prefix
attrVal := strings.TrimSpace(strings.TrimPrefix(string(data), "0x"))
@ -55,7 +55,7 @@ func readPciDevInfo(devPath string) (*nfdv1alpha1.InstanceFeature, error) {
for _, attr := range mandatoryDevAttrs {
attrVal, err := readSinglePciAttribute(devPath, attr)
if err != nil {
return nil, fmt.Errorf("failed to read device %s: %s", attr, err)
return nil, fmt.Errorf("failed to read device %s: %w", attr, err)
}
attrs[attr] = attrVal
}

View file

@ -43,7 +43,7 @@ var devAttrFileMap = map[string]string{
func readSingleUsbSysfsAttribute(path string) (string, error) {
data, err := os.ReadFile(path)
if err != nil {
return "", fmt.Errorf("failed to read device attribute %s: %v", filepath.Base(path), err)
return "", fmt.Errorf("failed to read device attribute %s: %w", filepath.Base(path), err)
}
attrVal := strings.TrimSpace(string(data))