Skip to content

Commit 8647eec

Browse files
authored
Merge pull request kubernetes#95113 from Git-Jiro/lint_ttlcontroller
Lint ttl_controller
2 parents 9891ac4 + 600d621 commit 8647eec

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

hack/.golint_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ pkg/controller/resourcequota/config/v1alpha1
7878
pkg/controller/serviceaccount/config/v1alpha1
7979
pkg/controller/statefulset
8080
pkg/controller/statefulset/config/v1alpha1
81-
pkg/controller/ttl
8281
pkg/controller/ttlafterfinished/config/v1alpha1
8382
pkg/controller/volume/attachdetach
8483
pkg/controller/volume/attachdetach/config/v1alpha1

pkg/controller/ttl/ttl_controller.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ import (
5252
"k8s.io/klog/v2"
5353
)
5454

55-
type TTLController struct {
55+
// Controller sets ttl annotations on nodes, based on cluster size.
56+
type Controller struct {
5657
kubeClient clientset.Interface
5758

5859
// nodeStore is a local cache of nodes.
@@ -76,8 +77,9 @@ type TTLController struct {
7677
boundaryStep int
7778
}
7879

79-
func NewTTLController(nodeInformer informers.NodeInformer, kubeClient clientset.Interface) *TTLController {
80-
ttlc := &TTLController{
80+
// NewTTLController creates a new TTLController
81+
func NewTTLController(nodeInformer informers.NodeInformer, kubeClient clientset.Interface) *Controller {
82+
ttlc := &Controller{
8183
kubeClient: kubeClient,
8284
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "ttlcontroller"),
8385
}
@@ -111,7 +113,8 @@ var (
111113
}
112114
)
113115

114-
func (ttlc *TTLController) Run(workers int, stopCh <-chan struct{}) {
116+
// Run begins watching and syncing.
117+
func (ttlc *Controller) Run(workers int, stopCh <-chan struct{}) {
115118
defer utilruntime.HandleCrash()
116119
defer ttlc.queue.ShutDown()
117120

@@ -129,7 +132,7 @@ func (ttlc *TTLController) Run(workers int, stopCh <-chan struct{}) {
129132
<-stopCh
130133
}
131134

132-
func (ttlc *TTLController) addNode(obj interface{}) {
135+
func (ttlc *Controller) addNode(obj interface{}) {
133136
node, ok := obj.(*v1.Node)
134137
if !ok {
135138
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj))
@@ -148,7 +151,7 @@ func (ttlc *TTLController) addNode(obj interface{}) {
148151
ttlc.enqueueNode(node)
149152
}
150153

151-
func (ttlc *TTLController) updateNode(_, newObj interface{}) {
154+
func (ttlc *Controller) updateNode(_, newObj interface{}) {
152155
node, ok := newObj.(*v1.Node)
153156
if !ok {
154157
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", newObj))
@@ -162,7 +165,7 @@ func (ttlc *TTLController) updateNode(_, newObj interface{}) {
162165
ttlc.enqueueNode(node)
163166
}
164167

165-
func (ttlc *TTLController) deleteNode(obj interface{}) {
168+
func (ttlc *Controller) deleteNode(obj interface{}) {
166169
_, ok := obj.(*v1.Node)
167170
if !ok {
168171
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
@@ -189,7 +192,7 @@ func (ttlc *TTLController) deleteNode(obj interface{}) {
189192
// We are not processing the node, as it no longer exists.
190193
}
191194

192-
func (ttlc *TTLController) enqueueNode(node *v1.Node) {
195+
func (ttlc *Controller) enqueueNode(node *v1.Node) {
193196
key, err := controller.KeyFunc(node)
194197
if err != nil {
195198
klog.Errorf("Couldn't get key for object %+v", node)
@@ -198,12 +201,12 @@ func (ttlc *TTLController) enqueueNode(node *v1.Node) {
198201
ttlc.queue.Add(key)
199202
}
200203

201-
func (ttlc *TTLController) worker() {
204+
func (ttlc *Controller) worker() {
202205
for ttlc.processItem() {
203206
}
204207
}
205208

206-
func (ttlc *TTLController) processItem() bool {
209+
func (ttlc *Controller) processItem() bool {
207210
key, quit := ttlc.queue.Get()
208211
if quit {
209212
return false
@@ -221,7 +224,7 @@ func (ttlc *TTLController) processItem() bool {
221224
return true
222225
}
223226

224-
func (ttlc *TTLController) getDesiredTTLSeconds() int {
227+
func (ttlc *Controller) getDesiredTTLSeconds() int {
225228
ttlc.lock.RLock()
226229
defer ttlc.lock.RUnlock()
227230
return ttlc.desiredTTLSeconds
@@ -251,7 +254,7 @@ func setIntAnnotation(node *v1.Node, annotationKey string, value int) {
251254
node.Annotations[annotationKey] = strconv.Itoa(value)
252255
}
253256

254-
func (ttlc *TTLController) patchNodeWithAnnotation(node *v1.Node, annotationKey string, value int) error {
257+
func (ttlc *Controller) patchNodeWithAnnotation(node *v1.Node, annotationKey string, value int) error {
255258
oldData, err := json.Marshal(node)
256259
if err != nil {
257260
return err
@@ -274,7 +277,7 @@ func (ttlc *TTLController) patchNodeWithAnnotation(node *v1.Node, annotationKey
274277
return nil
275278
}
276279

277-
func (ttlc *TTLController) updateNodeIfNeeded(key string) error {
280+
func (ttlc *Controller) updateNodeIfNeeded(key string) error {
278281
node, err := ttlc.nodeStore.Get(key)
279282
if err != nil {
280283
if apierrors.IsNotFound(err) {

pkg/controller/ttl/ttl_controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestPatchNode(t *testing.T) {
7575

7676
for i, testCase := range testCases {
7777
fakeClient := &fake.Clientset{}
78-
ttlController := &TTLController{
78+
ttlController := &Controller{
7979
kubeClient: fakeClient,
8080
}
8181
err := ttlController.patchNodeWithAnnotation(testCase.node, v1.ObjectTTLAnnotationKey, testCase.ttlSeconds)
@@ -132,7 +132,7 @@ func TestUpdateNodeIfNeeded(t *testing.T) {
132132
fakeClient := &fake.Clientset{}
133133
nodeStore := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{})
134134
nodeStore.Add(testCase.node)
135-
ttlController := &TTLController{
135+
ttlController := &Controller{
136136
kubeClient: fakeClient,
137137
nodeStore: listers.NewNodeLister(nodeStore),
138138
desiredTTLSeconds: testCase.desiredTTL,
@@ -213,7 +213,7 @@ func TestDesiredTTL(t *testing.T) {
213213
}
214214

215215
for i, testCase := range testCases {
216-
ttlController := &TTLController{
216+
ttlController := &Controller{
217217
queue: workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()),
218218
nodeCount: testCase.nodeCount,
219219
desiredTTLSeconds: testCase.desiredTTL,

0 commit comments

Comments
 (0)