Skip to content

Commit 64f76b6

Browse files
authored
Merge pull request kubernetes#124186 from HirazawaUi/remove-unused-func
[kubeadm]: remove kubeadm unused function
2 parents 80542ca + 4a4a04f commit 64f76b6

File tree

2 files changed

+0
-179
lines changed

2 files changed

+0
-179
lines changed

cmd/kubeadm/app/componentconfigs/configset.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -244,49 +244,6 @@ func FetchFromDocumentMap(clusterCfg *kubeadmapi.ClusterConfiguration, docmap ku
244244
return nil
245245
}
246246

247-
// FetchFromClusterWithLocalOverwrites fetches component configs from a cluster and overwrites them locally with
248-
// the ones present in the supplied document map. If any UnsupportedConfigVersionError are not handled by the configs
249-
// in the document map, the function returns them all as a single UnsupportedConfigVersionsErrorMap.
250-
// This function is normally called only in some specific cases during upgrade.
251-
func FetchFromClusterWithLocalOverwrites(clusterCfg *kubeadmapi.ClusterConfiguration, client clientset.Interface, docmap kubeadmapi.DocumentMap) error {
252-
ensureInitializedComponentConfigs(clusterCfg)
253-
254-
oldVersionErrs := UnsupportedConfigVersionsErrorMap{}
255-
256-
for _, handler := range known {
257-
componentCfg, err := handler.FromCluster(client, clusterCfg)
258-
if err != nil {
259-
if vererr, ok := err.(*UnsupportedConfigVersionError); ok {
260-
oldVersionErrs[handler.GroupVersion.Group] = vererr
261-
} else {
262-
return err
263-
}
264-
} else if componentCfg != nil {
265-
clusterCfg.ComponentConfigs[handler.GroupVersion.Group] = componentCfg
266-
}
267-
}
268-
269-
for _, handler := range known {
270-
componentCfg, err := handler.FromDocumentMap(docmap)
271-
if err != nil {
272-
if vererr, ok := err.(*UnsupportedConfigVersionError); ok {
273-
oldVersionErrs[handler.GroupVersion.Group] = vererr
274-
} else {
275-
return err
276-
}
277-
} else if componentCfg != nil {
278-
clusterCfg.ComponentConfigs[handler.GroupVersion.Group] = componentCfg
279-
delete(oldVersionErrs, handler.GroupVersion.Group)
280-
}
281-
}
282-
283-
if len(oldVersionErrs) != 0 {
284-
return oldVersionErrs
285-
}
286-
287-
return nil
288-
}
289-
290247
// GetVersionStates returns a slice of ComponentConfigVersionState structs
291248
// describing all supported component config groups that were identified on the cluster
292249
func GetVersionStates(clusterCfg *kubeadmapi.ClusterConfiguration, client clientset.Interface) ([]outputapiv1alpha3.ComponentConfigVersionState, error) {

cmd/kubeadm/app/componentconfigs/fakeconfig_test.go

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -186,22 +186,6 @@ var (
186186
clusterName: foo
187187
`, kubeadmapiv1.GroupName, oldClusterConfigVersion)
188188

189-
// currentBarClusterConfig is a minimal currently supported ClusterConfiguration
190-
// with a well known value of clusterName (in this case `bar`)
191-
currentBarClusterConfig = fmt.Sprintf(`
192-
apiVersion: %s
193-
kind: ClusterConfiguration
194-
clusterName: bar
195-
`, kubeadmapiv1.SchemeGroupVersion)
196-
197-
// oldBarClusterConfig is a minimal unsupported ClusterConfiguration
198-
// with a well known value of clusterName (in this case `bar`)
199-
oldBarClusterConfig = fmt.Sprintf(`
200-
apiVersion: %s/%s
201-
kind: ClusterConfiguration
202-
clusterName: bar
203-
`, kubeadmapiv1.GroupName, oldClusterConfigVersion)
204-
205189
// This is the "minimal" valid config that can be unmarshalled to and from YAML.
206190
// Due to same static defaulting it's not exactly small in size.
207191
validUnmarshallableClusterConfig = struct {
@@ -490,126 +474,6 @@ func TestLoadingFromCluster(t *testing.T) {
490474
})
491475
}
492476

493-
func TestFetchFromClusterWithLocalOverwrites(t *testing.T) {
494-
fakeKnownContext(func() {
495-
cases := []struct {
496-
desc string
497-
obj runtime.Object
498-
config string
499-
expectedValue string
500-
isNotLoaded bool
501-
expectedErr bool
502-
}{
503-
{
504-
desc: "appropriate cluster object without overwrite is used",
505-
obj: testClusterConfigMap(currentFooClusterConfig, false),
506-
expectedValue: "foo",
507-
},
508-
{
509-
desc: "appropriate cluster object with appropriate overwrite is overwritten",
510-
obj: testClusterConfigMap(currentFooClusterConfig, false),
511-
config: dedent.Dedent(currentBarClusterConfig),
512-
expectedValue: "bar",
513-
},
514-
{
515-
desc: "appropriate cluster object with old overwrite returns an error",
516-
obj: testClusterConfigMap(currentFooClusterConfig, false),
517-
config: dedent.Dedent(oldBarClusterConfig),
518-
expectedErr: true,
519-
},
520-
{
521-
desc: "old config without overwrite returns an error",
522-
obj: testClusterConfigMap(oldFooClusterConfig, false),
523-
expectedErr: true,
524-
},
525-
{
526-
desc: "old config with appropriate overwrite returns the substitute",
527-
obj: testClusterConfigMap(oldFooClusterConfig, false),
528-
config: dedent.Dedent(currentBarClusterConfig),
529-
expectedValue: "bar",
530-
},
531-
{
532-
desc: "old config with old overwrite returns an error",
533-
obj: testClusterConfigMap(oldFooClusterConfig, false),
534-
config: dedent.Dedent(oldBarClusterConfig),
535-
expectedErr: true,
536-
},
537-
{
538-
desc: "appropriate signed cluster object without overwrite is used",
539-
obj: testClusterConfigMap(currentFooClusterConfig, true),
540-
expectedValue: "foo",
541-
},
542-
{
543-
desc: "appropriate signed cluster object with appropriate overwrite is overwritten",
544-
obj: testClusterConfigMap(currentFooClusterConfig, true),
545-
config: dedent.Dedent(currentBarClusterConfig),
546-
expectedValue: "bar",
547-
},
548-
{
549-
desc: "appropriate signed cluster object with old overwrite returns an error",
550-
obj: testClusterConfigMap(currentFooClusterConfig, true),
551-
config: dedent.Dedent(oldBarClusterConfig),
552-
expectedErr: true,
553-
},
554-
{
555-
desc: "old signed config without an overwrite is not loaded",
556-
obj: testClusterConfigMap(oldFooClusterConfig, true),
557-
isNotLoaded: true,
558-
},
559-
{
560-
desc: "old signed config with appropriate overwrite returns the substitute",
561-
obj: testClusterConfigMap(oldFooClusterConfig, true),
562-
config: dedent.Dedent(currentBarClusterConfig),
563-
expectedValue: "bar",
564-
},
565-
{
566-
desc: "old signed config with old overwrite returns an error",
567-
obj: testClusterConfigMap(oldFooClusterConfig, true),
568-
config: dedent.Dedent(oldBarClusterConfig),
569-
expectedErr: true,
570-
},
571-
}
572-
573-
for _, test := range cases {
574-
t.Run(test.desc, func(t *testing.T) {
575-
client := clientsetfake.NewSimpleClientset(test.obj)
576-
577-
docmap, err := kubeadmutil.SplitYAMLDocuments([]byte(test.config))
578-
if err != nil {
579-
t.Fatalf("unexpected failure of SplitYAMLDocuments: %v", err)
580-
}
581-
582-
clusterCfg := testClusterCfg()
583-
584-
err = FetchFromClusterWithLocalOverwrites(clusterCfg, client, docmap)
585-
if err != nil {
586-
if !test.expectedErr {
587-
t.Errorf("unexpected failure: %v", err)
588-
}
589-
} else {
590-
if test.expectedErr {
591-
t.Error("unexpected success")
592-
} else {
593-
clusterCfg, ok := clusterCfg.ComponentConfigs[kubeadmapiv1.GroupName]
594-
if !ok {
595-
if !test.isNotLoaded {
596-
t.Error("no config was loaded when it should have been")
597-
}
598-
} else {
599-
actualConfig, ok := clusterCfg.(*clusterConfig)
600-
if !ok {
601-
t.Error("the config is not of the expected type")
602-
} else if actualConfig.config.ClusterName != test.expectedValue {
603-
t.Errorf("unexpected value:\n\tgot: %q\n\texpected: %q", actualConfig.config.ClusterName, test.expectedValue)
604-
}
605-
}
606-
}
607-
}
608-
})
609-
}
610-
})
611-
}
612-
613477
func TestGetVersionStates(t *testing.T) {
614478
fakeKnownContext(func() {
615479
versionStateCurrent := outputapiv1alpha3.ComponentConfigVersionState{

0 commit comments

Comments
 (0)