mirror of https://github.com/k3s-io/k3s
Merge pull request #59292 from JordanFaust/add-cri-socket-to-node-configuration
Automatic merge from submit-queue (batch tested with PRs 59292, 59600). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Add criSocket to kubeadm NodeConfiguration manifest **What this PR does / why we need it**: Adds a criSocket field to the NodeConfiguration manifest used by kubeadm. This field configures the cri socket that kubeadm uses during preflight checks. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # kubernetes/kubeadm#679 **Special notes for your reviewer**: This is a follow up PR, as requested, to https://github.com/kubernetes/kubernetes/pull/59057. The NodeConfiguration manifest now has a criSocket field that can be used when using the config manifest to join a node to the cluster. **Release note**: /area kubeadm /assign @luxas /cc @kubernetes/sig-cluster-lifecycle-pr-reviews ```release-note kubeadm: add criSocket field to NodeConfiguration manifiest ```pull/6/head
commit
a90e43ca32
|
@ -124,6 +124,7 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
|
|||
obj.DiscoveryTokenAPIServers = []string{"foo"}
|
||||
obj.TLSBootstrapToken = "foo"
|
||||
obj.Token = "foo"
|
||||
obj.CRISocket = "foo"
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -217,6 +217,8 @@ type NodeConfiguration struct {
|
|||
TLSBootstrapToken string
|
||||
// Token is used for both discovery and TLS bootstrapping.
|
||||
Token string
|
||||
// CRISocket is used to retrieve container runtime info.
|
||||
CRISocket string
|
||||
|
||||
// DiscoveryTokenCACertHashes specifies a set of public key pins to verify
|
||||
// when token-based discovery is used. The root CA found during discovery
|
||||
|
|
|
@ -49,6 +49,8 @@ const (
|
|||
DefaultImageRepository = "k8s.gcr.io"
|
||||
// DefaultManifestsDir defines default manifests directory
|
||||
DefaultManifestsDir = "/etc/kubernetes/manifests"
|
||||
// DefaultCRISocket defines the default cri socket
|
||||
DefaultCRISocket = "/var/run/dockershim.sock"
|
||||
|
||||
// DefaultEtcdDataDir defines default location of etcd where static pods will save data to
|
||||
DefaultEtcdDataDir = "/var/lib/etcd"
|
||||
|
@ -153,6 +155,9 @@ func SetDefaults_NodeConfiguration(obj *NodeConfiguration) {
|
|||
if len(obj.DiscoveryToken) == 0 && len(obj.DiscoveryFile) == 0 {
|
||||
obj.DiscoveryToken = obj.Token
|
||||
}
|
||||
if obj.CRISocket == "" {
|
||||
obj.CRISocket = DefaultCRISocket
|
||||
}
|
||||
// Make sure file URLs become paths
|
||||
if len(obj.DiscoveryFile) != 0 {
|
||||
u, err := url.Parse(obj.DiscoveryFile)
|
||||
|
|
|
@ -209,6 +209,8 @@ type NodeConfiguration struct {
|
|||
TLSBootstrapToken string `json:"tlsBootstrapToken"`
|
||||
// Token is used for both discovery and TLS bootstrapping.
|
||||
Token string `json:"token"`
|
||||
// CRISocket is used to retrieve container runtime info.
|
||||
CRISocket string `json:"criSocket,omitempty"`
|
||||
|
||||
// DiscoveryTokenCACertHashes specifies a set of public key pins to verify
|
||||
// when token-based discovery is used. The root CA found during discovery
|
||||
|
|
|
@ -336,6 +336,7 @@ func autoConvert_v1alpha1_NodeConfiguration_To_kubeadm_NodeConfiguration(in *Nod
|
|||
out.NodeName = in.NodeName
|
||||
out.TLSBootstrapToken = in.TLSBootstrapToken
|
||||
out.Token = in.Token
|
||||
out.CRISocket = in.CRISocket
|
||||
out.DiscoveryTokenCACertHashes = *(*[]string)(unsafe.Pointer(&in.DiscoveryTokenCACertHashes))
|
||||
out.DiscoveryTokenUnsafeSkipCAVerification = in.DiscoveryTokenUnsafeSkipCAVerification
|
||||
out.FeatureGates = *(*map[string]bool)(unsafe.Pointer(&in.FeatureGates))
|
||||
|
@ -355,6 +356,7 @@ func autoConvert_kubeadm_NodeConfiguration_To_v1alpha1_NodeConfiguration(in *kub
|
|||
out.NodeName = in.NodeName
|
||||
out.TLSBootstrapToken = in.TLSBootstrapToken
|
||||
out.Token = in.Token
|
||||
out.CRISocket = in.CRISocket
|
||||
out.DiscoveryTokenCACertHashes = *(*[]string)(unsafe.Pointer(&in.DiscoveryTokenCACertHashes))
|
||||
out.DiscoveryTokenUnsafeSkipCAVerification = in.DiscoveryTokenUnsafeSkipCAVerification
|
||||
out.FeatureGates = *(*map[string]bool)(unsafe.Pointer(&in.FeatureGates))
|
||||
|
|
|
@ -106,7 +106,6 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
|
|||
|
||||
var skipPreFlight bool
|
||||
var cfgPath string
|
||||
var criSocket string
|
||||
var featureGatesString string
|
||||
var ignorePreflightErrors []string
|
||||
|
||||
|
@ -129,7 +128,7 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
|
|||
ignorePreflightErrorsSet, err := validation.ValidateIgnorePreflightErrors(ignorePreflightErrors, skipPreFlight)
|
||||
kubeadmutil.CheckErr(err)
|
||||
|
||||
j, err := NewJoin(cfgPath, args, internalcfg, ignorePreflightErrorsSet, criSocket)
|
||||
j, err := NewJoin(cfgPath, args, internalcfg, ignorePreflightErrorsSet)
|
||||
kubeadmutil.CheckErr(err)
|
||||
kubeadmutil.CheckErr(j.Validate(cmd))
|
||||
kubeadmutil.CheckErr(j.Run(out))
|
||||
|
@ -137,7 +136,7 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
|
|||
}
|
||||
|
||||
AddJoinConfigFlags(cmd.PersistentFlags(), cfg, &featureGatesString)
|
||||
AddJoinOtherFlags(cmd.PersistentFlags(), &cfgPath, &skipPreFlight, &criSocket, &ignorePreflightErrors)
|
||||
AddJoinOtherFlags(cmd.PersistentFlags(), &cfgPath, &skipPreFlight, &ignorePreflightErrors)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
@ -169,10 +168,14 @@ func AddJoinConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiext.NodeConfigurat
|
|||
featureGatesString, "feature-gates", *featureGatesString,
|
||||
"A set of key=value pairs that describe feature gates for various features. "+
|
||||
"Options are:\n"+strings.Join(features.KnownFeatures(&features.InitFeatureGates), "\n"))
|
||||
flagSet.StringVar(
|
||||
&cfg.CRISocket, "cri-socket", cfg.CRISocket,
|
||||
`Specify the CRI socket to connect to.`,
|
||||
)
|
||||
}
|
||||
|
||||
// AddJoinOtherFlags adds join flags that are not bound to a configuration file to the given flagset
|
||||
func AddJoinOtherFlags(flagSet *flag.FlagSet, cfgPath *string, skipPreFlight *bool, criSocket *string, ignorePreflightErrors *[]string) {
|
||||
func AddJoinOtherFlags(flagSet *flag.FlagSet, cfgPath *string, skipPreFlight *bool, ignorePreflightErrors *[]string) {
|
||||
flagSet.StringVar(
|
||||
cfgPath, "config", *cfgPath,
|
||||
"Path to kubeadm config file.")
|
||||
|
@ -186,10 +189,6 @@ func AddJoinOtherFlags(flagSet *flag.FlagSet, cfgPath *string, skipPreFlight *bo
|
|||
"Skip preflight checks which normally run before modifying the system.",
|
||||
)
|
||||
flagSet.MarkDeprecated("skip-preflight-checks", "it is now equivalent to --ignore-preflight-errors=all")
|
||||
flagSet.StringVar(
|
||||
criSocket, "cri-socket", "/var/run/dockershim.sock",
|
||||
`Specify the CRI socket to connect to.`,
|
||||
)
|
||||
}
|
||||
|
||||
// Join defines struct used by kubeadm join command
|
||||
|
@ -198,7 +197,7 @@ type Join struct {
|
|||
}
|
||||
|
||||
// NewJoin instantiates Join struct with given arguments
|
||||
func NewJoin(cfgPath string, args []string, cfg *kubeadmapi.NodeConfiguration, ignorePreflightErrors sets.String, criSocket string) (*Join, error) {
|
||||
func NewJoin(cfgPath string, args []string, cfg *kubeadmapi.NodeConfiguration, ignorePreflightErrors sets.String) (*Join, error) {
|
||||
|
||||
if cfg.NodeName == "" {
|
||||
cfg.NodeName = nodeutil.GetHostname("")
|
||||
|
@ -217,7 +216,7 @@ func NewJoin(cfgPath string, args []string, cfg *kubeadmapi.NodeConfiguration, i
|
|||
fmt.Println("[preflight] Running pre-flight checks.")
|
||||
|
||||
// Then continue with the others...
|
||||
if err := preflight.RunJoinNodeChecks(utilsexec.New(), cfg, criSocket, ignorePreflightErrors); err != nil {
|
||||
if err := preflight.RunJoinNodeChecks(utilsexec.New(), cfg, ignorePreflightErrors); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -88,8 +88,7 @@ func NewCmdPreFlightNode() *cobra.Command {
|
|||
Example: nodePreflightExample,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cfg := &kubeadmapi.NodeConfiguration{}
|
||||
criSocket := ""
|
||||
err := preflight.RunJoinNodeChecks(utilsexec.New(), cfg, criSocket, sets.NewString())
|
||||
err := preflight.RunJoinNodeChecks(utilsexec.New(), cfg, sets.NewString())
|
||||
kubeadmutil.CheckErr(err)
|
||||
},
|
||||
}
|
||||
|
|
|
@ -949,7 +949,7 @@ func RunInitMasterChecks(execer utilsexec.Interface, cfg *kubeadmapi.MasterConfi
|
|||
}
|
||||
|
||||
// RunJoinNodeChecks executes all individual, applicable to node checks.
|
||||
func RunJoinNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.NodeConfiguration, criSocket string, ignorePreflightErrors sets.String) error {
|
||||
func RunJoinNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.NodeConfiguration, ignorePreflightErrors sets.String) error {
|
||||
// First, check if we're root separately from the other preflight checks and fail fast
|
||||
if err := RunRootCheckOnly(ignorePreflightErrors); err != nil {
|
||||
return err
|
||||
|
@ -966,7 +966,7 @@ func RunJoinNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.NodeConfigura
|
|||
useCRI := len(warns) == 0
|
||||
|
||||
checks := []Checker{
|
||||
SystemVerificationCheck{CRISocket: criSocket},
|
||||
SystemVerificationCheck{CRISocket: cfg.CRISocket},
|
||||
IsPrivilegedUserCheck{},
|
||||
HostnameCheck{cfg.NodeName},
|
||||
KubeletVersionCheck{exec: execer},
|
||||
|
@ -978,7 +978,7 @@ func RunJoinNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.NodeConfigura
|
|||
FileAvailableCheck{Path: filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.KubeletBootstrapKubeConfigFileName)},
|
||||
}
|
||||
if useCRI {
|
||||
checks = append(checks, CRICheck{socket: criSocket, exec: execer})
|
||||
checks = append(checks, CRICheck{socket: cfg.CRISocket, exec: execer})
|
||||
} else {
|
||||
// assume docker
|
||||
checks = append(checks, ServiceCheck{Service: "docker", CheckIfActive: true})
|
||||
|
|
|
@ -259,7 +259,7 @@ func TestRunJoinNodeChecks(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, rt := range tests {
|
||||
actual := RunJoinNodeChecks(exec.New(), rt.cfg, "", sets.NewString())
|
||||
actual := RunJoinNodeChecks(exec.New(), rt.cfg, sets.NewString())
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
"failed RunJoinNodeChecks:\n\texpected: %t\n\t actual: %t",
|
||||
|
|
Loading…
Reference in New Issue