diff --git a/federation/cmd/federation-controller-manager/app/controllermanager.go b/federation/cmd/federation-controller-manager/app/controllermanager.go index a66b34b3f99..78a71a2b2db 100644 --- a/federation/cmd/federation-controller-manager/app/controllermanager.go +++ b/federation/cmd/federation-controller-manager/app/controllermanager.go @@ -190,9 +190,7 @@ func StartControllers(s *options.CMServer, restClientCfg *restclient.Config) err } if controllerEnabled(s.Controllers, serverResources, secretcontroller.ControllerName, secretcontroller.RequiredResources, true) { - secretcontrollerClientset := federationclientset.NewForConfigOrDie(restclient.AddUserAgent(restClientCfg, "secret-controller")) - secretcontroller := secretcontroller.NewSecretController(secretcontrollerClientset) - secretcontroller.Run(wait.NeverStop) + secretcontroller.StartSecretController(restClientCfg, stopChan, minimizeLatency) } if controllerEnabled(s.Controllers, serverResources, configmapcontroller.ControllerName, configmapcontroller.RequiredResources, true) { diff --git a/federation/pkg/federation-controller/secret/BUILD b/federation/pkg/federation-controller/secret/BUILD index 363202a3de5..3ad927bed97 100644 --- a/federation/pkg/federation-controller/secret/BUILD +++ b/federation/pkg/federation-controller/secret/BUILD @@ -30,6 +30,7 @@ go_library( "//vendor:k8s.io/apimachinery/pkg/types", "//vendor:k8s.io/apimachinery/pkg/watch", "//vendor:k8s.io/client-go/pkg/api/v1", + "//vendor:k8s.io/client-go/rest", "//vendor:k8s.io/client-go/tools/cache", "//vendor:k8s.io/client-go/tools/record", "//vendor:k8s.io/client-go/util/flowcontrol", diff --git a/federation/pkg/federation-controller/secret/secret_controller.go b/federation/pkg/federation-controller/secret/secret_controller.go index a6a80e1dd0e..200f13404a9 100644 --- a/federation/pkg/federation-controller/secret/secret_controller.go +++ b/federation/pkg/federation-controller/secret/secret_controller.go @@ -27,6 +27,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/watch" clientv1 "k8s.io/client-go/pkg/api/v1" + restclient "k8s.io/client-go/rest" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/record" "k8s.io/client-go/util/flowcontrol" @@ -88,8 +89,20 @@ type SecretController struct { updateTimeout time.Duration } -// NewSecretController returns a new secret controller -func NewSecretController(client federationclientset.Interface) *SecretController { +// StartSecretController starts a new secret controller +func StartSecretController(config *restclient.Config, stopChan <-chan struct{}, minimizeLatency bool) { + restclient.AddUserAgent(config, "secret-controller") + client := federationclientset.NewForConfigOrDie(config) + controller := newSecretController(client) + if minimizeLatency { + controller.minimizeLatency() + } + glog.Infof("Starting Secret controller") + controller.Run(stopChan) +} + +// newSecretController returns a new secret controller +func newSecretController(client federationclientset.Interface) *SecretController { broadcaster := record.NewBroadcaster() broadcaster.StartRecordingToSink(eventsink.NewFederatedEventSink(client)) recorder := broadcaster.NewRecorder(api.Scheme, clientv1.EventSource{Component: "federated-secrets-controller"}) @@ -190,6 +203,14 @@ func NewSecretController(client federationclientset.Interface) *SecretController return secretcontroller } +// minimizeLatency reduces delays and timeouts to make the controller more responsive (useful for testing). +func (secretcontroller *SecretController) minimizeLatency() { + secretcontroller.clusterAvailableDelay = time.Second + secretcontroller.secretReviewDelay = 50 * time.Millisecond + secretcontroller.smallDelay = 20 * time.Millisecond + secretcontroller.updateTimeout = 5 * time.Second +} + // Returns true if the given object has the given finalizer in its ObjectMeta. func (secretcontroller *SecretController) hasFinalizerFunc(obj pkgruntime.Object, finalizer string) bool { secret := obj.(*apiv1.Secret) diff --git a/federation/pkg/federation-controller/secret/secret_controller_test.go b/federation/pkg/federation-controller/secret/secret_controller_test.go index bb71d343424..b7c68f87ce6 100644 --- a/federation/pkg/federation-controller/secret/secret_controller_test.go +++ b/federation/pkg/federation-controller/secret/secret_controller_test.go @@ -66,7 +66,7 @@ func TestSecretController(t *testing.T) { RegisterFakeList(secrets, &cluster2Client.Fake, &apiv1.SecretList{Items: []apiv1.Secret{}}) cluster2CreateChan := RegisterFakeCopyOnCreate(secrets, &cluster2Client.Fake, cluster2Watch) - secretController := NewSecretController(fakeClient) + secretController := newSecretController(fakeClient) informerClientFactory := func(cluster *federationapi.Cluster) (kubeclientset.Interface, error) { switch cluster.Name { case cluster1.Name: @@ -79,10 +79,7 @@ func TestSecretController(t *testing.T) { } setClientFactory(secretController.secretFederatedInformer, informerClientFactory) - secretController.clusterAvailableDelay = time.Second - secretController.secretReviewDelay = 50 * time.Millisecond - secretController.smallDelay = 20 * time.Millisecond - secretController.updateTimeout = 5 * time.Second + secretController.minimizeLatency() stop := make(chan struct{}) secretController.Run(stop)