fix serviceaccount controller remove unnecessary retries (#2188)
Signed-off-by: hongming <coder.scala@gmail.com> Co-authored-by: hongming <coder.scala@gmail.com>
This commit is contained in:
committed by
hongming
parent
8286d4888e
commit
42ef42ef12
@@ -13,17 +13,15 @@ import (
|
||||
. "github.com/onsi/gomega"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
rbacv1 "k8s.io/api/rbac/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/client-go/tools/record"
|
||||
iamv1beta1 "kubesphere.io/api/iam/v1beta1"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||
|
||||
iamv1beta1 "kubesphere.io/api/iam/v1beta1"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/utils/k8sutil"
|
||||
)
|
||||
|
||||
@@ -78,7 +76,6 @@ var _ = Describe("ServiceAccount", func() {
|
||||
ctx := context.Background()
|
||||
|
||||
reconciler := &Reconciler{
|
||||
//nolint:staticcheck
|
||||
Client: fake.NewClientBuilder().WithScheme(scheme.Scheme).Build(),
|
||||
logger: ctrl.Log.WithName("controllers").WithName("serviceaccount"),
|
||||
recorder: record.NewFakeRecorder(5),
|
||||
@@ -93,16 +90,15 @@ var _ = Describe("ServiceAccount", func() {
|
||||
By("Expecting to bind role successfully")
|
||||
rolebindings := &rbacv1.RoleBindingList{}
|
||||
Expect(func() bool {
|
||||
reconciler.List(ctx, rolebindings, client.InNamespace(sa.Namespace), client.MatchingLabels{iamv1beta1.ServiceAccountReferenceLabel: sa.Name})
|
||||
_ = reconciler.List(ctx, rolebindings, client.InNamespace(sa.Namespace), client.MatchingLabels{iamv1beta1.ServiceAccountReferenceLabel: sa.Name})
|
||||
return len(rolebindings.Items) == 1 && k8sutil.IsControlledBy(rolebindings.Items[0].OwnerReferences, "ServiceAccount", saName)
|
||||
}()).Should(BeTrue())
|
||||
})
|
||||
|
||||
It("Should report NotFound error when role doesn't exist", func() {
|
||||
It("Should not report NotFound error when role doesn't exist", func() {
|
||||
ctx := context.Background()
|
||||
|
||||
reconciler := &Reconciler{
|
||||
//nolint:staticcheck
|
||||
Client: fake.NewClientBuilder().WithScheme(scheme.Scheme).Build(),
|
||||
logger: ctrl.Log.WithName("controllers").WithName("serviceaccount"),
|
||||
recorder: record.NewFakeRecorder(5),
|
||||
@@ -110,7 +106,7 @@ var _ = Describe("ServiceAccount", func() {
|
||||
|
||||
Expect(reconciler.Create(ctx, sa)).Should(Succeed())
|
||||
_, err := reconciler.Reconcile(ctx, req)
|
||||
Expect(apierrors.IsNotFound(err)).To(BeTrue())
|
||||
Expect(err).Should(Succeed())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user