...

Source file src/k8s.io/kubernetes/cmd/kubeadm/app/preflight/checks_linux.go

Documentation: k8s.io/kubernetes/cmd/kubeadm/app/preflight

     1  //go:build linux
     2  // +build linux
     3  
     4  /*
     5  Copyright 2019 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  package preflight
    21  
    22  import (
    23  	"syscall"
    24  
    25  	"github.com/pkg/errors"
    26  
    27  	system "k8s.io/system-validators/validators"
    28  	utilsexec "k8s.io/utils/exec"
    29  )
    30  
    31  // Check number of memory required by kubeadm
    32  func (mc MemCheck) Check() (warnings, errorList []error) {
    33  	info := syscall.Sysinfo_t{}
    34  	err := syscall.Sysinfo(&info)
    35  	if err != nil {
    36  		errorList = append(errorList, errors.Wrapf(err, "failed to get system info"))
    37  	}
    38  
    39  	// Totalram holds the total usable memory. Unit holds the size of a memory unit in bytes. Multiply them and convert to MB
    40  	actual := uint64(info.Totalram) * uint64(info.Unit) / 1024 / 1024
    41  	if actual < mc.Mem {
    42  		errorList = append(errorList, errors.Errorf("the system RAM (%d MB) is less than the minimum %d MB", actual, mc.Mem))
    43  	}
    44  	return warnings, errorList
    45  }
    46  
    47  // addOSValidator adds a new OSValidator
    48  func addOSValidator(validators []system.Validator, reporter *system.StreamReporter) []system.Validator {
    49  	validators = append(validators, &system.OSValidator{Reporter: reporter}, &system.CgroupsValidator{Reporter: reporter})
    50  	return validators
    51  }
    52  
    53  // addIPv6Checks adds IPv6 related checks
    54  func addIPv6Checks(checks []Checker) []Checker {
    55  	checks = append(checks,
    56  		FileContentCheck{Path: ipv6DefaultForwarding, Content: []byte{'1'}},
    57  	)
    58  	return checks
    59  }
    60  
    61  // addIPv4Checks adds IPv4 related checks
    62  func addIPv4Checks(checks []Checker) []Checker {
    63  	checks = append(checks,
    64  		FileContentCheck{Path: ipv4Forward, Content: []byte{'1'}})
    65  	return checks
    66  }
    67  
    68  // addSwapCheck adds a swap check
    69  func addSwapCheck(checks []Checker) []Checker {
    70  	checks = append(checks, SwapCheck{})
    71  	return checks
    72  }
    73  
    74  // addExecChecks adds checks that verify if certain binaries are in PATH
    75  func addExecChecks(checks []Checker, execer utilsexec.Interface) []Checker {
    76  	checks = append(checks,
    77  		InPathCheck{executable: "crictl", mandatory: true, exec: execer},
    78  		InPathCheck{executable: "conntrack", mandatory: true, exec: execer},
    79  		InPathCheck{executable: "ip", mandatory: true, exec: execer},
    80  		InPathCheck{executable: "iptables", mandatory: true, exec: execer},
    81  		InPathCheck{executable: "mount", mandatory: true, exec: execer},
    82  		InPathCheck{executable: "nsenter", mandatory: true, exec: execer},
    83  		InPathCheck{executable: "ebtables", mandatory: false, exec: execer},
    84  		InPathCheck{executable: "ethtool", mandatory: false, exec: execer},
    85  		InPathCheck{executable: "socat", mandatory: false, exec: execer},
    86  		InPathCheck{executable: "tc", mandatory: false, exec: execer},
    87  		InPathCheck{executable: "touch", mandatory: false, exec: execer})
    88  	return checks
    89  }
    90  

View as plain text