mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-02-22 15:19:12 +00:00
Merge pull request #131970 from skitt/kubelet-pkg-errors
kubelet: drop dependency on github.com/pkg/errors
This commit is contained in:
@@ -39,7 +39,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubelet/prober"
|
||||
"k8s.io/kubernetes/pkg/windows/service"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sys/windows/registry"
|
||||
"golang.org/x/sys/windows/svc/mgr"
|
||||
)
|
||||
@@ -161,44 +160,44 @@ func (m *managerImpl) start() (chan struct{}, error) {
|
||||
// Process the shutdown only when it is running as a windows service
|
||||
isServiceInitialized := service.IsServiceInitialized()
|
||||
if !isServiceInitialized {
|
||||
return nil, errors.Errorf("%s is NOT running as a Windows service", serviceKubelet)
|
||||
return nil, fmt.Errorf("%s is NOT running as a Windows service", serviceKubelet)
|
||||
}
|
||||
|
||||
// Update the registry key to add the kubelet dependencies to the existing order
|
||||
mgr, err := mgr.Connect()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Could not connect to service manager")
|
||||
return nil, fmt.Errorf("Could not connect to service manager: %w", err)
|
||||
}
|
||||
defer mgr.Disconnect()
|
||||
|
||||
s, err := mgr.OpenService(serviceKubelet)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Could not access service %s", serviceKubelet)
|
||||
return nil, fmt.Errorf("Could not access service %s: %w", serviceKubelet, err)
|
||||
}
|
||||
defer s.Close()
|
||||
|
||||
preshutdownInfo, err := service.QueryPreShutdownInfo(s.Handle)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Could not query preshutdown info")
|
||||
return nil, fmt.Errorf("Could not query preshutdown info: %w", err)
|
||||
}
|
||||
m.logger.V(1).Info("Shutdown manager get current preshutdown info", "PreshutdownTimeout", preshutdownInfo.PreshutdownTimeout)
|
||||
|
||||
config, err := s.Config()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Could not access config of service %s", serviceKubelet)
|
||||
return nil, fmt.Errorf("Could not access config of service %s: %w", serviceKubelet, err)
|
||||
}
|
||||
|
||||
// Open the registry key
|
||||
key, err := registry.OpenKey(registry.LOCAL_MACHINE, shutdownOrderRegPath, registry.QUERY_VALUE|registry.SET_VALUE)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Could not access registry")
|
||||
return nil, fmt.Errorf("Could not access registry: %w", err)
|
||||
}
|
||||
defer key.Close()
|
||||
|
||||
// Read the existing values
|
||||
existingOrders, _, err := key.GetStringsValue(shutdownOrderStringValue)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Could not access registry value %s", shutdownOrderStringValue)
|
||||
return nil, fmt.Errorf("Could not access registry value %s: %w", shutdownOrderStringValue, err)
|
||||
}
|
||||
m.logger.V(1).Info("Shutdown manager get current service preshutdown order", "Preshutdownorder", existingOrders)
|
||||
|
||||
@@ -206,7 +205,7 @@ func (m *managerImpl) start() (chan struct{}, error) {
|
||||
newOrders := addToExistingOrder(config.Dependencies, existingOrders)
|
||||
err = key.SetStringsValue("PreshutdownOrder", newOrders)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Could not set registry %s to be new value %s", shutdownOrderStringValue, newOrders)
|
||||
return nil, fmt.Errorf("Could not set registry %s to be new value %s: %w", shutdownOrderStringValue, newOrders, err)
|
||||
}
|
||||
|
||||
// If the preshutdown timeout is less than periodRequested, attempt to update the value to periodRequested.
|
||||
|
||||
@@ -20,6 +20,8 @@ limitations under the License.
|
||||
package winstats
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
@@ -33,7 +35,6 @@ import (
|
||||
kubefeatures "k8s.io/kubernetes/pkg/features"
|
||||
|
||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sys/windows"
|
||||
"golang.org/x/sys/windows/registry"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
@@ -296,13 +297,13 @@ func (p *perfCounterNodeStatsClient) getCPUUsageNanoCores() uint64 {
|
||||
func getSystemUUID() (string, error) {
|
||||
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\HardwareConfig`, registry.QUERY_VALUE)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to open registry key HKLM\\SYSTEM\\HardwareConfig")
|
||||
return "", fmt.Errorf("failed to open registry key HKLM\\SYSTEM\\HardwareConfig: %w", err)
|
||||
}
|
||||
defer k.Close()
|
||||
|
||||
uuid, _, err := k.GetStringValue("LastConfig")
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to read registry value LastConfig from key HKLM\\SYSTEM\\HardwareConfig")
|
||||
return "", fmt.Errorf("failed to read registry value LastConfig from key HKLM\\SYSTEM\\HardwareConfig: %w", err)
|
||||
}
|
||||
|
||||
uuid = strings.Trim(uuid, "{")
|
||||
|
||||
Reference in New Issue
Block a user