Merge pull request #133893 from HirazawaUi/close-connections

Kubeadm: Close container runtime connections after use
This commit is contained in:
Kubernetes Prow Robot 2025-09-06 01:35:24 -07:00 committed by GitHub
commit d9b31d602d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 0 deletions

View file

@ -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,

View file

@ -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

View file

@ -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 {

View file

@ -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()