Skip to content

Commit 2086f81

Browse files
authored
Merge pull request kubernetes#74678 from pmcalpine/lint-bs_cj
Fix some golint failures for pkg/controller
2 parents 531dbd4 + ac88e13 commit 2086f81

File tree

11 files changed

+49
-49
lines changed

11 files changed

+49
-49
lines changed

cmd/kube-controller-manager/app/batch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func startCronJobController(ctx ControllerContext) (http.Handler, bool, error) {
4646
if !ctx.AvailableResources[schema.GroupVersionResource{Group: "batch", Version: "v1beta1", Resource: "cronjobs"}] {
4747
return nil, false, nil
4848
}
49-
cjc, err := cronjob.NewCronJobController(
49+
cjc, err := cronjob.NewController(
5050
ctx.ClientBuilder.ClientOrDie("cronjob-controller"),
5151
)
5252
if err != nil {

cmd/kube-controller-manager/app/bootstrap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ import (
2525
)
2626

2727
func startBootstrapSignerController(ctx ControllerContext) (http.Handler, bool, error) {
28-
bsc, err := bootstrap.NewBootstrapSigner(
28+
bsc, err := bootstrap.NewSigner(
2929
ctx.ClientBuilder.ClientOrDie("bootstrap-signer"),
3030
ctx.InformerFactory.Core().V1().Secrets(),
3131
ctx.InformerFactory.Core().V1().ConfigMaps(),
32-
bootstrap.DefaultBootstrapSignerOptions(),
32+
bootstrap.DefaultSignerOptions(),
3333
)
3434
if err != nil {
3535
return nil, true, fmt.Errorf("error creating BootstrapSigner controller: %v", err)

hack/.golint_failures

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,12 @@ pkg/cloudprovider/providers/photon
7373
pkg/cloudprovider/providers/vsphere
7474
pkg/controller
7575
pkg/controller/apis/config/v1alpha1
76-
pkg/controller/bootstrap
7776
pkg/controller/certificates
7877
pkg/controller/certificates/approver
7978
pkg/controller/certificates/signer
8079
pkg/controller/certificates/signer/config/v1alpha1
8180
pkg/controller/cloud
8281
pkg/controller/clusterroleaggregation
83-
pkg/controller/cronjob
8482
pkg/controller/daemon
8583
pkg/controller/daemon/config/v1alpha1
8684
pkg/controller/deployment

pkg/controller/bootstrap/bootstrapsigner.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import (
3939
"k8s.io/kubernetes/pkg/util/metrics"
4040
)
4141

42-
// BootstrapSignerOptions contains options for the BootstrapSigner
43-
type BootstrapSignerOptions struct {
42+
// SignerOptions contains options for the Signer
43+
type SignerOptions struct {
4444
// ConfigMapNamespace is the namespace of the ConfigMap
4545
ConfigMapNamespace string
4646

@@ -59,18 +59,17 @@ type BootstrapSignerOptions struct {
5959
SecretResync time.Duration
6060
}
6161

62-
// DefaultBootstrapSignerOptions returns a set of default options for creating a
63-
// BootstrapSigner
64-
func DefaultBootstrapSignerOptions() BootstrapSignerOptions {
65-
return BootstrapSignerOptions{
62+
// DefaultSignerOptions returns a set of default options for creating a Signer.
63+
func DefaultSignerOptions() SignerOptions {
64+
return SignerOptions{
6665
ConfigMapNamespace: api.NamespacePublic,
6766
ConfigMapName: bootstrapapi.ConfigMapClusterInfo,
6867
TokenSecretNamespace: api.NamespaceSystem,
6968
}
7069
}
7170

72-
// BootstrapSigner is a controller that signs a ConfigMap with a set of tokens.
73-
type BootstrapSigner struct {
71+
// Signer is a controller that signs a ConfigMap with a set of tokens.
72+
type Signer struct {
7473
client clientset.Interface
7574
configMapKey string
7675
configMapName string
@@ -90,9 +89,9 @@ type BootstrapSigner struct {
9089
configMapSynced cache.InformerSynced
9190
}
9291

93-
// NewBootstrapSigner returns a new *BootstrapSigner.
94-
func NewBootstrapSigner(cl clientset.Interface, secrets informers.SecretInformer, configMaps informers.ConfigMapInformer, options BootstrapSignerOptions) (*BootstrapSigner, error) {
95-
e := &BootstrapSigner{
92+
// NewSigner returns a new *Signer.
93+
func NewSigner(cl clientset.Interface, secrets informers.SecretInformer, configMaps informers.ConfigMapInformer, options SignerOptions) (*Signer, error) {
94+
e := &Signer{
9695
client: cl,
9796
configMapKey: options.ConfigMapNamespace + "/" + options.ConfigMapName,
9897
configMapName: options.ConfigMapName,
@@ -153,7 +152,7 @@ func NewBootstrapSigner(cl clientset.Interface, secrets informers.SecretInformer
153152
}
154153

155154
// Run runs controller loops and returns when they are done
156-
func (e *BootstrapSigner) Run(stopCh <-chan struct{}) {
155+
func (e *Signer) Run(stopCh <-chan struct{}) {
157156
// Shut down queues
158157
defer utilruntime.HandleCrash()
159158
defer e.syncQueue.ShutDown()
@@ -168,11 +167,11 @@ func (e *BootstrapSigner) Run(stopCh <-chan struct{}) {
168167
klog.V(1).Infof("Shutting down")
169168
}
170169

171-
func (e *BootstrapSigner) pokeConfigMapSync() {
170+
func (e *Signer) pokeConfigMapSync() {
172171
e.syncQueue.Add(e.configMapKey)
173172
}
174173

175-
func (e *BootstrapSigner) serviceConfigMapQueue() {
174+
func (e *Signer) serviceConfigMapQueue() {
176175
key, quit := e.syncQueue.Get()
177176
if quit {
178177
return
@@ -184,7 +183,7 @@ func (e *BootstrapSigner) serviceConfigMapQueue() {
184183

185184
// signConfigMap computes the signatures on our latest cached objects and writes
186185
// back if necessary.
187-
func (e *BootstrapSigner) signConfigMap() {
186+
func (e *Signer) signConfigMap() {
188187
origCM := e.getConfigMap()
189188

190189
if origCM == nil {
@@ -241,15 +240,15 @@ func (e *BootstrapSigner) signConfigMap() {
241240
}
242241
}
243242

244-
func (e *BootstrapSigner) updateConfigMap(cm *v1.ConfigMap) {
243+
func (e *Signer) updateConfigMap(cm *v1.ConfigMap) {
245244
_, err := e.client.CoreV1().ConfigMaps(cm.Namespace).Update(cm)
246245
if err != nil && !apierrors.IsConflict(err) && !apierrors.IsNotFound(err) {
247246
klog.V(3).Infof("Error updating ConfigMap: %v", err)
248247
}
249248
}
250249

251250
// getConfigMap gets the ConfigMap we are interested in
252-
func (e *BootstrapSigner) getConfigMap() *v1.ConfigMap {
251+
func (e *Signer) getConfigMap() *v1.ConfigMap {
253252
configMap, err := e.configMapLister.ConfigMaps(e.configMapNamespace).Get(e.configMapName)
254253

255254
// If we can't get the configmap just return nil. The resync will eventually
@@ -264,7 +263,7 @@ func (e *BootstrapSigner) getConfigMap() *v1.ConfigMap {
264263
return configMap
265264
}
266265

267-
func (e *BootstrapSigner) listSecrets() []*v1.Secret {
266+
func (e *Signer) listSecrets() []*v1.Secret {
268267
secrets, err := e.secretLister.Secrets(e.secretNamespace).List(labels.Everything())
269268
if err != nil {
270269
utilruntime.HandleError(err)
@@ -282,7 +281,7 @@ func (e *BootstrapSigner) listSecrets() []*v1.Secret {
282281

283282
// getTokens returns a map of tokenID->tokenSecret. It ensures the token is
284283
// valid for signing.
285-
func (e *BootstrapSigner) getTokens() map[string]string {
284+
func (e *Signer) getTokens() map[string]string {
286285
ret := map[string]string{}
287286
secretObjs := e.listSecrets()
288287
for _, secret := range secretObjs {

pkg/controller/bootstrap/bootstrapsigner_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ func init() {
3939

4040
const testTokenID = "abc123"
4141

42-
func newBootstrapSigner() (*BootstrapSigner, *fake.Clientset, coreinformers.SecretInformer, coreinformers.ConfigMapInformer, error) {
43-
options := DefaultBootstrapSignerOptions()
42+
func newSigner() (*Signer, *fake.Clientset, coreinformers.SecretInformer, coreinformers.ConfigMapInformer, error) {
43+
options := DefaultSignerOptions()
4444
cl := fake.NewSimpleClientset()
4545
informers := informers.NewSharedInformerFactory(fake.NewSimpleClientset(), controller.NoResyncPeriodFunc())
4646
secrets := informers.Core().V1().Secrets()
4747
configMaps := informers.Core().V1().ConfigMaps()
48-
bsc, err := NewBootstrapSigner(cl, secrets, configMaps, options)
48+
bsc, err := NewSigner(cl, secrets, configMaps, options)
4949
if err != nil {
5050
return nil, nil, nil, nil, err
5151
}
@@ -70,18 +70,18 @@ func newConfigMap(tokenID, signature string) *v1.ConfigMap {
7070
}
7171

7272
func TestNoConfigMap(t *testing.T) {
73-
signer, cl, _, _, err := newBootstrapSigner()
73+
signer, cl, _, _, err := newSigner()
7474
if err != nil {
75-
t.Fatalf("error creating BootstrapSigner: %v", err)
75+
t.Fatalf("error creating Signer: %v", err)
7676
}
7777
signer.signConfigMap()
7878
verifyActions(t, []core.Action{}, cl.Actions())
7979
}
8080

8181
func TestSimpleSign(t *testing.T) {
82-
signer, cl, secrets, configMaps, err := newBootstrapSigner()
82+
signer, cl, secrets, configMaps, err := newSigner()
8383
if err != nil {
84-
t.Fatalf("error creating BootstrapSigner: %v", err)
84+
t.Fatalf("error creating Signer: %v", err)
8585
}
8686

8787
cm := newConfigMap("", "")
@@ -103,9 +103,9 @@ func TestSimpleSign(t *testing.T) {
103103
}
104104

105105
func TestNoSignNeeded(t *testing.T) {
106-
signer, cl, secrets, configMaps, err := newBootstrapSigner()
106+
signer, cl, secrets, configMaps, err := newSigner()
107107
if err != nil {
108-
t.Fatalf("error creating BootstrapSigner: %v", err)
108+
t.Fatalf("error creating Signer: %v", err)
109109
}
110110

111111
cm := newConfigMap(testTokenID, "eyJhbGciOiJIUzI1NiIsImtpZCI6ImFiYzEyMyJ9..QSxpUG7Q542CirTI2ECPSZjvBOJURUW5a7XqFpNI958")
@@ -121,9 +121,9 @@ func TestNoSignNeeded(t *testing.T) {
121121
}
122122

123123
func TestUpdateSignature(t *testing.T) {
124-
signer, cl, secrets, configMaps, err := newBootstrapSigner()
124+
signer, cl, secrets, configMaps, err := newSigner()
125125
if err != nil {
126-
t.Fatalf("error creating BootstrapSigner: %v", err)
126+
t.Fatalf("error creating Signer: %v", err)
127127
}
128128

129129
cm := newConfigMap(testTokenID, "old signature")
@@ -145,9 +145,9 @@ func TestUpdateSignature(t *testing.T) {
145145
}
146146

147147
func TestRemoveSignature(t *testing.T) {
148-
signer, cl, _, configMaps, err := newBootstrapSigner()
148+
signer, cl, _, configMaps, err := newSigner()
149149
if err != nil {
150-
t.Fatalf("error creating BootstrapSigner: %v", err)
150+
t.Fatalf("error creating Signer: %v", err)
151151
}
152152

153153
cm := newConfigMap(testTokenID, "old signature")

pkg/controller/cronjob/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ load(
99
go_library(
1010
name = "go_default_library",
1111
srcs = [
12-
"cronjob_controller.go",
12+
"controller.go",
1313
"doc.go",
1414
"injection.go",
1515
"utils.go",
@@ -41,7 +41,7 @@ go_library(
4141
go_test(
4242
name = "go_default_test",
4343
srcs = [
44-
"cronjob_controller_test.go",
44+
"controller_test.go",
4545
"utils_test.go",
4646
],
4747
embed = [":go_default_library"],

pkg/controller/cronjob/cronjob_controller.go renamed to pkg/controller/cronjob/controller.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ import (
5858
// controllerKind contains the schema.GroupVersionKind for this controller type.
5959
var controllerKind = batchv1beta1.SchemeGroupVersion.WithKind("CronJob")
6060

61-
type CronJobController struct {
61+
// Controller is a controller for CronJobs.
62+
type Controller struct {
6263
kubeClient clientset.Interface
6364
jobControl jobControlInterface
6465
sjControl sjControlInterface
6566
podControl podControlInterface
6667
recorder record.EventRecorder
6768
}
6869

69-
func NewCronJobController(kubeClient clientset.Interface) (*CronJobController, error) {
70+
// NewController creates and initializes a new Controller.
71+
func NewController(kubeClient clientset.Interface) (*Controller, error) {
7072
eventBroadcaster := record.NewBroadcaster()
7173
eventBroadcaster.StartLogging(klog.Infof)
7274
eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")})
@@ -77,7 +79,7 @@ func NewCronJobController(kubeClient clientset.Interface) (*CronJobController, e
7779
}
7880
}
7981

80-
jm := &CronJobController{
82+
jm := &Controller{
8183
kubeClient: kubeClient,
8284
jobControl: realJobControl{KubeClient: kubeClient},
8385
sjControl: &realSJControl{KubeClient: kubeClient},
@@ -88,8 +90,8 @@ func NewCronJobController(kubeClient clientset.Interface) (*CronJobController, e
8890
return jm, nil
8991
}
9092

91-
// Run the main goroutine responsible for watching and syncing jobs.
92-
func (jm *CronJobController) Run(stopCh <-chan struct{}) {
93+
// Run starts the main goroutine responsible for watching and syncing jobs.
94+
func (jm *Controller) Run(stopCh <-chan struct{}) {
9395
defer utilruntime.HandleCrash()
9496
klog.Infof("Starting CronJob Manager")
9597
// Check things every 10 second.
@@ -99,7 +101,7 @@ func (jm *CronJobController) Run(stopCh <-chan struct{}) {
99101
}
100102

101103
// syncAll lists all the CronJobs and Jobs and reconciles them.
102-
func (jm *CronJobController) syncAll() {
104+
func (jm *Controller) syncAll() {
103105
// List children (Jobs) before parents (CronJob).
104106
// This guarantees that if we see any Job that got orphaned by the GC orphan finalizer,
105107
// we must also see that the parent CronJob has non-nil DeletionTimestamp (see #42639).
File renamed without changes.

pkg/controller/cronjob/utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func getRecentUnmetScheduleTimes(sj batchv1beta1.CronJob, now time.Time) ([]time
142142
// but less than "lots".
143143
if len(starts) > 100 {
144144
// We can't get the most recent times so just return an empty slice
145-
return []time.Time{}, fmt.Errorf("Too many missed start time (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.")
145+
return []time.Time{}, fmt.Errorf("too many missed start time (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew")
146146
}
147147
}
148148
return starts, nil
@@ -183,6 +183,7 @@ func getFinishedStatus(j *batchv1.Job) (bool, batchv1.JobConditionType) {
183183
return false, ""
184184
}
185185

186+
// IsJobFinished returns whether or not a job has completed successfully or failed.
186187
func IsJobFinished(j *batchv1.Job) bool {
187188
isFinished, _ := getFinishedStatus(j)
188189
return isFinished

pkg/controller/cronjob/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestGetJobFromTemplate(t *testing.T) {
3535
// and other fields, and add a created-by reference.
3636

3737
var one int64 = 1
38-
var no bool = false
38+
var no bool
3939

4040
sj := batchv1beta1.CronJob{
4141
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)