Skip to content

Commit eb213a8

Browse files
authored
Merge pull request #61 from kinvolk/invidian/more-fixes
Updates and improvements
2 parents bdf79b8 + 5a98440 commit eb213a8

File tree

6 files changed

+34
-14
lines changed

6 files changed

+34
-14
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
lint:
2828
name: Lint
2929
runs-on: ubuntu-latest
30-
container: golangci/golangci-lint:v1.32.2
30+
container: golangci/golangci-lint:v1.35.2
3131
timeout-minutes: 10
3232
steps:
3333

.golangci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ issues:
2222
- linters:
2323
- lll
2424
source: "http(s)://"
25+
# Allow use of fmt.Print* functions.
26+
- linters:
27+
- forbidigo
28+
text: "use of `fmt.Printf` forbidden by pattern"
29+
- linters:
30+
- forbidigo
31+
text: "use of `fmt.Println` forbidden by pattern"
2532

2633
linters-settings:
2734
exhaustive:
@@ -42,6 +49,7 @@ linters:
4249
- errorlint
4350
- exhaustive
4451
- exportloopref
52+
- forbidigo
4553
- funlen
4654
- gochecknoinits
4755
- gocognit
@@ -60,19 +68,23 @@ linters:
6068
- ineffassign
6169
- interfacer
6270
- lll
71+
- makezero
6372
- misspell
6473
- nakedret
6574
- nestif
6675
- nlreturn
6776
- noctx
6877
- nolintlint
78+
- paralleltest
6979
- prealloc
80+
- predeclared
7081
- rowserrcheck
7182
- scopelint
7283
- sqlclosecheck
7384
- structcheck
7485
- stylecheck
7586
- testpackage
87+
- thelper
7688
- tparallel
7789
- typecheck
7890
- unconvert
@@ -82,9 +94,15 @@ linters:
8294
- wrapcheck
8395
- wsl
8496
disable:
97+
# We use different import grouping style than gci forces.
8598
- gci
99+
# We still have many globals to get rid of.
86100
- gochecknoglobals
101+
# TODOs in the code are OK.
87102
- godox
103+
# We do not have clearly defined error types yet.
88104
- goerr113
105+
# We do not require all used structs to have all fields initialized.
89106
- exhaustivestruct
107+
# We do not care about the memory efficiency really.
90108
- maligned

pkg/agent/agent.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ type Klocksmith struct {
3737
reapTimeout time.Duration
3838
}
3939

40-
const defaultPollInterval = 10 * time.Second
40+
const (
41+
defaultPollInterval = 10 * time.Second
42+
maxOperatorResponseTime = 24 * time.Hour
43+
)
4144

4245
var shouldRebootSelector = fields.Set(map[string]string{
4346
constants.AnnotationOkToReboot: constants.True,
@@ -354,7 +357,7 @@ func (k *Klocksmith) waitForOkToReboot() error {
354357

355358
// Hopefully 24 hours is enough time between indicating we need a
356359
// reboot and the controller telling us to do it.
357-
ctx, _ := watchtools.ContextWithOptionalTimeout(context.Background(), time.Hour*24)
360+
ctx, _ := watchtools.ContextWithOptionalTimeout(context.Background(), maxOperatorResponseTime)
358361

359362
ev, err := watchtools.UntilWithoutRetry(ctx, watcher, k8sutil.NodeAnnotationCondition(shouldRebootSelector))
360363
if err != nil {
@@ -400,7 +403,7 @@ func (k *Klocksmith) waitForNotOkToReboot() error {
400403
// true' vs '== False'; due to the operator matching on '== True', and not
401404
// going out of its way to convert '' => 'False', checking the exact inverse
402405
// of what the operator checks is the correct thing to do.
403-
ctx, _ := watchtools.ContextWithOptionalTimeout(context.Background(), time.Hour*24)
406+
ctx, _ := watchtools.ContextWithOptionalTimeout(context.Background(), maxOperatorResponseTime)
404407

405408
ev, err := watchtools.UntilWithoutRetry(ctx, watcher, watchtools.ConditionFunc(func(event watch.Event) (bool, error) {
406409
switch event.Type {

pkg/k8sutil/metadata_internal_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
)
77

88
func Test_slitNewlineEnv_retain_map_values_when_given_empty_input(t *testing.T) {
9+
t.Parallel()
10+
911
expected := map[string]string{"foo": "bar"}
1012

1113
input := map[string]string{}

pkg/k8sutil/metadata_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func atomicCounterIncrement(n *corev1.Node) {
3636
}
3737

3838
func TestUpdateNodeRetryHandlesConflict(t *testing.T) {
39+
t.Parallel()
40+
3941
ctrl := gomock.NewController(t)
4042
defer ctrl.Finish()
4143
mockNi := mock_v1.NewMockNodeInterface(ctrl)

pkg/operator/operator.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ func (k *Kontroller) process() {
276276
// fix them.
277277
klog.V(4).Info("Cleaning up node state")
278278

279-
err := k.cleanupState()
280-
if err != nil {
279+
if err := k.cleanupState(); err != nil {
281280
klog.Errorf("Failed to cleanup node state: %v", err)
282281

283282
return
@@ -289,8 +288,7 @@ func (k *Kontroller) process() {
289288
// the reboot has completed.
290289
klog.V(4).Info("Checking if configured after-reboot annotations are set to true")
291290

292-
err = k.checkAfterReboot()
293-
if err != nil {
291+
if err := k.checkAfterReboot(); err != nil {
294292
klog.Errorf("Failed to check after reboot: %v", err)
295293

296294
return
@@ -300,8 +298,7 @@ func (k *Kontroller) process() {
300298
// remove after-reboot annotations and add the after-reboot=true label.
301299
klog.V(4).Info("Labeling rebooted nodes with after-reboot label")
302300

303-
err = k.markAfterReboot()
304-
if err != nil {
301+
if err := k.markAfterReboot(); err != nil {
305302
klog.Errorf("Failed to update recently rebooted nodes: %v", err)
306303

307304
return
@@ -313,8 +310,7 @@ func (k *Kontroller) process() {
313310
// time to reboot.
314311
klog.V(4).Info("Checking if configured before-reboot annotations are set to true")
315312

316-
err = k.checkBeforeReboot()
317-
if err != nil {
313+
if err := k.checkBeforeReboot(); err != nil {
318314
klog.Errorf("Failed to check before reboot: %v", err)
319315

320316
return
@@ -324,8 +320,7 @@ func (k *Kontroller) process() {
324320
// annotations and add the before-reboot=true label.
325321
klog.V(4).Info("Labeling rebootable nodes with before-reboot label")
326322

327-
err = k.markBeforeReboot()
328-
if err != nil {
323+
if err := k.markBeforeReboot(); err != nil {
329324
klog.Errorf("Failed to update rebootable nodes: %v", err)
330325

331326
return

0 commit comments

Comments
 (0)