Merge pull request #114489 from aimuz/replace2tag

kubeadm: replace Runtime.GOOS with go:build tag
This commit is contained in:
Kubernetes Prow Robot 2022-12-15 07:27:47 -08:00 committed by GitHub
commit c1c0e4fe0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 111 additions and 36 deletions

View File

@ -525,12 +525,7 @@ func (sysver SystemVerificationCheck) Check() (warnings, errorList []error) {
var validators = []system.Validator{
&system.KernelValidator{Reporter: reporter}}
if runtime.GOOS == "linux" {
//add linux validators
validators = append(validators,
&system.OSValidator{Reporter: reporter},
&system.CgroupsValidator{Reporter: reporter})
}
validators = addOSValidator(validators, reporter)
// Run all validators
for _, v := range validators {
@ -931,11 +926,8 @@ func RunInitNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigura
// Check if Bridge-netfilter and IPv6 relevant flags are set
if ip := netutils.ParseIPSloppy(cfg.LocalAPIEndpoint.AdvertiseAddress); ip != nil {
if netutils.IsIPv6(ip) && runtime.GOOS == "linux" {
checks = append(checks,
FileContentCheck{Path: bridgenf6, Content: []byte{'1'}},
FileContentCheck{Path: ipv6DefaultForwarding, Content: []byte{'1'}},
)
if netutils.IsIPv6(ip) {
checks = addIPv6Checks(checks)
}
}
@ -987,7 +979,6 @@ func RunJoinNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.JoinConfigura
checks = append(checks, FileAvailableCheck{Path: cfg.CACertPath})
}
addIPv6Checks := false
if cfg.Discovery.BootstrapToken != nil {
ipstr, _, err := net.SplitHostPort(cfg.Discovery.BootstrapToken.APIServerEndpoint)
if err == nil {
@ -996,17 +987,11 @@ func RunJoinNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.JoinConfigura
)
if ip := netutils.ParseIPSloppy(ipstr); ip != nil {
if netutils.IsIPv6(ip) {
addIPv6Checks = true
checks = addIPv6Checks(checks)
}
}
}
}
if addIPv6Checks && runtime.GOOS == "linux" {
checks = append(checks,
FileContentCheck{Path: bridgenf6, Content: []byte{'1'}},
FileContentCheck{Path: ipv6DefaultForwarding, Content: []byte{'1'}},
)
}
return RunChecks(checks, os.Stderr, ignorePreflightErrors)
}
@ -1022,23 +1007,9 @@ func addCommonChecks(execer utilsexec.Interface, k8sVersion string, nodeReg *kub
}
// non-windows checks
if runtime.GOOS == "linux" {
checks = append(checks,
FileContentCheck{Path: bridgenf, Content: []byte{'1'}},
FileContentCheck{Path: ipv4Forward, Content: []byte{'1'}},
SwapCheck{},
InPathCheck{executable: "crictl", mandatory: true, exec: execer},
InPathCheck{executable: "conntrack", mandatory: true, exec: execer},
InPathCheck{executable: "ip", mandatory: true, exec: execer},
InPathCheck{executable: "iptables", mandatory: true, exec: execer},
InPathCheck{executable: "mount", mandatory: true, exec: execer},
InPathCheck{executable: "nsenter", mandatory: true, exec: execer},
InPathCheck{executable: "ebtables", mandatory: false, exec: execer},
InPathCheck{executable: "ethtool", mandatory: false, exec: execer},
InPathCheck{executable: "socat", mandatory: false, exec: execer},
InPathCheck{executable: "tc", mandatory: false, exec: execer},
InPathCheck{executable: "touch", mandatory: false, exec: execer})
}
checks = addIPv4Checks(checks)
checks = addSwapCheck(checks)
checks = addExecChecks(checks, execer)
checks = append(checks,
SystemVerificationCheck{},
HostnameCheck{nodeName: nodeReg.Name},

View File

@ -23,6 +23,9 @@ import (
"syscall"
"github.com/pkg/errors"
system "k8s.io/system-validators/validators"
utilsexec "k8s.io/utils/exec"
)
// Check number of memory required by kubeadm
@ -40,3 +43,49 @@ func (mc MemCheck) Check() (warnings, errorList []error) {
}
return warnings, errorList
}
// addOSValidator adds a new OSValidator
func addOSValidator(validators []system.Validator, reporter *system.StreamReporter) []system.Validator {
validators = append(validators, &system.OSValidator{Reporter: reporter}, &system.CgroupsValidator{Reporter: reporter})
return validators
}
// addIPv6Checks adds IPv6 related bridgenf and forwarding checks
func addIPv6Checks(checks []Checker) []Checker {
checks = append(checks,
FileContentCheck{Path: bridgenf6, Content: []byte{'1'}},
FileContentCheck{Path: ipv6DefaultForwarding, Content: []byte{'1'}},
)
return checks
}
// addIPv4Checks adds IPv4 related bridgenf and forwarding checks
func addIPv4Checks(checks []Checker) []Checker {
checks = append(checks,
FileContentCheck{Path: bridgenf, Content: []byte{'1'}},
FileContentCheck{Path: ipv4Forward, Content: []byte{'1'}})
return checks
}
// addSwapCheck adds a swap check
func addSwapCheck(checks []Checker) []Checker {
checks = append(checks, SwapCheck{})
return checks
}
// addExecChecks adds checks that verify if certain binaries are in PATH
func addExecChecks(checks []Checker, execer utilsexec.Interface) []Checker {
checks = append(checks,
InPathCheck{executable: "crictl", mandatory: true, exec: execer},
InPathCheck{executable: "conntrack", mandatory: true, exec: execer},
InPathCheck{executable: "ip", mandatory: true, exec: execer},
InPathCheck{executable: "iptables", mandatory: true, exec: execer},
InPathCheck{executable: "mount", mandatory: true, exec: execer},
InPathCheck{executable: "nsenter", mandatory: true, exec: execer},
InPathCheck{executable: "ebtables", mandatory: false, exec: execer},
InPathCheck{executable: "ethtool", mandatory: false, exec: execer},
InPathCheck{executable: "socat", mandatory: false, exec: execer},
InPathCheck{executable: "tc", mandatory: false, exec: execer},
InPathCheck{executable: "touch", mandatory: false, exec: execer})
return checks
}

View File

@ -0,0 +1,55 @@
//go:build !linux
// +build !linux
/*
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package preflight
import (
system "k8s.io/system-validators/validators"
utilsexec "k8s.io/utils/exec"
)
// addOSValidator adds a new OSValidator
// No-op for Darwin (MacOS), Windows.
func addOSValidator(validators []system.Validator, _ *system.StreamReporter) []system.Validator {
return validators
}
// addIPv6Checks adds IPv6 related bridgenf and forwarding checks
// No-op for Darwin (MacOS), Windows.
func addIPv6Checks(checks []Checker) []Checker {
return checks
}
// addIPv4Checks adds IPv4 related bridgenf and forwarding checks
// No-op for Darwin (MacOS), Windows.
func addIPv4Checks(checks []Checker) []Checker {
return checks
}
// addSwapCheck adds a swap check
// No-op for Darwin (MacOS), Windows.
func addSwapCheck(checks []Checker) []Checker {
return checks
}
// addExecChecks adds checks that verify if certain binaries are in PATH
// No-op for Darwin (MacOS), Windows.
func addExecChecks(checks []Checker, _ utilsexec.Interface) []Checker {
return checks
}