Skip to content

Commit 5d01274

Browse files
committed
kubeadm upgrade plan: don't load component configs
Component configs are used by kubeadm upgrade plan at the moment. However, they can prevent kubeadm upgrade plan from functioning if loading of an unsupported version of a component config is attempted. For that matter it's best to just stop loading component configs as part of the kubeadm config load process. Signed-off-by: Rostislav M. Georgiev <[email protected]>
1 parent e7427c6 commit 5d01274

File tree

8 files changed

+15
-13
lines changed

8 files changed

+15
-13
lines changed

cmd/kubeadm/app/cmd/alpha/certs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func getInternalCfg(cfgPath string, kubeconfigPath string, cfg kubeadmapiv1beta2
254254
if cfgPath == "" {
255255
client, err := kubeconfigutil.ClientSetFromFile(kubeconfigPath)
256256
if err == nil {
257-
internalcfg, err := configutil.FetchInitConfigurationFromCluster(client, out, logPrefix, false)
257+
internalcfg, err := configutil.FetchInitConfigurationFromCluster(client, out, logPrefix, false, false)
258258
if err == nil {
259259
fmt.Println() // add empty line to separate the FetchInitConfigurationFromCluster output from the command output
260260
return internalcfg, nil

cmd/kubeadm/app/cmd/join.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ func fetchInitConfiguration(tlsBootstrapCfg *clientcmdapi.Config) (*kubeadmapi.I
545545
}
546546

547547
// Fetches the init configuration
548-
initConfiguration, err := configutil.FetchInitConfigurationFromCluster(tlsClient, os.Stdout, "preflight", true)
548+
initConfiguration, err := configutil.FetchInitConfigurationFromCluster(tlsClient, os.Stdout, "preflight", true, false)
549549
if err != nil {
550550
return nil, errors.Wrap(err, "unable to fetch the kubeadm-config ConfigMap")
551551
}

cmd/kubeadm/app/cmd/reset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func newResetData(cmd *cobra.Command, options *resetOptions, in io.Reader, out i
9494
client, err := getClientset(options.kubeconfigPath, false)
9595
if err == nil {
9696
klog.V(1).Infof("[reset] Loaded client set from kubeconfig file: %s", options.kubeconfigPath)
97-
cfg, err = configutil.FetchInitConfigurationFromCluster(client, out, "reset", false)
97+
cfg, err = configutil.FetchInitConfigurationFromCluster(client, out, "reset", false, false)
9898
if err != nil {
9999
klog.Warningf("[reset] Unable to fetch the kubeadm-config ConfigMap from cluster: %v", err)
100100
}

cmd/kubeadm/app/cmd/upgrade/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func enforceRequirements(flags *applyPlanFlags, args []string, dryRun bool, upgr
7474
newK8sVersion = cfg.KubernetesVersion
7575
}
7676
} else {
77-
cfg, err = configutil.FetchInitConfigurationFromCluster(client, os.Stdout, "upgrade/config", false)
77+
cfg, err = configutil.FetchInitConfigurationFromCluster(client, os.Stdout, "upgrade/config", false, !upgradeApply)
7878
}
7979

8080
if err != nil {

cmd/kubeadm/app/cmd/upgrade/diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func runDiff(flags *diffFlags, args []string) error {
9191
if err != nil {
9292
return errors.Wrapf(err, "couldn't create a Kubernetes client from file %q", flags.kubeConfigPath)
9393
}
94-
cfg, err = configutil.FetchInitConfigurationFromCluster(client, flags.out, "upgrade/diff", false)
94+
cfg, err = configutil.FetchInitConfigurationFromCluster(client, flags.out, "upgrade/diff", false, false)
9595
}
9696
if err != nil {
9797
return err

cmd/kubeadm/app/cmd/upgrade/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func newNodeData(cmd *cobra.Command, args []string, options *nodeOptions) (*node
141141
// Fetches the cluster configuration
142142
// NB in case of control-plane node, we are reading all the info for the node; in case of NOT control-plane node
143143
// (worker node), we are not reading local API address and the CRI socket from the node object
144-
cfg, err := configutil.FetchInitConfigurationFromCluster(client, os.Stdout, "upgrade", !isControlPlaneNode)
144+
cfg, err := configutil.FetchInitConfigurationFromCluster(client, os.Stdout, "upgrade", !isControlPlaneNode, false)
145145
if err != nil {
146146
return nil, errors.Wrap(err, "unable to fetch the kubeadm-config ConfigMap")
147147
}

cmd/kubeadm/app/util/config/cluster.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ func (ue *unretriableError) Error() string {
6161
}
6262

6363
// FetchInitConfigurationFromCluster fetches configuration from a ConfigMap in the cluster
64-
func FetchInitConfigurationFromCluster(client clientset.Interface, w io.Writer, logPrefix string, newControlPlane bool) (*kubeadmapi.InitConfiguration, error) {
64+
func FetchInitConfigurationFromCluster(client clientset.Interface, w io.Writer, logPrefix string, newControlPlane, skipComponentConfigs bool) (*kubeadmapi.InitConfiguration, error) {
6565
fmt.Fprintf(w, "[%s] Reading configuration from the cluster...\n", logPrefix)
6666
fmt.Fprintf(w, "[%s] FYI: You can look at this config file with 'kubectl -n %s get cm %s -oyaml'\n", logPrefix, metav1.NamespaceSystem, constants.KubeadmConfigConfigMap)
6767

6868
// Fetch the actual config from cluster
69-
cfg, err := getInitConfigurationFromCluster(constants.KubernetesDir, client, newControlPlane)
69+
cfg, err := getInitConfigurationFromCluster(constants.KubernetesDir, client, newControlPlane, skipComponentConfigs)
7070
if err != nil {
7171
return nil, err
7272
}
@@ -80,7 +80,7 @@ func FetchInitConfigurationFromCluster(client clientset.Interface, w io.Writer,
8080
}
8181

8282
// getInitConfigurationFromCluster is separate only for testing purposes, don't call it directly, use FetchInitConfigurationFromCluster instead
83-
func getInitConfigurationFromCluster(kubeconfigDir string, client clientset.Interface, newControlPlane bool) (*kubeadmapi.InitConfiguration, error) {
83+
func getInitConfigurationFromCluster(kubeconfigDir string, client clientset.Interface, newControlPlane, skipComponentConfigs bool) (*kubeadmapi.InitConfiguration, error) {
8484
// Also, the config map really should be KubeadmConfigConfigMap...
8585
configMap, err := apiclient.GetConfigMapWithRetry(client, metav1.NamespaceSystem, constants.KubeadmConfigConfigMap)
8686
if err != nil {
@@ -99,9 +99,11 @@ func getInitConfigurationFromCluster(kubeconfigDir string, client clientset.Inte
9999
return nil, errors.Wrap(err, "failed to decode cluster configuration data")
100100
}
101101

102-
// gets the component configs from the corresponding config maps
103-
if err := componentconfigs.FetchFromCluster(&initcfg.ClusterConfiguration, client); err != nil {
104-
return nil, errors.Wrap(err, "failed to get component configs")
102+
if !skipComponentConfigs {
103+
// get the component configs from the corresponding config maps
104+
if err := componentconfigs.FetchFromCluster(&initcfg.ClusterConfiguration, client); err != nil {
105+
return nil, errors.Wrap(err, "failed to get component configs")
106+
}
105107
}
106108

107109
// if this isn't a new controlplane instance (e.g. in case of kubeadm upgrades)

cmd/kubeadm/app/util/config/cluster_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ func TestGetInitConfigurationFromCluster(t *testing.T) {
736736
}
737737
}
738738

739-
cfg, err := getInitConfigurationFromCluster(tmpdir, client, rt.newControlPlane)
739+
cfg, err := getInitConfigurationFromCluster(tmpdir, client, rt.newControlPlane, false)
740740
if rt.expectedError != (err != nil) {
741741
t.Errorf("unexpected return err from getInitConfigurationFromCluster: %v", err)
742742
return

0 commit comments

Comments
 (0)