mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-09-27 18:34:40 +00:00
Pull controller-go back into this repository as internal/controllerlib.
Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
@@ -18,9 +18,9 @@ import (
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"github.com/suzerain-io/controller-go"
|
||||
"github.com/suzerain-io/pinniped/internal/constable"
|
||||
pinnipedcontroller "github.com/suzerain-io/pinniped/internal/controller"
|
||||
"github.com/suzerain-io/pinniped/internal/controllerlib"
|
||||
)
|
||||
|
||||
type certsExpirerController struct {
|
||||
@@ -33,7 +33,7 @@ type certsExpirerController struct {
|
||||
renewBefore time.Duration
|
||||
}
|
||||
|
||||
// NewCertsExpirerController returns a controller.Controller that will delete a
|
||||
// NewCertsExpirerController returns a controllerlib.Controller that will delete a
|
||||
// certificate secret once it gets within some threshold of its expiration time. The
|
||||
// deletion forces rotation of the secret with the help of other controllers.
|
||||
func NewCertsExpirerController(
|
||||
@@ -42,9 +42,9 @@ func NewCertsExpirerController(
|
||||
secretInformer corev1informers.SecretInformer,
|
||||
withInformer pinnipedcontroller.WithInformerOptionFunc,
|
||||
renewBefore time.Duration,
|
||||
) controller.Controller {
|
||||
return controller.New(
|
||||
controller.Config{
|
||||
) controllerlib.Controller {
|
||||
return controllerlib.New(
|
||||
controllerlib.Config{
|
||||
Name: "certs-expirer-controller",
|
||||
Syncer: &certsExpirerController{
|
||||
namespace: namespace,
|
||||
@@ -56,13 +56,13 @@ func NewCertsExpirerController(
|
||||
withInformer(
|
||||
secretInformer,
|
||||
pinnipedcontroller.NameAndNamespaceExactMatchFilterFactory(certsSecretName, namespace),
|
||||
controller.InformerOption{},
|
||||
controllerlib.InformerOption{},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// Sync implements controller.Syncer.Sync.
|
||||
func (c *certsExpirerController) Sync(ctx controller.Context) error {
|
||||
func (c *certsExpirerController) Sync(ctx controllerlib.Context) error {
|
||||
secret, err := c.secretInformer.Lister().Secrets(c.namespace).Get(certsSecretName)
|
||||
notFound := k8serrors.IsNotFound(err)
|
||||
if err != nil && !notFound {
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
kubernetesfake "k8s.io/client-go/kubernetes/fake"
|
||||
kubetesting "k8s.io/client-go/testing"
|
||||
|
||||
"github.com/suzerain-io/controller-go"
|
||||
"github.com/suzerain-io/pinniped/internal/controllerlib"
|
||||
"github.com/suzerain-io/pinniped/internal/testutil"
|
||||
)
|
||||
|
||||
@@ -247,15 +247,15 @@ func TestExpirerControllerSync(t *testing.T) {
|
||||
namespace,
|
||||
kubeAPIClient,
|
||||
kubeInformers.Core().V1().Secrets(),
|
||||
controller.WithInformer,
|
||||
controllerlib.WithInformer,
|
||||
test.renewBefore,
|
||||
)
|
||||
|
||||
// Must start informers before calling TestRunSynchronously().
|
||||
kubeInformers.Start(ctx.Done())
|
||||
controller.TestRunSynchronously(t, c)
|
||||
controllerlib.TestRunSynchronously(t, c)
|
||||
|
||||
err := controller.TestSync(t, c, controller.Context{
|
||||
err := controllerlib.TestSync(t, c, controllerlib.Context{
|
||||
Context: ctx,
|
||||
})
|
||||
if test.wantError != "" {
|
||||
|
||||
@@ -18,9 +18,9 @@ import (
|
||||
"k8s.io/klog/v2"
|
||||
aggregatorclient "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
|
||||
|
||||
"github.com/suzerain-io/controller-go"
|
||||
"github.com/suzerain-io/pinniped/internal/certauthority"
|
||||
pinnipedcontroller "github.com/suzerain-io/pinniped/internal/controller"
|
||||
"github.com/suzerain-io/pinniped/internal/controllerlib"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -50,9 +50,9 @@ func NewCertsManagerController(
|
||||
withInformer pinnipedcontroller.WithInformerOptionFunc,
|
||||
withInitialEvent pinnipedcontroller.WithInitialEventOptionFunc,
|
||||
certDuration time.Duration,
|
||||
) controller.Controller {
|
||||
return controller.New(
|
||||
controller.Config{
|
||||
) controllerlib.Controller {
|
||||
return controllerlib.New(
|
||||
controllerlib.Config{
|
||||
Name: "certs-manager-controller",
|
||||
Syncer: &certsManagerController{
|
||||
namespace: namespace,
|
||||
@@ -65,17 +65,17 @@ func NewCertsManagerController(
|
||||
withInformer(
|
||||
secretInformer,
|
||||
pinnipedcontroller.NameAndNamespaceExactMatchFilterFactory(certsSecretName, namespace),
|
||||
controller.InformerOption{},
|
||||
controllerlib.InformerOption{},
|
||||
),
|
||||
// Be sure to run once even if the Secret that the informer is watching doesn't exist.
|
||||
withInitialEvent(controller.Key{
|
||||
withInitialEvent(controllerlib.Key{
|
||||
Namespace: namespace,
|
||||
Name: certsSecretName,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
func (c *certsManagerController) Sync(ctx controller.Context) error {
|
||||
func (c *certsManagerController) Sync(ctx controllerlib.Context) error {
|
||||
// Try to get the secret from the informer cache.
|
||||
_, err := c.secretInformer.Lister().Secrets(c.namespace).Get(certsSecretName)
|
||||
notFound := k8serrors.IsNotFound(err)
|
||||
|
||||
@@ -24,8 +24,8 @@ import (
|
||||
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
|
||||
aggregatorfake "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/fake"
|
||||
|
||||
"github.com/suzerain-io/controller-go"
|
||||
pinnipedv1alpha1 "github.com/suzerain-io/pinniped/generated/1.19/apis/pinniped/v1alpha1"
|
||||
"github.com/suzerain-io/pinniped/internal/controllerlib"
|
||||
"github.com/suzerain-io/pinniped/internal/testutil"
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ func TestManagerControllerOptions(t *testing.T) {
|
||||
var r *require.Assertions
|
||||
var observableWithInformerOption *testutil.ObservableWithInformerOption
|
||||
var observableWithInitialEventOption *testutil.ObservableWithInitialEventOption
|
||||
var secretsInformerFilter controller.Filter
|
||||
var secretsInformerFilter controllerlib.Filter
|
||||
|
||||
it.Before(func() {
|
||||
r = require.New(t)
|
||||
@@ -56,7 +56,7 @@ func TestManagerControllerOptions(t *testing.T) {
|
||||
})
|
||||
|
||||
when("watching Secret objects", func() {
|
||||
var subject controller.Filter
|
||||
var subject controllerlib.Filter
|
||||
var target, wrongNamespace, wrongName, unrelated *corev1.Secret
|
||||
|
||||
it.Before(func() {
|
||||
@@ -105,7 +105,7 @@ func TestManagerControllerOptions(t *testing.T) {
|
||||
|
||||
when("starting up", func() {
|
||||
it("asks for an initial event because the Secret may not exist yet and it needs to run anyway", func() {
|
||||
r.Equal(controller.Key{
|
||||
r.Equal(controllerlib.Key{
|
||||
Namespace: installedInNamespace,
|
||||
Name: "api-serving-cert",
|
||||
}, observableWithInitialEventOption.GetInitialEventKey())
|
||||
@@ -121,14 +121,14 @@ func TestManagerControllerSync(t *testing.T) {
|
||||
|
||||
var r *require.Assertions
|
||||
|
||||
var subject controller.Controller
|
||||
var subject controllerlib.Controller
|
||||
var kubeAPIClient *kubernetesfake.Clientset
|
||||
var aggregatorAPIClient *aggregatorfake.Clientset
|
||||
var kubeInformerClient *kubernetesfake.Clientset
|
||||
var kubeInformers kubeinformers.SharedInformerFactory
|
||||
var timeoutContext context.Context
|
||||
var timeoutContextCancel context.CancelFunc
|
||||
var syncContext *controller.Context
|
||||
var syncContext *controllerlib.Context
|
||||
|
||||
// Defer starting the informers until the last possible moment so that the
|
||||
// nested Before's can keep adding things to the informer caches.
|
||||
@@ -139,16 +139,16 @@ func TestManagerControllerSync(t *testing.T) {
|
||||
kubeAPIClient,
|
||||
aggregatorAPIClient,
|
||||
kubeInformers.Core().V1().Secrets(),
|
||||
controller.WithInformer,
|
||||
controller.WithInitialEvent,
|
||||
controllerlib.WithInformer,
|
||||
controllerlib.WithInitialEvent,
|
||||
certDuration,
|
||||
)
|
||||
|
||||
// Set this at the last second to support calling subject.Name().
|
||||
syncContext = &controller.Context{
|
||||
syncContext = &controllerlib.Context{
|
||||
Context: timeoutContext,
|
||||
Name: subject.Name(),
|
||||
Key: controller.Key{
|
||||
Key: controllerlib.Key{
|
||||
Namespace: installedInNamespace,
|
||||
Name: "api-serving-cert",
|
||||
},
|
||||
@@ -156,7 +156,7 @@ func TestManagerControllerSync(t *testing.T) {
|
||||
|
||||
// Must start informers before calling TestRunSynchronously()
|
||||
kubeInformers.Start(timeoutContext.Done())
|
||||
controller.TestRunSynchronously(t, subject)
|
||||
controllerlib.TestRunSynchronously(t, subject)
|
||||
}
|
||||
|
||||
it.Before(func() {
|
||||
@@ -203,7 +203,7 @@ func TestManagerControllerSync(t *testing.T) {
|
||||
|
||||
it("creates the api-serving-cert Secret and updates the APIService's ca bundle", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.NoError(err)
|
||||
|
||||
// Check all the relevant fields from the create Secret action
|
||||
@@ -269,7 +269,7 @@ func TestManagerControllerSync(t *testing.T) {
|
||||
|
||||
it("returns the update error", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.EqualError(err, "could not update the API service: could not update API service: update failed")
|
||||
})
|
||||
})
|
||||
@@ -287,7 +287,7 @@ func TestManagerControllerSync(t *testing.T) {
|
||||
|
||||
it("returns an error", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.Error(err)
|
||||
r.Regexp("could not get existing version of API service: .* not found", err.Error())
|
||||
})
|
||||
@@ -306,7 +306,7 @@ func TestManagerControllerSync(t *testing.T) {
|
||||
|
||||
it("returns the create error and does not update the APIService", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.EqualError(err, "could not create secret: create failed")
|
||||
r.Empty(aggregatorAPIClient.Actions())
|
||||
})
|
||||
@@ -327,7 +327,7 @@ func TestManagerControllerSync(t *testing.T) {
|
||||
|
||||
it("does not need to make any API calls with its API clients", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.NoError(err)
|
||||
r.Empty(kubeAPIClient.Actions())
|
||||
r.Empty(aggregatorAPIClient.Actions())
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
corev1informers "k8s.io/client-go/informers/core/v1"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"github.com/suzerain-io/controller-go"
|
||||
pinnipedcontroller "github.com/suzerain-io/pinniped/internal/controller"
|
||||
"github.com/suzerain-io/pinniped/internal/controllerlib"
|
||||
"github.com/suzerain-io/pinniped/internal/provider"
|
||||
)
|
||||
|
||||
@@ -28,9 +28,9 @@ func NewCertsObserverController(
|
||||
dynamicCertProvider provider.DynamicTLSServingCertProvider,
|
||||
secretInformer corev1informers.SecretInformer,
|
||||
withInformer pinnipedcontroller.WithInformerOptionFunc,
|
||||
) controller.Controller {
|
||||
return controller.New(
|
||||
controller.Config{
|
||||
) controllerlib.Controller {
|
||||
return controllerlib.New(
|
||||
controllerlib.Config{
|
||||
Name: "certs-observer-controller",
|
||||
Syncer: &certsObserverController{
|
||||
namespace: namespace,
|
||||
@@ -41,12 +41,12 @@ func NewCertsObserverController(
|
||||
withInformer(
|
||||
secretInformer,
|
||||
pinnipedcontroller.NameAndNamespaceExactMatchFilterFactory(certsSecretName, namespace),
|
||||
controller.InformerOption{},
|
||||
controllerlib.InformerOption{},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
func (c *certsObserverController) Sync(_ controller.Context) error {
|
||||
func (c *certsObserverController) Sync(_ controllerlib.Context) error {
|
||||
// Try to get the secret from the informer cache.
|
||||
certSecret, err := c.secretInformer.Lister().Secrets(c.namespace).Get(certsSecretName)
|
||||
notFound := k8serrors.IsNotFound(err)
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
kubeinformers "k8s.io/client-go/informers"
|
||||
kubernetesfake "k8s.io/client-go/kubernetes/fake"
|
||||
|
||||
"github.com/suzerain-io/controller-go"
|
||||
"github.com/suzerain-io/pinniped/internal/controllerlib"
|
||||
"github.com/suzerain-io/pinniped/internal/provider"
|
||||
"github.com/suzerain-io/pinniped/internal/testutil"
|
||||
)
|
||||
@@ -29,7 +29,7 @@ func TestObserverControllerInformerFilters(t *testing.T) {
|
||||
|
||||
var r *require.Assertions
|
||||
var observableWithInformerOption *testutil.ObservableWithInformerOption
|
||||
var secretsInformerFilter controller.Filter
|
||||
var secretsInformerFilter controllerlib.Filter
|
||||
|
||||
it.Before(func() {
|
||||
r = require.New(t)
|
||||
@@ -45,7 +45,7 @@ func TestObserverControllerInformerFilters(t *testing.T) {
|
||||
})
|
||||
|
||||
when("watching Secret objects", func() {
|
||||
var subject controller.Filter
|
||||
var subject controllerlib.Filter
|
||||
var target, wrongNamespace, wrongName, unrelated *corev1.Secret
|
||||
|
||||
it.Before(func() {
|
||||
@@ -100,12 +100,12 @@ func TestObserverControllerSync(t *testing.T) {
|
||||
|
||||
var r *require.Assertions
|
||||
|
||||
var subject controller.Controller
|
||||
var subject controllerlib.Controller
|
||||
var kubeInformerClient *kubernetesfake.Clientset
|
||||
var kubeInformers kubeinformers.SharedInformerFactory
|
||||
var timeoutContext context.Context
|
||||
var timeoutContextCancel context.CancelFunc
|
||||
var syncContext *controller.Context
|
||||
var syncContext *controllerlib.Context
|
||||
var dynamicCertProvider provider.DynamicTLSServingCertProvider
|
||||
|
||||
// Defer starting the informers until the last possible moment so that the
|
||||
@@ -116,14 +116,14 @@ func TestObserverControllerSync(t *testing.T) {
|
||||
installedInNamespace,
|
||||
dynamicCertProvider,
|
||||
kubeInformers.Core().V1().Secrets(),
|
||||
controller.WithInformer,
|
||||
controllerlib.WithInformer,
|
||||
)
|
||||
|
||||
// Set this at the last second to support calling subject.Name().
|
||||
syncContext = &controller.Context{
|
||||
syncContext = &controllerlib.Context{
|
||||
Context: timeoutContext,
|
||||
Name: subject.Name(),
|
||||
Key: controller.Key{
|
||||
Key: controllerlib.Key{
|
||||
Namespace: installedInNamespace,
|
||||
Name: "api-serving-cert",
|
||||
},
|
||||
@@ -131,7 +131,7 @@ func TestObserverControllerSync(t *testing.T) {
|
||||
|
||||
// Must start informers before calling TestRunSynchronously()
|
||||
kubeInformers.Start(timeoutContext.Done())
|
||||
controller.TestRunSynchronously(t, subject)
|
||||
controllerlib.TestRunSynchronously(t, subject)
|
||||
}
|
||||
|
||||
it.Before(func() {
|
||||
@@ -164,7 +164,7 @@ func TestObserverControllerSync(t *testing.T) {
|
||||
|
||||
it("sets the dynamicCertProvider's cert and key to nil", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.NoError(err)
|
||||
|
||||
actualCertChain, actualKey := dynamicCertProvider.CurrentCertKeyContent()
|
||||
@@ -194,7 +194,7 @@ func TestObserverControllerSync(t *testing.T) {
|
||||
|
||||
it("updates the dynamicCertProvider's cert and key", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.NoError(err)
|
||||
|
||||
actualCertChain, actualKey := dynamicCertProvider.CurrentCertKeyContent()
|
||||
@@ -220,7 +220,7 @@ func TestObserverControllerSync(t *testing.T) {
|
||||
|
||||
it("set the missing values in the dynamicCertProvider as nil", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.NoError(err)
|
||||
|
||||
actualCertChain, actualKey := dynamicCertProvider.CurrentCertKeyContent()
|
||||
|
||||
@@ -14,11 +14,11 @@ import (
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"github.com/suzerain-io/controller-go"
|
||||
crdpinnipedv1alpha1 "github.com/suzerain-io/pinniped/generated/1.19/apis/crdpinniped/v1alpha1"
|
||||
pinnipedclientset "github.com/suzerain-io/pinniped/generated/1.19/client/clientset/versioned"
|
||||
crdpinnipedv1alpha1informers "github.com/suzerain-io/pinniped/generated/1.19/client/informers/externalversions/crdpinniped/v1alpha1"
|
||||
pinnipedcontroller "github.com/suzerain-io/pinniped/internal/controller"
|
||||
"github.com/suzerain-io/pinniped/internal/controllerlib"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -45,9 +45,9 @@ func NewPublisherController(
|
||||
configMapInformer corev1informers.ConfigMapInformer,
|
||||
credentialIssuerConfigInformer crdpinnipedv1alpha1informers.CredentialIssuerConfigInformer,
|
||||
withInformer pinnipedcontroller.WithInformerOptionFunc,
|
||||
) controller.Controller {
|
||||
return controller.New(
|
||||
controller.Config{
|
||||
) controllerlib.Controller {
|
||||
return controllerlib.New(
|
||||
controllerlib.Config{
|
||||
Name: "publisher-controller",
|
||||
Syncer: &publisherController{
|
||||
namespace: namespace,
|
||||
@@ -60,17 +60,17 @@ func NewPublisherController(
|
||||
withInformer(
|
||||
configMapInformer,
|
||||
pinnipedcontroller.NameAndNamespaceExactMatchFilterFactory(clusterInfoName, ClusterInfoNamespace),
|
||||
controller.InformerOption{},
|
||||
controllerlib.InformerOption{},
|
||||
),
|
||||
withInformer(
|
||||
credentialIssuerConfigInformer,
|
||||
pinnipedcontroller.NameAndNamespaceExactMatchFilterFactory(configName, namespace),
|
||||
controller.InformerOption{},
|
||||
controllerlib.InformerOption{},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
func (c *publisherController) Sync(ctx controller.Context) error {
|
||||
func (c *publisherController) Sync(ctx controllerlib.Context) error {
|
||||
configMap, err := c.configMapInformer.
|
||||
Lister().
|
||||
ConfigMaps(ClusterInfoNamespace).
|
||||
|
||||
@@ -23,10 +23,10 @@ import (
|
||||
kubernetesfake "k8s.io/client-go/kubernetes/fake"
|
||||
coretesting "k8s.io/client-go/testing"
|
||||
|
||||
"github.com/suzerain-io/controller-go"
|
||||
crdpinnipedv1alpha1 "github.com/suzerain-io/pinniped/generated/1.19/apis/crdpinniped/v1alpha1"
|
||||
pinnipedfake "github.com/suzerain-io/pinniped/generated/1.19/client/clientset/versioned/fake"
|
||||
pinnipedinformers "github.com/suzerain-io/pinniped/generated/1.19/client/informers/externalversions"
|
||||
"github.com/suzerain-io/pinniped/internal/controllerlib"
|
||||
"github.com/suzerain-io/pinniped/internal/testutil"
|
||||
)
|
||||
|
||||
@@ -36,8 +36,8 @@ func TestInformerFilters(t *testing.T) {
|
||||
|
||||
var r *require.Assertions
|
||||
var observableWithInformerOption *testutil.ObservableWithInformerOption
|
||||
var configMapInformerFilter controller.Filter
|
||||
var credentialIssuerConfigInformerFilter controller.Filter
|
||||
var configMapInformerFilter controllerlib.Filter
|
||||
var credentialIssuerConfigInformerFilter controllerlib.Filter
|
||||
|
||||
it.Before(func() {
|
||||
r = require.New(t)
|
||||
@@ -57,7 +57,7 @@ func TestInformerFilters(t *testing.T) {
|
||||
})
|
||||
|
||||
when("watching ConfigMap objects", func() {
|
||||
var subject controller.Filter
|
||||
var subject controllerlib.Filter
|
||||
var target, wrongNamespace, wrongName, unrelated *corev1.ConfigMap
|
||||
|
||||
it.Before(func() {
|
||||
@@ -105,7 +105,7 @@ func TestInformerFilters(t *testing.T) {
|
||||
})
|
||||
|
||||
when("watching CredentialIssuerConfig objects", func() {
|
||||
var subject controller.Filter
|
||||
var subject controllerlib.Filter
|
||||
var target, wrongNamespace, wrongName, unrelated *crdpinnipedv1alpha1.CredentialIssuerConfig
|
||||
|
||||
it.Before(func() {
|
||||
@@ -168,7 +168,7 @@ func TestSync(t *testing.T) {
|
||||
|
||||
var r *require.Assertions
|
||||
|
||||
var subject controller.Controller
|
||||
var subject controllerlib.Controller
|
||||
var serverOverride *string
|
||||
var kubeInformerClient *kubernetesfake.Clientset
|
||||
var pinnipedInformerClient *pinnipedfake.Clientset
|
||||
@@ -177,7 +177,7 @@ func TestSync(t *testing.T) {
|
||||
var pinnipedAPIClient *pinnipedfake.Clientset
|
||||
var timeoutContext context.Context
|
||||
var timeoutContextCancel context.CancelFunc
|
||||
var syncContext *controller.Context
|
||||
var syncContext *controllerlib.Context
|
||||
|
||||
var expectedCredentialIssuerConfig = func(expectedNamespace, expectedServerURL, expectedCAData string) (schema.GroupVersionResource, *crdpinnipedv1alpha1.CredentialIssuerConfig) {
|
||||
expectedCredentialIssuerConfigGVR := schema.GroupVersionResource{
|
||||
@@ -211,14 +211,14 @@ func TestSync(t *testing.T) {
|
||||
pinnipedAPIClient,
|
||||
kubeInformers.Core().V1().ConfigMaps(),
|
||||
pinnipedInformers.Crd().V1alpha1().CredentialIssuerConfigs(),
|
||||
controller.WithInformer,
|
||||
controllerlib.WithInformer,
|
||||
)
|
||||
|
||||
// Set this at the last second to support calling subject.Name().
|
||||
syncContext = &controller.Context{
|
||||
syncContext = &controllerlib.Context{
|
||||
Context: timeoutContext,
|
||||
Name: subject.Name(),
|
||||
Key: controller.Key{
|
||||
Key: controllerlib.Key{
|
||||
Namespace: "kube-public",
|
||||
Name: "cluster-info",
|
||||
},
|
||||
@@ -227,7 +227,7 @@ func TestSync(t *testing.T) {
|
||||
// Must start informers before calling TestRunSynchronously()
|
||||
kubeInformers.Start(timeoutContext.Done())
|
||||
pinnipedInformers.Start(timeoutContext.Done())
|
||||
controller.TestRunSynchronously(t, subject)
|
||||
controllerlib.TestRunSynchronously(t, subject)
|
||||
}
|
||||
|
||||
it.Before(func() {
|
||||
@@ -274,7 +274,7 @@ func TestSync(t *testing.T) {
|
||||
when("the CredentialIssuerConfig does not already exist", func() {
|
||||
it("creates a CredentialIssuerConfig", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.NoError(err)
|
||||
|
||||
expectedCredentialIssuerConfigGVR, expectedCredentialIssuerConfig := expectedCredentialIssuerConfig(
|
||||
@@ -308,7 +308,7 @@ func TestSync(t *testing.T) {
|
||||
|
||||
it("returns the create error", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.EqualError(err, "could not create or update credentialissuerconfig: create failed: create failed")
|
||||
})
|
||||
})
|
||||
@@ -319,7 +319,7 @@ func TestSync(t *testing.T) {
|
||||
*serverOverride = "https://some-server-override"
|
||||
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.NoError(err)
|
||||
|
||||
expectedCredentialIssuerConfigGVR, expectedCredentialIssuerConfig := expectedCredentialIssuerConfig(
|
||||
@@ -357,7 +357,7 @@ func TestSync(t *testing.T) {
|
||||
|
||||
it("does not update the CredentialIssuerConfig to avoid unnecessary etcd writes/api calls", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.NoError(err)
|
||||
|
||||
r.Empty(pinnipedAPIClient.Actions())
|
||||
@@ -378,7 +378,7 @@ func TestSync(t *testing.T) {
|
||||
|
||||
it("updates the existing CredentialIssuerConfig", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.NoError(err)
|
||||
|
||||
expectedCredentialIssuerConfigGVR, expectedCredentialIssuerConfig := expectedCredentialIssuerConfig(
|
||||
@@ -409,7 +409,7 @@ func TestSync(t *testing.T) {
|
||||
|
||||
it("returns the update error", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.EqualError(err, "could not create or update credentialissuerconfig: update failed")
|
||||
})
|
||||
})
|
||||
@@ -431,7 +431,7 @@ func TestSync(t *testing.T) {
|
||||
|
||||
it("keeps waiting for it to exist", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.NoError(err)
|
||||
r.Empty(pinnipedAPIClient.Actions())
|
||||
})
|
||||
@@ -451,7 +451,7 @@ func TestSync(t *testing.T) {
|
||||
|
||||
it("keeps waiting for it to be properly formatted", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.NoError(err)
|
||||
r.Empty(pinnipedAPIClient.Actions())
|
||||
})
|
||||
@@ -472,7 +472,7 @@ func TestSync(t *testing.T) {
|
||||
|
||||
it("keeps waiting for one", func() {
|
||||
startInformersAndController()
|
||||
err := controller.TestSync(t, subject, *syncContext)
|
||||
err := controllerlib.TestSync(t, subject, *syncContext)
|
||||
r.NoError(err)
|
||||
r.Empty(pinnipedAPIClient.Actions())
|
||||
})
|
||||
|
||||
@@ -8,14 +8,14 @@ package controller
|
||||
import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/suzerain-io/controller-go"
|
||||
"github.com/suzerain-io/pinniped/internal/controllerlib"
|
||||
)
|
||||
|
||||
func NameAndNamespaceExactMatchFilterFactory(name, namespace string) controller.FilterFuncs {
|
||||
func NameAndNamespaceExactMatchFilterFactory(name, namespace string) controllerlib.FilterFuncs {
|
||||
objMatchesFunc := func(obj metav1.Object) bool {
|
||||
return obj.GetName() == name && obj.GetNamespace() == namespace
|
||||
}
|
||||
return controller.FilterFuncs{
|
||||
return controllerlib.FilterFuncs{
|
||||
AddFunc: objMatchesFunc,
|
||||
UpdateFunc: func(oldObj, newObj metav1.Object) bool {
|
||||
return objMatchesFunc(oldObj) || objMatchesFunc(newObj)
|
||||
@@ -24,11 +24,11 @@ func NameAndNamespaceExactMatchFilterFactory(name, namespace string) controller.
|
||||
}
|
||||
}
|
||||
|
||||
// Same signature as controller.WithInformer().
|
||||
// Same signature as controllerlib.WithInformer().
|
||||
type WithInformerOptionFunc func(
|
||||
getter controller.InformerGetter,
|
||||
filter controller.Filter,
|
||||
opt controller.InformerOption) controller.Option
|
||||
getter controllerlib.InformerGetter,
|
||||
filter controllerlib.Filter,
|
||||
opt controllerlib.InformerOption) controllerlib.Option
|
||||
|
||||
// Same signature as controller.WithInitialEvent().
|
||||
type WithInitialEventOptionFunc func(key controller.Key) controller.Option
|
||||
// Same signature as controllerlib.WithInitialEvent().
|
||||
type WithInitialEventOptionFunc func(key controllerlib.Key) controllerlib.Option
|
||||
|
||||
Reference in New Issue
Block a user