Skip to content

Commit 0786fcc

Browse files
committed
kubeadm: Remove the support of configurable component configs
`kubeadm upgrade plan` uses to support the configure of component configs(kubeproxy and kubelet) in a config file and then check if the version is supported or not, if it's not supported it will be marked as a unsupported version and require to manually upgrade the component. This feature will make the upgrade config API much harder as this violates the no-mutation principle for upgrade, and we have seen it's quite problematic to do like this. This change removes the support of configurable component configs for `kubeadm upgrade plan`, along with the removal, the logic to parse the config file to decide whether a manual upgrade for the component configs is needed is removed as well. NOTE that API is not changed, i.e. `ManualUpgradeRequired` is not removed from `ComponentConfigVersionState` but it's no-op now. Signed-off-by: Dave Chen <[email protected]>
1 parent 160fe01 commit 0786fcc

File tree

3 files changed

+28
-118
lines changed

3 files changed

+28
-118
lines changed

cmd/kubeadm/app/cmd/upgrade/plan.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,13 @@ import (
3232
"k8s.io/apimachinery/pkg/util/version"
3333
"k8s.io/cli-runtime/pkg/genericclioptions"
3434
"k8s.io/cli-runtime/pkg/printers"
35-
clientset "k8s.io/client-go/kubernetes"
3635
"k8s.io/klog/v2"
3736

38-
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
3937
outputapischeme "k8s.io/kubernetes/cmd/kubeadm/app/apis/output/scheme"
4038
outputapiv1alpha2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/output/v1alpha2"
4139
"k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs"
4240
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
4341
"k8s.io/kubernetes/cmd/kubeadm/app/phases/upgrade"
44-
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
4542
"k8s.io/kubernetes/cmd/kubeadm/app/util/output"
4643
)
4744

@@ -268,7 +265,7 @@ func runPlan(flags *planFlags, args []string, printer output.Printer) error {
268265

269266
// Fetch the current state of the component configs
270267
klog.V(1).Infoln("[upgrade/plan] analysing component config version states")
271-
configVersionStates, err := getComponentConfigVersionStates(&cfg.ClusterConfiguration, client, flags.cfgPath)
268+
configVersionStates, err := componentconfigs.GetVersionStates(&cfg.ClusterConfiguration, client)
272269
if err != nil {
273270
return errors.WithMessage(err, "[upgrade/versions] FATAL")
274271
}
@@ -352,24 +349,6 @@ func genUpgradePlan(up *upgrade.Upgrade, isExternalEtcd bool) (*outputapiv1alpha
352349
return &outputapiv1alpha2.UpgradePlan{Components: components}, unstableVersionFlag, nil
353350
}
354351

355-
func getComponentConfigVersionStates(cfg *kubeadmapi.ClusterConfiguration, client clientset.Interface, cfgPath string) ([]outputapiv1alpha2.ComponentConfigVersionState, error) {
356-
docmap := kubeadmapi.DocumentMap{}
357-
358-
if cfgPath != "" {
359-
bytes, err := os.ReadFile(cfgPath)
360-
if err != nil {
361-
return nil, errors.Wrapf(err, "unable to read config file %q", cfgPath)
362-
}
363-
364-
docmap, err = kubeadmutil.SplitYAMLDocuments(bytes)
365-
if err != nil {
366-
return nil, err
367-
}
368-
}
369-
370-
return componentconfigs.GetVersionStates(cfg, client, docmap)
371-
}
372-
373352
// printUpgradePlan prints a UX-friendly overview of what versions are available to upgrade to
374353
func printUpgradePlan(up *upgrade.Upgrade, plan *outputapiv1alpha2.UpgradePlan, unstableVersionFlag string, isExternalEtcd bool, writer io.Writer, printer output.Printer) {
375354
printHeader := true

cmd/kubeadm/app/componentconfigs/configset.go

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -289,38 +289,22 @@ func FetchFromClusterWithLocalOverwrites(clusterCfg *kubeadmapi.ClusterConfigura
289289

290290
// GetVersionStates returns a slice of ComponentConfigVersionState structs
291291
// describing all supported component config groups that were identified on the cluster
292-
func GetVersionStates(clusterCfg *kubeadmapi.ClusterConfiguration, client clientset.Interface, docmap kubeadmapi.DocumentMap) ([]outputapiv1alpha2.ComponentConfigVersionState, error) {
292+
func GetVersionStates(clusterCfg *kubeadmapi.ClusterConfiguration, client clientset.Interface) ([]outputapiv1alpha2.ComponentConfigVersionState, error) {
293293
// We don't want to modify clusterCfg so we make a working deep copy of it.
294294
// Also, we don't want the defaulted component configs so we get rid of them.
295295
scratchClusterCfg := clusterCfg.DeepCopy()
296296
scratchClusterCfg.ComponentConfigs = kubeadmapi.ComponentConfigMap{}
297297

298-
// Call FetchFromClusterWithLocalOverwrites. This will populate the configs it can load and will return all
299-
// UnsupportedConfigVersionError(s) in a sinle instance of a MultipleUnsupportedConfigVersionsError.
300-
var multipleVerErrs UnsupportedConfigVersionsErrorMap
301-
err := FetchFromClusterWithLocalOverwrites(scratchClusterCfg, client, docmap)
298+
err := FetchFromCluster(scratchClusterCfg, client)
302299
if err != nil {
303-
if vererrs, ok := err.(UnsupportedConfigVersionsErrorMap); ok {
304-
multipleVerErrs = vererrs
305-
} else {
306-
// This seems to be a genuine error so we end here
307-
return nil, err
308-
}
300+
// This seems to be a genuine error so we end here
301+
return nil, err
309302
}
310303

311304
results := []outputapiv1alpha2.ComponentConfigVersionState{}
312305
for _, handler := range known {
313306
group := handler.GroupVersion.Group
314-
if vererr, ok := multipleVerErrs[group]; ok {
315-
// If there is an UnsupportedConfigVersionError then we are dealing with a case where the config was user
316-
// supplied and requires manual upgrade
317-
results = append(results, outputapiv1alpha2.ComponentConfigVersionState{
318-
Group: group,
319-
CurrentVersion: vererr.OldVersion.Version,
320-
PreferredVersion: vererr.CurrentVersion.Version,
321-
ManualUpgradeRequired: true,
322-
})
323-
} else if _, ok := scratchClusterCfg.ComponentConfigs[group]; ok {
307+
if _, ok := scratchClusterCfg.ComponentConfigs[group]; ok {
324308
// Normally loaded component config. No manual upgrade required on behalf of users.
325309
results = append(results, outputapiv1alpha2.ComponentConfigVersionState{
326310
Group: group,

cmd/kubeadm/app/componentconfigs/fakeconfig_test.go

Lines changed: 22 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -617,111 +617,58 @@ func TestGetVersionStates(t *testing.T) {
617617
CurrentVersion: currentClusterConfigVersion,
618618
PreferredVersion: currentClusterConfigVersion,
619619
}
620-
versionStateOld := outputapiv1alpha2.ComponentConfigVersionState{
621-
Group: kubeadmapiv1.GroupName,
622-
CurrentVersion: oldClusterConfigVersion,
623-
PreferredVersion: currentClusterConfigVersion,
624-
ManualUpgradeRequired: true,
625-
}
626620

627621
cases := []struct {
628-
desc string
629-
obj runtime.Object
630-
config string
631-
expected outputapiv1alpha2.ComponentConfigVersionState
622+
desc string
623+
obj runtime.Object
624+
expectedErr bool
625+
expected outputapiv1alpha2.ComponentConfigVersionState
632626
}{
633627
{
634-
desc: "appropriate cluster object without overwrite",
635-
obj: testClusterConfigMap(currentFooClusterConfig, false),
636-
expected: versionStateCurrent,
637-
},
638-
{
639-
desc: "appropriate cluster object with appropriate overwrite",
628+
desc: "appropriate cluster object",
640629
obj: testClusterConfigMap(currentFooClusterConfig, false),
641-
config: dedent.Dedent(currentBarClusterConfig),
642630
expected: versionStateCurrent,
643631
},
644632
{
645-
desc: "appropriate cluster object with old overwrite",
646-
obj: testClusterConfigMap(currentFooClusterConfig, false),
647-
config: dedent.Dedent(oldBarClusterConfig),
648-
expected: versionStateOld,
649-
},
650-
{
651-
desc: "old config without overwrite returns an error",
652-
obj: testClusterConfigMap(oldFooClusterConfig, false),
653-
expected: versionStateOld,
654-
},
655-
{
656-
desc: "old config with appropriate overwrite",
657-
obj: testClusterConfigMap(oldFooClusterConfig, false),
658-
config: dedent.Dedent(currentBarClusterConfig),
659-
expected: versionStateCurrent,
660-
},
661-
{
662-
desc: "old config with old overwrite",
663-
obj: testClusterConfigMap(oldFooClusterConfig, false),
664-
config: dedent.Dedent(oldBarClusterConfig),
665-
expected: versionStateOld,
666-
},
667-
{
668-
desc: "appropriate signed cluster object without overwrite",
669-
obj: testClusterConfigMap(currentFooClusterConfig, true),
670-
expected: versionStateCurrent,
633+
desc: "old config returns an error",
634+
obj: testClusterConfigMap(oldFooClusterConfig, false),
635+
expectedErr: true,
671636
},
672637
{
673-
desc: "appropriate signed cluster object with appropriate overwrite",
638+
desc: "appropriate signed cluster object",
674639
obj: testClusterConfigMap(currentFooClusterConfig, true),
675-
config: dedent.Dedent(currentBarClusterConfig),
676640
expected: versionStateCurrent,
677641
},
678642
{
679-
desc: "appropriate signed cluster object with old overwrit",
680-
obj: testClusterConfigMap(currentFooClusterConfig, true),
681-
config: dedent.Dedent(oldBarClusterConfig),
682-
expected: versionStateOld,
683-
},
684-
{
685-
desc: "old signed config without an overwrite",
643+
desc: "old signed config",
686644
obj: testClusterConfigMap(oldFooClusterConfig, true),
687645
expected: outputapiv1alpha2.ComponentConfigVersionState{
688646
Group: kubeadmapiv1.GroupName,
689647
CurrentVersion: "", // The config is treated as if it's missing
690648
PreferredVersion: currentClusterConfigVersion,
691649
},
692650
},
693-
{
694-
desc: "old signed config with appropriate overwrite",
695-
obj: testClusterConfigMap(oldFooClusterConfig, true),
696-
config: dedent.Dedent(currentBarClusterConfig),
697-
expected: versionStateCurrent,
698-
},
699-
{
700-
desc: "old signed config with old overwrite",
701-
obj: testClusterConfigMap(oldFooClusterConfig, true),
702-
config: dedent.Dedent(oldBarClusterConfig),
703-
expected: versionStateOld,
704-
},
705651
}
706652

707653
for _, test := range cases {
708654
t.Run(test.desc, func(t *testing.T) {
709655
client := clientsetfake.NewSimpleClientset(test.obj)
710656

711-
docmap, err := kubeadmutil.SplitYAMLDocuments([]byte(test.config))
712-
if err != nil {
713-
t.Fatalf("unexpected failure of SplitYAMLDocuments: %v", err)
714-
}
715-
716657
clusterCfg := testClusterCfg()
717658

718-
got, err := GetVersionStates(clusterCfg, client, docmap)
719-
if err != nil {
659+
got, err := GetVersionStates(clusterCfg, client)
660+
if err != nil && !test.expectedErr {
720661
t.Errorf("unexpected error: %v", err)
721-
} else if len(got) != 1 {
722-
t.Errorf("got %d, but expected only a single result: %v", len(got), got)
723-
} else if got[0] != test.expected {
724-
t.Errorf("unexpected result:\n\texpected: %v\n\tgot: %v", test.expected, got[0])
662+
}
663+
if err == nil {
664+
if test.expectedErr {
665+
t.Errorf("expected error not found: %v", test.expectedErr)
666+
}
667+
if len(got) != 1 {
668+
t.Errorf("got %d, but expected only a single result: %v", len(got), got)
669+
} else if got[0] != test.expected {
670+
t.Errorf("unexpected result:\n\texpected: %v\n\tgot: %v", test.expected, got[0])
671+
}
725672
}
726673
})
727674
}

0 commit comments

Comments
 (0)