@@ -35,6 +35,7 @@ import (
35
35
"time"
36
36
37
37
"github.com/PuerkitoBio/purell"
38
+ "github.com/pbnjay/memory"
38
39
"github.com/pkg/errors"
39
40
netutil "k8s.io/apimachinery/pkg/util/net"
40
41
"k8s.io/apimachinery/pkg/util/sets"
@@ -869,6 +870,25 @@ func (ncc NumCPUCheck) Check() (warnings, errorList []error) {
869
870
return warnings , errorList
870
871
}
871
872
873
+ // MemCheck checks if the number of megabytes of memory is not less than required
874
+ type MemCheck struct {
875
+ Mem uint64
876
+ }
877
+
878
+ // Name returns the label for memory
879
+ func (MemCheck ) Name () string {
880
+ return "Mem"
881
+ }
882
+
883
+ // Check number of memory required by kubeadm
884
+ func (mc MemCheck ) Check () (warnings , errorList []error ) {
885
+ actual := memory .TotalMemory () / 1024 / 1024 // TotalMemory returns bytes; convert to MB
886
+ if actual < mc .Mem {
887
+ errorList = append (errorList , errors .Errorf ("the system RAM (%d MB) is less than the minimum %d MB" , actual , mc .Mem ))
888
+ }
889
+ return warnings , errorList
890
+ }
891
+
872
892
// RunInitNodeChecks executes all individual, applicable to control-plane node checks.
873
893
// The boolean flag 'isSecondaryControlPlane' controls whether we are running checks in a --join-control-plane scenario.
874
894
// The boolean flag 'downloadCerts' controls whether we should skip checks on certificates because we are downloading them.
@@ -884,6 +904,7 @@ func RunInitNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigura
884
904
manifestsDir := filepath .Join (kubeadmconstants .KubernetesDir , kubeadmconstants .ManifestsSubDirName )
885
905
checks := []Checker {
886
906
NumCPUCheck {NumCPU : kubeadmconstants .ControlPlaneNumCPU },
907
+ MemCheck {Mem : kubeadmconstants .ControlPlaneMem },
887
908
KubernetesVersionCheck {KubernetesVersion : cfg .KubernetesVersion , KubeadmVersion : kubeadmversion .Get ().GitVersion },
888
909
FirewalldCheck {ports : []int {int (cfg .LocalAPIEndpoint .BindPort ), kubeadmconstants .KubeletPort }},
889
910
PortOpenCheck {port : int (cfg .LocalAPIEndpoint .BindPort )},
0 commit comments