mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
use default unkown sock for kubeadm cmd if cri detect is not needed
Signed-off-by: pacoxu <paco.xu@daocloud.io>
This commit is contained in:
parent
17bb2fc050
commit
bd3a74fece
@ -58,7 +58,7 @@ func NewCmdKubeConfigUtility(out io.Writer) *cobra.Command {
|
|||||||
// newCmdUserKubeConfig returns sub commands for kubeconfig phase
|
// newCmdUserKubeConfig returns sub commands for kubeconfig phase
|
||||||
func newCmdUserKubeConfig(out io.Writer) *cobra.Command {
|
func newCmdUserKubeConfig(out io.Writer) *cobra.Command {
|
||||||
|
|
||||||
initCfg := &kubeadmapiv1beta2.InitConfiguration{}
|
initCfg := cmdutil.DefaultInitConfiguration()
|
||||||
clusterCfg := &kubeadmapiv1beta2.ClusterConfiguration{}
|
clusterCfg := &kubeadmapiv1beta2.ClusterConfiguration{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -134,7 +134,7 @@ func (o *genCSRConfig) addFlagSet(flagSet *pflag.FlagSet) {
|
|||||||
func (o *genCSRConfig) load() (err error) {
|
func (o *genCSRConfig) load() (err error) {
|
||||||
o.kubeadmConfig, err = configutil.LoadOrDefaultInitConfiguration(
|
o.kubeadmConfig, err = configutil.LoadOrDefaultInitConfiguration(
|
||||||
o.kubeadmConfigPath,
|
o.kubeadmConfigPath,
|
||||||
&kubeadmapiv1beta2.InitConfiguration{},
|
cmdutil.DefaultInitConfiguration(),
|
||||||
&kubeadmapiv1beta2.ClusterConfiguration{},
|
&kubeadmapiv1beta2.ClusterConfiguration{},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -359,7 +359,7 @@ func getInternalCfg(cfgPath string, kubeconfigPath string, cfg kubeadmapiv1beta2
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise read config from --config if provided, otherwise use default configuration
|
// Otherwise read config from --config if provided, otherwise use default configuration
|
||||||
return configutil.LoadOrDefaultInitConfiguration(cfgPath, &kubeadmapiv1beta2.InitConfiguration{}, &cfg)
|
return configutil.LoadOrDefaultInitConfiguration(cfgPath, cmdutil.DefaultInitConfiguration(), &cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// newCmdCertsExpiration creates a new `cert check-expiration` command.
|
// newCmdCertsExpiration creates a new `cert check-expiration` command.
|
||||||
|
@ -455,14 +455,7 @@ func newCmdConfigImagesList(out io.Writer, mockK8sVersion *string) *cobra.Comman
|
|||||||
|
|
||||||
// NewImagesList returns the underlying struct for the "kubeadm config images list" command
|
// NewImagesList returns the underlying struct for the "kubeadm config images list" command
|
||||||
func NewImagesList(cfgPath string, cfg *kubeadmapiv1beta2.ClusterConfiguration) (*ImagesList, error) {
|
func NewImagesList(cfgPath string, cfg *kubeadmapiv1beta2.ClusterConfiguration) (*ImagesList, error) {
|
||||||
// Avoid running the CRI auto-detection code as we don't need it
|
initcfg, err := configutil.LoadOrDefaultInitConfiguration(cfgPath, cmdutil.DefaultInitConfiguration(), cfg)
|
||||||
versionedInitCfg := &kubeadmapiv1beta2.InitConfiguration{
|
|
||||||
NodeRegistration: kubeadmapiv1beta2.NodeRegistrationOptions{
|
|
||||||
CRISocket: constants.DefaultDockerCRISocket,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
initcfg, err := configutil.LoadOrDefaultInitConfiguration(cfgPath, versionedInitCfg, cfg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not convert cfg to an internal cfg")
|
return nil, errors.Wrap(err, "could not convert cfg to an internal cfg")
|
||||||
}
|
}
|
||||||
|
@ -154,12 +154,12 @@ func getCertPhaseFlags(name string) []string {
|
|||||||
|
|
||||||
func getSANDescription(certSpec *certsphase.KubeadmCert) string {
|
func getSANDescription(certSpec *certsphase.KubeadmCert) string {
|
||||||
//Defaulted config we will use to get SAN certs
|
//Defaulted config we will use to get SAN certs
|
||||||
defaultConfig := &kubeadmapiv1beta2.InitConfiguration{
|
defaultConfig := cmdutil.DefaultInitConfiguration()
|
||||||
LocalAPIEndpoint: kubeadmapiv1beta2.APIEndpoint{
|
// GetAPIServerAltNames errors without an AdvertiseAddress; this is as good as any.
|
||||||
// GetAPIServerAltNames errors without an AdvertiseAddress; this is as good as any.
|
defaultConfig.LocalAPIEndpoint = kubeadmapiv1beta2.APIEndpoint{
|
||||||
AdvertiseAddress: "127.0.0.1",
|
AdvertiseAddress: "127.0.0.1",
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultInternalConfig := &kubeadmapi.InitConfiguration{}
|
defaultInternalConfig := &kubeadmapi.InitConfiguration{}
|
||||||
|
|
||||||
kubeadmscheme.Scheme.Default(defaultConfig)
|
kubeadmscheme.Scheme.Default(defaultConfig)
|
||||||
|
@ -92,7 +92,7 @@ func newCmdToken(out io.Writer, errW io.Writer) *cobra.Command {
|
|||||||
tokenCmd.PersistentFlags().BoolVar(&dryRun,
|
tokenCmd.PersistentFlags().BoolVar(&dryRun,
|
||||||
options.DryRun, dryRun, "Whether to enable dry-run mode or not")
|
options.DryRun, dryRun, "Whether to enable dry-run mode or not")
|
||||||
|
|
||||||
cfg := &kubeadmapiv1beta2.InitConfiguration{}
|
cfg := cmdutil.DefaultInitConfiguration()
|
||||||
|
|
||||||
// Default values for the cobra help text
|
// Default values for the cobra help text
|
||||||
kubeadmscheme.Scheme.Default(cfg)
|
kubeadmscheme.Scheme.Default(cfg)
|
||||||
@ -244,11 +244,6 @@ func RunCreateToken(out io.Writer, client clientset.Interface, cfgPath string, i
|
|||||||
// This call returns the ready-to-use configuration based on the configuration file that might or might not exist and the default cfg populated by flags
|
// This call returns the ready-to-use configuration based on the configuration file that might or might not exist and the default cfg populated by flags
|
||||||
klog.V(1).Infoln("[token] loading configurations")
|
klog.V(1).Infoln("[token] loading configurations")
|
||||||
|
|
||||||
// In fact, we don't do any CRI ops at all.
|
|
||||||
// This is just to force skipping the CRI detection.
|
|
||||||
// Ref: https://github.com/kubernetes/kubeadm/issues/1559
|
|
||||||
initCfg.NodeRegistration.CRISocket = kubeadmconstants.DefaultDockerCRISocket
|
|
||||||
|
|
||||||
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(cfgPath, initCfg, clusterCfg)
|
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(cfgPath, initCfg, clusterCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -10,6 +10,7 @@ go_library(
|
|||||||
importpath = "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util",
|
importpath = "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
|
"//cmd/kubeadm/app/apis/kubeadm/v1beta2:go_default_library",
|
||||||
"//cmd/kubeadm/app/cmd/options:go_default_library",
|
"//cmd/kubeadm/app/cmd/options:go_default_library",
|
||||||
"//cmd/kubeadm/app/constants:go_default_library",
|
"//cmd/kubeadm/app/constants:go_default_library",
|
||||||
"//cmd/kubeadm/app/util/kubeconfig:go_default_library",
|
"//cmd/kubeadm/app/util/kubeconfig:go_default_library",
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
|
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
kubeadmapiv1beta2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
||||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
)
|
)
|
||||||
@ -87,3 +88,14 @@ func AddCRISocketFlag(flagSet *pflag.FlagSet, criSocket *string) {
|
|||||||
"Path to the CRI socket to connect. If empty kubeadm will try to auto-detect this value; use this option only if you have more than one CRI installed or if you have non-standard CRI socket.",
|
"Path to the CRI socket to connect. If empty kubeadm will try to auto-detect this value; use this option only if you have more than one CRI installed or if you have non-standard CRI socket.",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultInitConfiguration return default InitConfiguration. Avoid running the CRI auto-detection
|
||||||
|
// code as we don't need it.
|
||||||
|
func DefaultInitConfiguration() *kubeadmapiv1beta2.InitConfiguration {
|
||||||
|
initCfg := &kubeadmapiv1beta2.InitConfiguration{
|
||||||
|
NodeRegistration: kubeadmapiv1beta2.NodeRegistrationOptions{
|
||||||
|
CRISocket: kubeadmconstants.UnknownCRISocket, // avoid CRI detection
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return initCfg
|
||||||
|
}
|
||||||
|
@ -236,6 +236,9 @@ const (
|
|||||||
// init/join time for use later. kubeadm annotates the node object with this information
|
// init/join time for use later. kubeadm annotates the node object with this information
|
||||||
AnnotationKubeadmCRISocket = "kubeadm.alpha.kubernetes.io/cri-socket"
|
AnnotationKubeadmCRISocket = "kubeadm.alpha.kubernetes.io/cri-socket"
|
||||||
|
|
||||||
|
// UnknownCRISocket defines the undetected or unknown CRI socket
|
||||||
|
UnknownCRISocket = "/var/run/unknown.sock"
|
||||||
|
|
||||||
// KubeadmConfigConfigMap specifies in what ConfigMap in the kube-system namespace the `kubeadm init` configuration should be stored
|
// KubeadmConfigConfigMap specifies in what ConfigMap in the kube-system namespace the `kubeadm init` configuration should be stored
|
||||||
KubeadmConfigConfigMap = "kubeadm-config"
|
KubeadmConfigConfigMap = "kubeadm-config"
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ func getInitConfigurationFromCluster(kubeconfigDir string, client clientset.Inte
|
|||||||
// However, if newControlPlane == true, initcfg.NodeRegistration is not used at all and it's overwritten later on.
|
// However, if newControlPlane == true, initcfg.NodeRegistration is not used at all and it's overwritten later on.
|
||||||
// Thus it's necessary to supply some default value, that will avoid the call to DetectCRISocket() and as
|
// Thus it's necessary to supply some default value, that will avoid the call to DetectCRISocket() and as
|
||||||
// initcfg.NodeRegistration is discarded, setting whatever value here is harmless.
|
// initcfg.NodeRegistration is discarded, setting whatever value here is harmless.
|
||||||
initcfg.NodeRegistration.CRISocket = "/var/run/unknown.sock"
|
initcfg.NodeRegistration.CRISocket = constants.UnknownCRISocket
|
||||||
}
|
}
|
||||||
return initcfg, nil
|
return initcfg, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user