kubeadm: don't fail post upgrade in EnsureAdminClusterRoleBindingImpl if the error is crb already exists

This commit is contained in:
Paco Xu 2024-01-22 14:32:13 +08:00
parent 3aa8c59fec
commit ec1516b45d
2 changed files with 9 additions and 4 deletions

View File

@ -694,9 +694,8 @@ func EnsureAdminClusterRoleBindingImpl(ctx context.Context, adminClient, superAd
); err != nil {
lastError = err
if apierrors.IsAlreadyExists(err) {
// This should not happen, as the previous "create" call that uses
// the admin.conf should have passed. Return the error.
return true, err
klog.V(5).Infof("ClusterRoleBinding %s already exists.", kubeadmconstants.ClusterAdminsGroupAndClusterRoleBinding)
return true, nil
}
// Retry on any other type of error.
return false, nil

View File

@ -850,6 +850,12 @@ func TestEnsureAdminClusterRoleBindingImpl(t *testing.T) {
schema.GroupResource{}, "name")
})
},
setupSuperAdminClient: func(client *clientsetfake.Clientset) {
client.PrependReactor("create", "clusterrolebindings", func(action clientgotesting.Action) (bool, runtime.Object, error) {
return true, nil, apierrors.NewAlreadyExists(
schema.GroupResource{}, "name")
})
},
expectedError: false,
},
{
@ -916,7 +922,7 @@ func TestEnsureAdminClusterRoleBindingImpl(t *testing.T) {
schema.GroupResource{}, "name")
})
},
expectedError: true,
expectedError: false,
},
}