mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-08-08 23:37:11 +00:00
Merge pull request #133893 from HirazawaUi/close-connections
Kubeadm: Close container runtime connections after use
This commit is contained in:
@@ -387,6 +387,7 @@ func newCmdConfigImagesPull() *cobra.Command {
|
||||
if err := containerRuntime.Connect(); err != nil {
|
||||
return err
|
||||
}
|
||||
defer containerRuntime.Close()
|
||||
return PullControlPlaneImages(containerRuntime, &internalcfg.ClusterConfiguration)
|
||||
},
|
||||
Args: cobra.NoArgs,
|
||||
|
||||
@@ -138,6 +138,8 @@ func removeContainers(criSocketPath string) error {
|
||||
if err := containerRuntime.Connect(); err != nil {
|
||||
return err
|
||||
}
|
||||
defer containerRuntime.Close()
|
||||
|
||||
containers, err := containerRuntime.ListKubeContainers()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -84,6 +84,7 @@ func (ContainerRuntimeCheck) Name() string {
|
||||
// Check validates the container runtime
|
||||
func (crc ContainerRuntimeCheck) Check() (warnings, errorList []error) {
|
||||
klog.V(1).Infoln("validating the container runtime")
|
||||
defer crc.runtime.Close()
|
||||
if err := crc.runtime.IsRunning(); err != nil {
|
||||
errorList = append(errorList, err)
|
||||
}
|
||||
@@ -1087,6 +1088,7 @@ func RunPullImagesCheck(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigur
|
||||
if err := containerRuntime.Connect(); err != nil {
|
||||
return handleError(os.Stderr, err.Error())
|
||||
}
|
||||
defer containerRuntime.Close()
|
||||
|
||||
serialPull := true
|
||||
if cfg.NodeRegistration.ImagePullSerial != nil {
|
||||
|
||||
@@ -42,6 +42,7 @@ var defaultKnownCRISockets = []string{
|
||||
// ContainerRuntime is an interface for working with container runtimes
|
||||
type ContainerRuntime interface {
|
||||
Connect() error
|
||||
Close()
|
||||
SetImpl(impl)
|
||||
IsRunning() error
|
||||
ListKubeContainers() ([]string, error)
|
||||
@@ -93,6 +94,20 @@ func (runtime *CRIRuntime) Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close closes the connections to the runtime and image services.
|
||||
func (runtime *CRIRuntime) Close() {
|
||||
if runtime.runtimeService != nil {
|
||||
if err := runtime.runtimeService.Close(); err != nil {
|
||||
klog.Warningf("failed to close runtime service: %v", err)
|
||||
}
|
||||
}
|
||||
if runtime.imageService != nil {
|
||||
if err := runtime.imageService.Close(); err != nil {
|
||||
klog.Warningf("failed to close image service: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IsRunning checks if runtime is running.
|
||||
func (runtime *CRIRuntime) IsRunning() error {
|
||||
ctx, cancel := defaultContext()
|
||||
|
||||
Reference in New Issue
Block a user