mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +00:00 
			
		
		
		
	Merge pull request #50840 from kad/swapcheck
Automatic merge from submit-queue kubeadm: preflight check for enabled swap **What this PR does / why we need it**: Recent versions of kubelet require special flags if runned on the system with enabled swap. Thus, remind user about either disabling swap or add appropriate flag to kubelet settings **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
		@@ -431,6 +431,32 @@ func (kubever KubernetesVersionCheck) Check() (warnings, errors []error) {
 | 
				
			|||||||
	return nil, nil
 | 
						return nil, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// SwapCheck warns if swap is enabled
 | 
				
			||||||
 | 
					type SwapCheck struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (swc SwapCheck) Check() (warnings, errors []error) {
 | 
				
			||||||
 | 
						f, err := os.Open("/proc/swaps")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							// /proc/swaps not available, thus no reasons to warn
 | 
				
			||||||
 | 
							return nil, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer f.Close()
 | 
				
			||||||
 | 
						var buf []string
 | 
				
			||||||
 | 
						scanner := bufio.NewScanner(f)
 | 
				
			||||||
 | 
						for scanner.Scan() {
 | 
				
			||||||
 | 
							buf = append(buf, scanner.Text())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := scanner.Err(); err != nil {
 | 
				
			||||||
 | 
							return nil, []error{fmt.Errorf("error parsing /proc/swaps: %v", err)}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(buf) > 1 {
 | 
				
			||||||
 | 
							return []error{fmt.Errorf("Running with swap on is not supported. Please disable swap or set kubelet's --fail-swap-on flag to false.")}, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type etcdVersionResponse struct {
 | 
					type etcdVersionResponse struct {
 | 
				
			||||||
	Etcdserver  string `json:"etcdserver"`
 | 
						Etcdserver  string `json:"etcdserver"`
 | 
				
			||||||
	Etcdcluster string `json:"etcdcluster"`
 | 
						Etcdcluster string `json:"etcdcluster"`
 | 
				
			||||||
@@ -586,6 +612,7 @@ func RunInitMasterChecks(cfg *kubeadmapi.MasterConfiguration) error {
 | 
				
			|||||||
		DirAvailableCheck{Path: filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.ManifestsSubDirName)},
 | 
							DirAvailableCheck{Path: filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.ManifestsSubDirName)},
 | 
				
			||||||
		DirAvailableCheck{Path: "/var/lib/kubelet"},
 | 
							DirAvailableCheck{Path: "/var/lib/kubelet"},
 | 
				
			||||||
		FileContentCheck{Path: bridgenf, Content: []byte{'1'}},
 | 
							FileContentCheck{Path: bridgenf, Content: []byte{'1'}},
 | 
				
			||||||
 | 
							SwapCheck{},
 | 
				
			||||||
		InPathCheck{executable: "ip", mandatory: true},
 | 
							InPathCheck{executable: "ip", mandatory: true},
 | 
				
			||||||
		InPathCheck{executable: "iptables", mandatory: true},
 | 
							InPathCheck{executable: "iptables", mandatory: true},
 | 
				
			||||||
		InPathCheck{executable: "mount", mandatory: true},
 | 
							InPathCheck{executable: "mount", mandatory: true},
 | 
				
			||||||
@@ -646,6 +673,7 @@ func RunJoinNodeChecks(cfg *kubeadmapi.NodeConfiguration) error {
 | 
				
			|||||||
		FileAvailableCheck{Path: cfg.CACertPath},
 | 
							FileAvailableCheck{Path: cfg.CACertPath},
 | 
				
			||||||
		FileAvailableCheck{Path: filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.KubeletKubeConfigFileName)},
 | 
							FileAvailableCheck{Path: filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.KubeletKubeConfigFileName)},
 | 
				
			||||||
		FileContentCheck{Path: bridgenf, Content: []byte{'1'}},
 | 
							FileContentCheck{Path: bridgenf, Content: []byte{'1'}},
 | 
				
			||||||
 | 
							SwapCheck{},
 | 
				
			||||||
		InPathCheck{executable: "ip", mandatory: true},
 | 
							InPathCheck{executable: "ip", mandatory: true},
 | 
				
			||||||
		InPathCheck{executable: "iptables", mandatory: true},
 | 
							InPathCheck{executable: "iptables", mandatory: true},
 | 
				
			||||||
		InPathCheck{executable: "mount", mandatory: true},
 | 
							InPathCheck{executable: "mount", mandatory: true},
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user