Test more filters in SupervisorSecretsController (see 6e8d564013)

Signed-off-by: Andrew Keesler <akeesler@vmware.com>
This commit is contained in:
Andrew Keesler 2020-12-15 07:58:33 -05:00
parent 9a3e60d4df
commit 60d4a7beac
No known key found for this signature in database
GPG Key ID: 27CE0444346F9413
3 changed files with 31 additions and 6 deletions

View File

@ -157,6 +157,7 @@ func startControllers(
secretCache.SetCSRFCookieEncoderHashKey(secret) secretCache.SetCSRFCookieEncoderHashKey(secret)
}, },
controllerlib.WithInformer, controllerlib.WithInformer,
controllerlib.WithInitialEvent,
), ),
singletonWorker, singletonWorker,
). ).

View File

@ -43,6 +43,7 @@ func NewSupervisorSecretsController(
secretInformer corev1informers.SecretInformer, secretInformer corev1informers.SecretInformer,
setCacheFunc func(secret []byte), setCacheFunc func(secret []byte),
withInformer pinnipedcontroller.WithInformerOptionFunc, withInformer pinnipedcontroller.WithInformerOptionFunc,
initialEventFunc pinnipedcontroller.WithInitialEventOptionFunc,
) controllerlib.Controller { ) controllerlib.Controller {
c := supervisorSecretsController{ c := supervisorSecretsController{
owner: owner, owner: owner,
@ -60,7 +61,7 @@ func NewSupervisorSecretsController(
}, nil), }, nil),
controllerlib.InformerOption{}, controllerlib.InformerOption{},
), ),
controllerlib.WithInitialEvent(controllerlib.Key{ initialEventFunc(controllerlib.Key{
Namespace: owner.Namespace, Namespace: owner.Namespace,
Name: owner.Name + "-key", Name: owner.Name + "-key",
}), }),

View File

@ -21,7 +21,6 @@ import (
kubernetesfake "k8s.io/client-go/kubernetes/fake" kubernetesfake "k8s.io/client-go/kubernetes/fake"
kubetesting "k8s.io/client-go/testing" kubetesting "k8s.io/client-go/testing"
configv1alpha1 "go.pinniped.dev/generated/1.19/apis/supervisor/config/v1alpha1"
"go.pinniped.dev/internal/controllerlib" "go.pinniped.dev/internal/controllerlib"
"go.pinniped.dev/internal/testutil" "go.pinniped.dev/internal/testutil"
) )
@ -30,6 +29,7 @@ var (
owner = &appsv1.Deployment{ owner = &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "some-owner-name", Name: "some-owner-name",
Namespace: "some-namespace",
UID: "some-owner-uid", UID: "some-owner-uid",
}, },
} }
@ -69,7 +69,7 @@ func TestSupervisorSecretsControllerFilterSecret(t *testing.T) {
Namespace: "some-namespace", Namespace: "some-namespace",
OwnerReferences: []metav1.OwnerReference{ OwnerReferences: []metav1.OwnerReference{
{ {
APIVersion: configv1alpha1.SchemeGroupVersion.String(), APIVersion: ownerGVK.String(),
Name: "some-name", Name: "some-name",
Kind: ownerGVK.Kind, Kind: ownerGVK.Kind,
UID: owner.GetUID(), UID: owner.GetUID(),
@ -103,7 +103,7 @@ func TestSupervisorSecretsControllerFilterSecret(t *testing.T) {
Namespace: "some-namespace", Namespace: "some-namespace",
OwnerReferences: []metav1.OwnerReference{ OwnerReferences: []metav1.OwnerReference{
{ {
APIVersion: configv1alpha1.SchemeGroupVersion.String(), APIVersion: ownerGVK.String(),
Name: "some-name", Name: "some-name",
Kind: "IncorrectKind", Kind: "IncorrectKind",
Controller: boolPtr(true), Controller: boolPtr(true),
@ -165,6 +165,7 @@ func TestSupervisorSecretsControllerFilterSecret(t *testing.T) {
secretInformer, secretInformer,
nil, // setCache, not needed nil, // setCache, not needed
withInformer.WithInformer, withInformer.WithInformer,
testutil.NewObservableWithInitialEventOption().WithInitialEvent,
) )
unrelated := corev1.Secret{} unrelated := corev1.Secret{}
@ -177,6 +178,27 @@ func TestSupervisorSecretsControllerFilterSecret(t *testing.T) {
} }
} }
func TestSupervisorSecretsControllerInitialEvent(t *testing.T) {
initialEventOption := testutil.NewObservableWithInitialEventOption()
secretInformer := kubeinformers.NewSharedInformerFactory(
kubernetesfake.NewSimpleClientset(),
0,
).Core().V1().Secrets()
_ = NewSupervisorSecretsController(
owner,
nil,
nil, // kubeClient, not needed
secretInformer,
nil, // setCache, not needed
testutil.NewObservableWithInformerOption().WithInformer,
initialEventOption.WithInitialEvent,
)
require.Equal(t, &controllerlib.Key{
owner.Namespace,
owner.Name + "-key",
}, initialEventOption.GetInitialEventKey())
}
func TestSupervisorSecretsControllerSync(t *testing.T) { func TestSupervisorSecretsControllerSync(t *testing.T) {
const ( const (
generatedSecretNamespace = "some-namespace" generatedSecretNamespace = "some-namespace"
@ -459,6 +481,7 @@ func TestSupervisorSecretsControllerSync(t *testing.T) {
callbackSecret = secret callbackSecret = secret
}, },
testutil.NewObservableWithInformerOption().WithInformer, testutil.NewObservableWithInformerOption().WithInformer,
testutil.NewObservableWithInitialEventOption().WithInitialEvent,
) )
// Must start informers before calling TestRunSynchronously(). // Must start informers before calling TestRunSynchronously().