From 4cfcf0519db4c82abdb0ff8e7108b6784cf35cdf Mon Sep 17 00:00:00 2001 From: Peter McAlpine Date: Tue, 26 Feb 2019 14:51:44 -0500 Subject: [PATCH] Fix lint warnings in pkg/controller/bootstrap --- cmd/kube-controller-manager/app/bootstrap.go | 4 +- hack/.golint_failures | 1 - pkg/controller/bootstrap/bootstrapsigner.go | 37 +++++++++---------- .../bootstrap/bootstrapsigner_test.go | 26 ++++++------- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/cmd/kube-controller-manager/app/bootstrap.go b/cmd/kube-controller-manager/app/bootstrap.go index 70c00b9e52d..75e8a113f67 100644 --- a/cmd/kube-controller-manager/app/bootstrap.go +++ b/cmd/kube-controller-manager/app/bootstrap.go @@ -25,11 +25,11 @@ import ( ) func startBootstrapSignerController(ctx ControllerContext) (http.Handler, bool, error) { - bsc, err := bootstrap.NewBootstrapSigner( + bsc, err := bootstrap.NewSigner( ctx.ClientBuilder.ClientOrDie("bootstrap-signer"), ctx.InformerFactory.Core().V1().Secrets(), ctx.InformerFactory.Core().V1().ConfigMaps(), - bootstrap.DefaultBootstrapSignerOptions(), + bootstrap.DefaultSignerOptions(), ) if err != nil { return nil, true, fmt.Errorf("error creating BootstrapSigner controller: %v", err) diff --git a/hack/.golint_failures b/hack/.golint_failures index 5a9a043e6fa..5814940e1b1 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -74,7 +74,6 @@ pkg/cloudprovider/providers/photon pkg/cloudprovider/providers/vsphere pkg/controller pkg/controller/apis/config/v1alpha1 -pkg/controller/bootstrap pkg/controller/certificates pkg/controller/certificates/approver pkg/controller/certificates/signer diff --git a/pkg/controller/bootstrap/bootstrapsigner.go b/pkg/controller/bootstrap/bootstrapsigner.go index 60952976eb5..1ae56033c7d 100644 --- a/pkg/controller/bootstrap/bootstrapsigner.go +++ b/pkg/controller/bootstrap/bootstrapsigner.go @@ -39,8 +39,8 @@ import ( "k8s.io/kubernetes/pkg/util/metrics" ) -// BootstrapSignerOptions contains options for the BootstrapSigner -type BootstrapSignerOptions struct { +// SignerOptions contains options for the Signer +type SignerOptions struct { // ConfigMapNamespace is the namespace of the ConfigMap ConfigMapNamespace string @@ -59,18 +59,17 @@ type BootstrapSignerOptions struct { SecretResync time.Duration } -// DefaultBootstrapSignerOptions returns a set of default options for creating a -// BootstrapSigner -func DefaultBootstrapSignerOptions() BootstrapSignerOptions { - return BootstrapSignerOptions{ +// DefaultSignerOptions returns a set of default options for creating a Signer. +func DefaultSignerOptions() SignerOptions { + return SignerOptions{ ConfigMapNamespace: api.NamespacePublic, ConfigMapName: bootstrapapi.ConfigMapClusterInfo, TokenSecretNamespace: api.NamespaceSystem, } } -// BootstrapSigner is a controller that signs a ConfigMap with a set of tokens. -type BootstrapSigner struct { +// Signer is a controller that signs a ConfigMap with a set of tokens. +type Signer struct { client clientset.Interface configMapKey string configMapName string @@ -90,9 +89,9 @@ type BootstrapSigner struct { configMapSynced cache.InformerSynced } -// NewBootstrapSigner returns a new *BootstrapSigner. -func NewBootstrapSigner(cl clientset.Interface, secrets informers.SecretInformer, configMaps informers.ConfigMapInformer, options BootstrapSignerOptions) (*BootstrapSigner, error) { - e := &BootstrapSigner{ +// NewSigner returns a new *Signer. +func NewSigner(cl clientset.Interface, secrets informers.SecretInformer, configMaps informers.ConfigMapInformer, options SignerOptions) (*Signer, error) { + e := &Signer{ client: cl, configMapKey: options.ConfigMapNamespace + "/" + options.ConfigMapName, configMapName: options.ConfigMapName, @@ -153,7 +152,7 @@ func NewBootstrapSigner(cl clientset.Interface, secrets informers.SecretInformer } // Run runs controller loops and returns when they are done -func (e *BootstrapSigner) Run(stopCh <-chan struct{}) { +func (e *Signer) Run(stopCh <-chan struct{}) { // Shut down queues defer utilruntime.HandleCrash() defer e.syncQueue.ShutDown() @@ -168,11 +167,11 @@ func (e *BootstrapSigner) Run(stopCh <-chan struct{}) { klog.V(1).Infof("Shutting down") } -func (e *BootstrapSigner) pokeConfigMapSync() { +func (e *Signer) pokeConfigMapSync() { e.syncQueue.Add(e.configMapKey) } -func (e *BootstrapSigner) serviceConfigMapQueue() { +func (e *Signer) serviceConfigMapQueue() { key, quit := e.syncQueue.Get() if quit { return @@ -184,7 +183,7 @@ func (e *BootstrapSigner) serviceConfigMapQueue() { // signConfigMap computes the signatures on our latest cached objects and writes // back if necessary. -func (e *BootstrapSigner) signConfigMap() { +func (e *Signer) signConfigMap() { origCM := e.getConfigMap() if origCM == nil { @@ -241,7 +240,7 @@ func (e *BootstrapSigner) signConfigMap() { } } -func (e *BootstrapSigner) updateConfigMap(cm *v1.ConfigMap) { +func (e *Signer) updateConfigMap(cm *v1.ConfigMap) { _, err := e.client.CoreV1().ConfigMaps(cm.Namespace).Update(cm) if err != nil && !apierrors.IsConflict(err) && !apierrors.IsNotFound(err) { klog.V(3).Infof("Error updating ConfigMap: %v", err) @@ -249,7 +248,7 @@ func (e *BootstrapSigner) updateConfigMap(cm *v1.ConfigMap) { } // getConfigMap gets the ConfigMap we are interested in -func (e *BootstrapSigner) getConfigMap() *v1.ConfigMap { +func (e *Signer) getConfigMap() *v1.ConfigMap { configMap, err := e.configMapLister.ConfigMaps(e.configMapNamespace).Get(e.configMapName) // If we can't get the configmap just return nil. The resync will eventually @@ -264,7 +263,7 @@ func (e *BootstrapSigner) getConfigMap() *v1.ConfigMap { return configMap } -func (e *BootstrapSigner) listSecrets() []*v1.Secret { +func (e *Signer) listSecrets() []*v1.Secret { secrets, err := e.secretLister.Secrets(e.secretNamespace).List(labels.Everything()) if err != nil { utilruntime.HandleError(err) @@ -282,7 +281,7 @@ func (e *BootstrapSigner) listSecrets() []*v1.Secret { // getTokens returns a map of tokenID->tokenSecret. It ensures the token is // valid for signing. -func (e *BootstrapSigner) getTokens() map[string]string { +func (e *Signer) getTokens() map[string]string { ret := map[string]string{} secretObjs := e.listSecrets() for _, secret := range secretObjs { diff --git a/pkg/controller/bootstrap/bootstrapsigner_test.go b/pkg/controller/bootstrap/bootstrapsigner_test.go index ce3eda7c46b..99e46861a5b 100644 --- a/pkg/controller/bootstrap/bootstrapsigner_test.go +++ b/pkg/controller/bootstrap/bootstrapsigner_test.go @@ -39,13 +39,13 @@ func init() { const testTokenID = "abc123" -func newBootstrapSigner() (*BootstrapSigner, *fake.Clientset, coreinformers.SecretInformer, coreinformers.ConfigMapInformer, error) { - options := DefaultBootstrapSignerOptions() +func newSigner() (*Signer, *fake.Clientset, coreinformers.SecretInformer, coreinformers.ConfigMapInformer, error) { + options := DefaultSignerOptions() cl := fake.NewSimpleClientset() informers := informers.NewSharedInformerFactory(fake.NewSimpleClientset(), controller.NoResyncPeriodFunc()) secrets := informers.Core().V1().Secrets() configMaps := informers.Core().V1().ConfigMaps() - bsc, err := NewBootstrapSigner(cl, secrets, configMaps, options) + bsc, err := NewSigner(cl, secrets, configMaps, options) if err != nil { return nil, nil, nil, nil, err } @@ -70,18 +70,18 @@ func newConfigMap(tokenID, signature string) *v1.ConfigMap { } func TestNoConfigMap(t *testing.T) { - signer, cl, _, _, err := newBootstrapSigner() + signer, cl, _, _, err := newSigner() if err != nil { - t.Fatalf("error creating BootstrapSigner: %v", err) + t.Fatalf("error creating Signer: %v", err) } signer.signConfigMap() verifyActions(t, []core.Action{}, cl.Actions()) } func TestSimpleSign(t *testing.T) { - signer, cl, secrets, configMaps, err := newBootstrapSigner() + signer, cl, secrets, configMaps, err := newSigner() if err != nil { - t.Fatalf("error creating BootstrapSigner: %v", err) + t.Fatalf("error creating Signer: %v", err) } cm := newConfigMap("", "") @@ -103,9 +103,9 @@ func TestSimpleSign(t *testing.T) { } func TestNoSignNeeded(t *testing.T) { - signer, cl, secrets, configMaps, err := newBootstrapSigner() + signer, cl, secrets, configMaps, err := newSigner() if err != nil { - t.Fatalf("error creating BootstrapSigner: %v", err) + t.Fatalf("error creating Signer: %v", err) } cm := newConfigMap(testTokenID, "eyJhbGciOiJIUzI1NiIsImtpZCI6ImFiYzEyMyJ9..QSxpUG7Q542CirTI2ECPSZjvBOJURUW5a7XqFpNI958") @@ -121,9 +121,9 @@ func TestNoSignNeeded(t *testing.T) { } func TestUpdateSignature(t *testing.T) { - signer, cl, secrets, configMaps, err := newBootstrapSigner() + signer, cl, secrets, configMaps, err := newSigner() if err != nil { - t.Fatalf("error creating BootstrapSigner: %v", err) + t.Fatalf("error creating Signer: %v", err) } cm := newConfigMap(testTokenID, "old signature") @@ -145,9 +145,9 @@ func TestUpdateSignature(t *testing.T) { } func TestRemoveSignature(t *testing.T) { - signer, cl, _, configMaps, err := newBootstrapSigner() + signer, cl, _, configMaps, err := newSigner() if err != nil { - t.Fatalf("error creating BootstrapSigner: %v", err) + t.Fatalf("error creating Signer: %v", err) } cm := newConfigMap(testTokenID, "old signature")