...

Source file src/k8s.io/kubernetes/cmd/kubeadm/app/phases/kubelet/kubelet.go

Documentation: k8s.io/kubernetes/cmd/kubeadm/app/phases/kubelet

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package kubelet
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"k8s.io/klog/v2"
    23  
    24  	kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
    25  	"k8s.io/kubernetes/cmd/kubeadm/app/util/initsystem"
    26  )
    27  
    28  // TryStartKubelet attempts to bring up kubelet service
    29  func TryStartKubelet() {
    30  	// If we notice that the kubelet service is inactive, try to start it
    31  	initSystem, err := initsystem.GetInitSystem()
    32  	if err != nil {
    33  		fmt.Println("[kubelet-start] No supported init system detected, won't make sure the kubelet is running properly.")
    34  		return
    35  	}
    36  
    37  	if !initSystem.ServiceExists(kubeadmconstants.Kubelet) {
    38  		fmt.Println("[kubelet-start] Couldn't detect a kubelet service, can't make sure the kubelet is running properly.")
    39  	}
    40  
    41  	// This runs "systemctl daemon-reload && systemctl restart kubelet"
    42  	if err := initSystem.ServiceRestart(kubeadmconstants.Kubelet); err != nil {
    43  		klog.Warningf("[kubelet-start] WARNING: unable to start the kubelet service: [%v]\n", err)
    44  		fmt.Printf("[kubelet-start] Please ensure kubelet is reloaded and running manually.\n")
    45  	}
    46  }
    47  
    48  // TryStopKubelet attempts to bring down the kubelet service momentarily
    49  func TryStopKubelet() {
    50  	// If we notice that the kubelet service is inactive, try to start it
    51  	initSystem, err := initsystem.GetInitSystem()
    52  	if err != nil {
    53  		fmt.Println("[kubelet-start] No supported init system detected, won't make sure the kubelet not running for a short period of time while setting up configuration for it.")
    54  		return
    55  	}
    56  
    57  	if !initSystem.ServiceExists(kubeadmconstants.Kubelet) {
    58  		fmt.Println("[kubelet-start] Couldn't detect a kubelet service, can't make sure the kubelet not running for a short period of time while setting up configuration for it.")
    59  	}
    60  
    61  	// This runs "systemctl daemon-reload && systemctl stop kubelet"
    62  	if err := initSystem.ServiceStop(kubeadmconstants.Kubelet); err != nil {
    63  		klog.Warningf("[kubelet-start] WARNING: unable to stop the kubelet service momentarily: [%v]\n", err)
    64  	}
    65  }
    66  
    67  // TryRestartKubelet attempts to restart the kubelet service
    68  func TryRestartKubelet() {
    69  	// If we notice that the kubelet service is inactive, try to start it
    70  	initSystem, err := initsystem.GetInitSystem()
    71  	if err != nil {
    72  		fmt.Println("[kubelet-start] No supported init system detected, won't make sure the kubelet not running for a short period of time while setting up configuration for it.")
    73  		return
    74  	}
    75  
    76  	if !initSystem.ServiceExists(kubeadmconstants.Kubelet) {
    77  		fmt.Println("[kubelet-start] Couldn't detect a kubelet service, can't make sure the kubelet not running for a short period of time while setting up configuration for it.")
    78  	}
    79  
    80  	// This runs "systemctl daemon-reload && systemctl stop kubelet"
    81  	if err := initSystem.ServiceRestart(kubeadmconstants.Kubelet); err != nil {
    82  		klog.Warningf("[kubelet-start] WARNING: unable to restart the kubelet service momentarily: [%v]\n", err)
    83  	}
    84  }
    85  

View as plain text