Merge pull request #119313 from chendave/migrate_config

kubeadm: Support `kubeadm config migrate` for ResetConfiguration
This commit is contained in:
Kubernetes Prow Robot 2023-07-15 00:31:22 -07:00 committed by GitHub
commit 871e6b5b8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 0 deletions

View File

@ -289,6 +289,19 @@ func MigrateOldConfig(oldConfig []byte, allowExperimental bool) ([]byte, error)
newConfig = append(newConfig, b)
}
// Migrate ResetConfiguration if there is any
if kubeadmutil.GroupVersionKindsHasResetConfiguration(gvks...) {
o, err := documentMapToResetConfiguration(gvkmap, true, allowExperimental)
if err != nil {
return []byte{}, err
}
b, err := MarshalKubeadmConfigObject(o, gv)
if err != nil {
return []byte{}, err
}
newConfig = append(newConfig, b)
}
return bytes.Join(newConfig, []byte(constants.YAMLDocumentSeparator)), nil
}

View File

@ -425,6 +425,31 @@ func TestMigrateOldConfig(t *testing.T) {
allowExperimental: false,
expectErr: true,
},
{
name: "ResetConfiguration gets migrated from experimental API",
oldCfg: dedent.Dedent(fmt.Sprintf(`
apiVersion: %s
kind: ResetConfiguration
force: true
cleanupTmpDir: true
criSocket: unix:///var/run/containerd/containerd.sock
certificatesDir: /etc/kubernetes/pki
`, gvExperimental)),
expectedKinds: []string{
constants.ResetConfigurationKind,
},
allowExperimental: true,
expectErr: false,
},
{
name: "ResetConfiguration from experimental API cannot be migrated",
oldCfg: dedent.Dedent(fmt.Sprintf(`
apiVersion: %s
kind: ResetConfiguration
`, gvExperimental)),
allowExperimental: false,
expectErr: true,
},
}
for _, test := range tests {

View File

@ -158,3 +158,8 @@ func GroupVersionKindsHasInitConfiguration(gvks ...schema.GroupVersionKind) bool
func GroupVersionKindsHasJoinConfiguration(gvks ...schema.GroupVersionKind) bool {
return GroupVersionKindsHasKind(gvks, constants.JoinConfigurationKind)
}
// GroupVersionKindsHasResetConfiguration returns whether the following gvk slice contains a ResetConfiguration object
func GroupVersionKindsHasResetConfiguration(gvks ...schema.GroupVersionKind) bool {
return GroupVersionKindsHasKind(gvks, constants.ResetConfigurationKind)
}

View File

@ -402,3 +402,38 @@ func TestGroupVersionKindsHasJoinConfiguration(t *testing.T) {
})
}
}
func TestGroupVersionKindsHasResetConfiguration(t *testing.T) {
var tests = []struct {
name string
gvks []schema.GroupVersionKind
kind string
expected bool
}{
{
name: "NoResetConfiguration",
gvks: []schema.GroupVersionKind{
{Group: "foo.k8s.io", Version: "v1", Kind: "Foo"},
},
expected: false,
},
{
name: "ResetConfigurationFound",
gvks: []schema.GroupVersionKind{
{Group: "foo.k8s.io", Version: "v1", Kind: "Foo"},
{Group: "bar.k8s.io", Version: "v2", Kind: "ResetConfiguration"},
},
expected: true,
},
}
for _, rt := range tests {
t.Run(rt.name, func(t2 *testing.T) {
actual := GroupVersionKindsHasResetConfiguration(rt.gvks...)
if rt.expected != actual {
t2.Errorf("expected gvks has ResetConfiguration: %t\n\tactual: %t\n", rt.expected, actual)
}
})
}
}