Upstream Watcher Controller Syncs less often by adjusting its filters
- Only watches Secrets of type "secrets.pinniped.dev/oidc-client" Signed-off-by: Ryan Richard <richardry@vmware.com>
This commit is contained in:
parent
cc5af1a810
commit
1b5e8c3439
@ -237,7 +237,9 @@ func startControllers(
|
|||||||
pinnipedClient,
|
pinnipedClient,
|
||||||
pinnipedInformers.IDP().V1alpha1().OIDCIdentityProviders(),
|
pinnipedInformers.IDP().V1alpha1().OIDCIdentityProviders(),
|
||||||
secretInformer,
|
secretInformer,
|
||||||
klogr.New()),
|
klogr.New(),
|
||||||
|
controllerlib.WithInformer,
|
||||||
|
),
|
||||||
singletonWorker)
|
singletonWorker)
|
||||||
|
|
||||||
kubeInformers.Start(ctx.Done())
|
kubeInformers.Start(ctx.Done())
|
||||||
|
@ -52,7 +52,7 @@ func NewJWKSObserverController(
|
|||||||
},
|
},
|
||||||
withInformer(
|
withInformer(
|
||||||
secretInformer,
|
secretInformer,
|
||||||
pinnipedcontroller.MatchAnySecretOfTypeFilter(jwksSecretTypeValue),
|
pinnipedcontroller.MatchAnySecretOfTypeFilter(jwksSecretTypeValue, nil),
|
||||||
controllerlib.InformerOption{},
|
controllerlib.InformerOption{},
|
||||||
),
|
),
|
||||||
withInformer(
|
withInformer(
|
||||||
|
@ -50,7 +50,7 @@ func NewTLSCertObserverController(
|
|||||||
},
|
},
|
||||||
withInformer(
|
withInformer(
|
||||||
secretInformer,
|
secretInformer,
|
||||||
pinnipedcontroller.MatchAnySecretOfTypeFilter(v1.SecretTypeTLS),
|
pinnipedcontroller.MatchAnySecretOfTypeFilter(v1.SecretTypeTLS, nil),
|
||||||
controllerlib.InformerOption{},
|
controllerlib.InformerOption{},
|
||||||
),
|
),
|
||||||
withInformer(
|
withInformer(
|
||||||
|
@ -117,6 +117,7 @@ func New(
|
|||||||
oidcIdentityProviderInformer idpinformers.OIDCIdentityProviderInformer,
|
oidcIdentityProviderInformer idpinformers.OIDCIdentityProviderInformer,
|
||||||
secretInformer corev1informers.SecretInformer,
|
secretInformer corev1informers.SecretInformer,
|
||||||
log logr.Logger,
|
log logr.Logger,
|
||||||
|
withInformer pinnipedcontroller.WithInformerOptionFunc,
|
||||||
) controllerlib.Controller {
|
) controllerlib.Controller {
|
||||||
c := controller{
|
c := controller{
|
||||||
cache: idpCache,
|
cache: idpCache,
|
||||||
@ -126,11 +127,18 @@ func New(
|
|||||||
secretInformer: secretInformer,
|
secretInformer: secretInformer,
|
||||||
validatorCache: &lruValidatorCache{cache: cache.NewExpiring()},
|
validatorCache: &lruValidatorCache{cache: cache.NewExpiring()},
|
||||||
}
|
}
|
||||||
filter := pinnipedcontroller.MatchAnythingFilter(pinnipedcontroller.SingletonQueue())
|
|
||||||
return controllerlib.New(
|
return controllerlib.New(
|
||||||
controllerlib.Config{Name: controllerName, Syncer: &c},
|
controllerlib.Config{Name: controllerName, Syncer: &c},
|
||||||
controllerlib.WithInformer(oidcIdentityProviderInformer, filter, controllerlib.InformerOption{}),
|
withInformer(
|
||||||
controllerlib.WithInformer(secretInformer, filter, controllerlib.InformerOption{}),
|
oidcIdentityProviderInformer,
|
||||||
|
pinnipedcontroller.MatchAnythingFilter(pinnipedcontroller.SingletonQueue()),
|
||||||
|
controllerlib.InformerOption{},
|
||||||
|
),
|
||||||
|
withInformer(
|
||||||
|
secretInformer,
|
||||||
|
pinnipedcontroller.MatchAnySecretOfTypeFilter(oidcClientSecretType, pinnipedcontroller.SingletonQueue()),
|
||||||
|
controllerlib.InformerOption{},
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,76 @@ import (
|
|||||||
"go.pinniped.dev/internal/upstreamoidc"
|
"go.pinniped.dev/internal/upstreamoidc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestControllerFilterSecret(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
secret metav1.Object
|
||||||
|
wantAdd bool
|
||||||
|
wantUpdate bool
|
||||||
|
wantDelete bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "a secret of the right type",
|
||||||
|
secret: &corev1.Secret{
|
||||||
|
Type: "secrets.pinniped.dev/oidc-client",
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "some-name", Namespace: "some-namespace"},
|
||||||
|
},
|
||||||
|
wantAdd: true,
|
||||||
|
wantUpdate: true,
|
||||||
|
wantDelete: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "a secret of the wrong type",
|
||||||
|
secret: &corev1.Secret{
|
||||||
|
Type: "secrets.pinniped.dev/not-the-oidc-client-type",
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "some-name", Namespace: "some-namespace"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "resource of wrong data type",
|
||||||
|
secret: &corev1.Namespace{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "some-name", Namespace: "some-namespace"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
test := test
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
fakePinnipedClient := pinnipedfake.NewSimpleClientset()
|
||||||
|
pinnipedInformers := pinnipedinformers.NewSharedInformerFactory(fakePinnipedClient, 0)
|
||||||
|
fakeKubeClient := fake.NewSimpleClientset()
|
||||||
|
kubeInformers := informers.NewSharedInformerFactory(fakeKubeClient, 0)
|
||||||
|
testLog := testlogger.New(t)
|
||||||
|
cache := provider.NewDynamicUpstreamIDPProvider()
|
||||||
|
cache.SetIDPList([]provider.UpstreamOIDCIdentityProviderI{
|
||||||
|
&upstreamoidc.ProviderConfig{Name: "initial-entry"},
|
||||||
|
})
|
||||||
|
secretInformer := kubeInformers.Core().V1().Secrets()
|
||||||
|
withInformer := testutil.NewObservableWithInformerOption()
|
||||||
|
|
||||||
|
New(
|
||||||
|
cache,
|
||||||
|
nil,
|
||||||
|
pinnipedInformers.IDP().V1alpha1().OIDCIdentityProviders(),
|
||||||
|
secretInformer,
|
||||||
|
testLog,
|
||||||
|
withInformer.WithInformer,
|
||||||
|
)
|
||||||
|
|
||||||
|
unrelated := corev1.Secret{}
|
||||||
|
filter := withInformer.GetFilterForInformer(secretInformer)
|
||||||
|
require.Equal(t, test.wantAdd, filter.Add(test.secret))
|
||||||
|
require.Equal(t, test.wantUpdate, filter.Update(&unrelated, test.secret))
|
||||||
|
require.Equal(t, test.wantUpdate, filter.Update(test.secret, &unrelated))
|
||||||
|
require.Equal(t, test.wantDelete, filter.Delete(test.secret))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestController(t *testing.T) {
|
func TestController(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
now := metav1.NewTime(time.Now().UTC())
|
now := metav1.NewTime(time.Now().UTC())
|
||||||
@ -550,7 +620,9 @@ func TestController(t *testing.T) {
|
|||||||
fakePinnipedClient,
|
fakePinnipedClient,
|
||||||
pinnipedInformers.IDP().V1alpha1().OIDCIdentityProviders(),
|
pinnipedInformers.IDP().V1alpha1().OIDCIdentityProviders(),
|
||||||
kubeInformers.Core().V1().Secrets(),
|
kubeInformers.Core().V1().Secrets(),
|
||||||
testLog)
|
testLog,
|
||||||
|
controllerlib.WithInformer,
|
||||||
|
)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
@ -33,7 +33,7 @@ func SimpleFilter(match func(metav1.Object) bool, parentFunc controllerlib.Paren
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func MatchAnySecretOfTypeFilter(secretType v1.SecretType) controllerlib.Filter {
|
func MatchAnySecretOfTypeFilter(secretType v1.SecretType, parentFunc controllerlib.ParentFunc) controllerlib.Filter {
|
||||||
isSecretOfType := func(obj metav1.Object) bool {
|
isSecretOfType := func(obj metav1.Object) bool {
|
||||||
secret, ok := obj.(*v1.Secret)
|
secret, ok := obj.(*v1.Secret)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -41,7 +41,7 @@ func MatchAnySecretOfTypeFilter(secretType v1.SecretType) controllerlib.Filter {
|
|||||||
}
|
}
|
||||||
return secret.Type == secretType
|
return secret.Type == secretType
|
||||||
}
|
}
|
||||||
return SimpleFilter(isSecretOfType, nil)
|
return SimpleFilter(isSecretOfType, parentFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SecretIsControlledByParentFunc(matchFunc func(obj metav1.Object) bool) func(obj metav1.Object) controllerlib.Key {
|
func SecretIsControlledByParentFunc(matchFunc func(obj metav1.Object) bool) func(obj metav1.Object) controllerlib.Key {
|
||||||
|
Loading…
Reference in New Issue
Block a user