Skip to content

Commit 169a9a8

Browse files
author
Evsyukov Denis
authored
[addon-operator] tests: added ListReleases to LibClient for testing (#602)
* tests: added ListReleases to LibClient for testing Signed-off-by: Evsyukov Denis <denis.evsyukov@flant.com>
1 parent 0942f85 commit 169a9a8

File tree

9 files changed

+252
-118
lines changed

9 files changed

+252
-118
lines changed

.github/workflows/lint.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ jobs:
3838
3939
- name: Run golangci-lint
4040
run: |
41-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b . v1.61.0
42-
./golangci-lint run --sort-results
41+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b . v2.1.6
42+
./golangci-lint run
4343
4444
codespell:
4545
name: Run codespell

.golangci.yaml

Lines changed: 100 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,121 @@
1-
run:
2-
timeout: 15m
1+
version: "2"
2+
run:
3+
timeout: 15m
4+
35
linters:
4-
disable-all: true
6+
default: none
57
enable:
6-
- asciicheck
7-
- bodyclose
8-
- copyloopvar
9-
- depguard
10-
- dogsled
11-
- durationcheck
12-
- gci
13-
- gochecknoinits
14-
- gocritic
15-
- gofmt
16-
- gofumpt
17-
- goimports
18-
- goprintffuncname
19-
- gosimple
20-
- govet
21-
- ineffassign
22-
- misspell
23-
- nolintlint
24-
- nonamedreturns
25-
- prealloc
26-
- revive
27-
- sloglint
28-
- staticcheck
29-
- stylecheck
30-
- unconvert
31-
- unused
32-
- whitespace
33-
linters-settings:
34-
gci:
35-
sections:
36-
- standard
37-
- default
38-
- prefix(github.com/flant/)
39-
goimports:
40-
local-prefixes: github.com/flant/
41-
sloglint:
42-
# Enforce not mixing key-value pairs and attributes.
8+
- asciicheck
9+
- bodyclose
10+
- copyloopvar
11+
- depguard
12+
- dogsled
13+
- durationcheck
14+
- gochecknoinits
15+
- gocritic
16+
- goprintffuncname
17+
- govet
18+
- ineffassign
19+
- misspell
20+
- nolintlint
21+
- nonamedreturns
22+
- prealloc
23+
- revive
24+
- sloglint
25+
- staticcheck
26+
- unconvert
27+
- unused
28+
- whitespace
29+
settings:
30+
depguard:
31+
rules:
32+
Main:
33+
files:
34+
- $all
35+
deny:
36+
- pkg: github.com/evanphx/json-patch
37+
desc: The 'github.com/evanphx/json-patch' package is superseded. Use pkg/utils/jsonpatch.go instead.
38+
- pkg: gopkg.in/satori/go.uuid.v1
39+
desc: Use https://github.com/gofrs/uuid instead. Satori/go.uuid is no longer maintained and has critical vulnerabilities.
40+
nonamedreturns:
41+
report-error-in-defer: false
42+
sloglint:
4343
no-mixed-args: true
44-
# Enforce using key-value pairs only (overrides no-mixed-args, incompatible with attr-only).
4544
kv-only: false
46-
# Enforce using attributes only (overrides no-mixed-args, incompatible with kv-only).
4745
attr-only: false
48-
# Enforce not using global loggers.
4946
no-global: ""
50-
# Enforce using methods that accept a context.
5147
context: ""
52-
# Enforce using static values for log messages.
5348
static-msg: false
54-
# Enforce using constants instead of raw keys.
5549
no-raw-keys: false
56-
# Enforce a single key naming convention.
57-
key-naming-case: ""
58-
# Enforce not using specific keys.
5950
forbidden-keys:
6051
- level
6152
- msg
6253
- logger
6354
- source
6455
- stacktrace
6556
- time
66-
# Enforce putting arguments on separate lines.
6757
args-on-sep-lines: false
68-
depguard:
58+
staticcheck:
59+
checks:
60+
- all
61+
- '-QF1008' # not need to fix; we understand how to call nested structs
62+
exclusions:
63+
generated: lax
64+
presets:
65+
- comments
66+
- common-false-positives
67+
- legacy
68+
- std-error-handling
6969
rules:
70-
Main:
71-
files:
72-
- $all
73-
deny:
74-
- pkg: "github.com/evanphx/json-patch"
75-
desc: "The 'github.com/evanphx/json-patch' package is superseded. Use pkg/utils/jsonpatch.go instead."
76-
- pkg: "gopkg.in/satori/go.uuid.v1"
77-
desc: "Use https://github.com/gofrs/uuid instead. Satori/go.uuid is no longer maintained and has critical vulnerabilities."
78-
nonamedreturns:
79-
# Report named error if it is assigned inside defer.
80-
# Default: false
81-
report-error-in-defer: false
70+
- path: (.+)\.go$
71+
text: 'var-naming: don''t use an underscore in package name'
72+
- path: (.+)\.go$
73+
text: 'ST1003: should not use underscores in package names'
74+
- path: (.+)\.go$
75+
text: 'ST1005: error strings should not be capitalized'
76+
- path: (.+)\.go$
77+
text: 'error-strings: error strings should not be capitalized or end with punctuation or a newline'
78+
- path: (.+)\.go$
79+
text: 'ST1005: error strings should not end with punctuation or newlines'
80+
- path: (.+)\.go$
81+
text: 'dot-imports: should not use dot imports'
82+
- path: (.+)\.go$
83+
text: 'ST1001: should not use dot imports'
84+
- path: (.+)\.go$
85+
text: don't use `init` function
86+
- path: (.+)\.go$
87+
text: 'var-naming:'
88+
- path: (.+)\.go$
89+
text: 'ST1003: '
90+
- path: (.+)\.go$
91+
text: 'exported: type name will be used as'
92+
- path: (.+)\.go$
93+
text: 'unexported-return: exported func NewModuleManager'
94+
paths:
95+
- third_party$
96+
- builtin$
97+
- examples$
8298
issues:
83-
exclude:
84-
# Using underscores is a common practice, refactor in the future
85-
- "var-naming: don't use an underscore in package name" # revive
86-
- "ST1003: should not use underscores in package names" # stylecheck
87-
88-
# Sometime errors are used to propagate messages for end-users
89-
- "ST1005: error strings should not be capitalized" # stylecheck
90-
- "error-strings: error strings should not be capitalized or end with punctuation or a newline" # revive
91-
- "ST1005: error strings should not end with punctuation or newlines" # stylecheck
92-
93-
# Dot imports are used for types, consider refactoring
94-
- "dot-imports: should not use dot imports" # revive
95-
- "ST1001: should not use dot imports" # stylecheck
96-
97-
# Init functions are used for global variables' initialization, consider refactoring
98-
- "don't use `init` function"
99-
100-
# Suggests changing Json -> JSON. Figure out which style we want to follow.
101-
- "var-naming:" # revive
102-
- "ST1003: " # stylecheck
103-
104-
# Exported name should not start with the package name, e.g., helm3.Helm3Options.
105-
# However, this penetrates all the code and sometimes is used to avoid name collisions.
106-
# Nice to refactor, but not necessary.
107-
- "exported: type name will be used as" # revive
108-
109-
# Do not know why, but a complicated thing to refactor. Let it be for now.
110-
- "unexported-return: exported func NewModuleManager" # revive
11199
max-issues-per-linter: 0
112100
max-same-issues: 0
101+
formatters:
102+
enable:
103+
- gci
104+
- gofmt
105+
- gofumpt
106+
- goimports
107+
settings:
108+
gci:
109+
sections:
110+
- standard
111+
- default
112+
- prefix(github.com/flant/)
113+
goimports:
114+
local-prefixes:
115+
- github.com/flant/
116+
exclusions:
117+
generated: lax
118+
paths:
119+
- third_party$
120+
- builtin$
121+
- examples$

pkg/addon-operator/debug_server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (op *AddonOperator) RegisterDebugGraphRoutes(dbgSrv *debug.Server) {
8080
image, err := op.ModuleManager.GetGraphImage(req.Context())
8181
if err != nil {
8282
w.WriteHeader(http.StatusInternalServerError)
83-
_, _ = w.Write([]byte(fmt.Sprintf("couldn't get graph's image: %s", err)))
83+
_, _ = fmt.Fprintf(w, "couldn't get graph's image: %s", err)
8484
return
8585
}
8686

@@ -267,7 +267,7 @@ func (op *AddonOperator) RegisterDebugModuleRoutes(dbgSrv *debug.Server) {
267267
}
268268

269269
err = differ.Diff(obj, printer, false)
270-
if !(err != nil && apierrors.IsConflict(err)) {
270+
if err == nil || !apierrors.IsConflict(err) {
271271
break
272272
}
273273
}

pkg/addon-operator/handler_module_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (op *AddonOperator) StartModuleManagerEventHandler() {
164164
}
165165

166166
// Append ModuleRun tasks if ModuleRun is not queued already.
167-
if kubeConfigTask != nil && convergeTask == nil {
167+
if kubeConfigTask != nil {
168168
reloadTasks := op.CreateReloadModulesTasks(modulesToRerun, kubeConfigTask.GetLogLabels(), "KubeConfig-Changed-Modules")
169169
op.engine.TaskQueues.GetMain().AddFirst(kubeConfigTask)
170170
if len(reloadTasks) > 0 {

pkg/addon-operator/http_server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (op *AddonOperator) registerDefaultRoutes() {
102102

103103
// handleRootPage serves the main HTML page with links to all available endpoints
104104
func (op *AddonOperator) handleRootPage(writer http.ResponseWriter, _ *http.Request) {
105-
_, _ = writer.Write([]byte(fmt.Sprintf(`<html>
105+
_, _ = fmt.Fprintf(writer, `<html>
106106
<head><title>Addon-operator</title></head>
107107
<body>
108108
<h1>Addon-operator</h1>
@@ -115,7 +115,7 @@ func (op *AddonOperator) handleRootPage(writer http.ResponseWriter, _ *http.Requ
115115
<a href="/readyz">ready url</a>
116116
</p>
117117
</body>
118-
</html>`, app.ListenPort)))
118+
</html>`, app.ListenPort)
119119
}
120120

121121
// handleHealthCheck responds with 200 OK for health probes

pkg/addon-operator/queue_test.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,9 @@ func Test_RemoveAdjacentConvergeModules(t *testing.T) {
288288

289289
q := queue.NewTasksQueue().WithMetricStorage(metricStorage)
290290

291-
//nolint:govet
292-
for _, tsk := range tt.in {
293-
tmpTsk := tsk
294-
q.AddLast(&tmpTsk)
291+
for i := range tt.in {
292+
tsk := &tt.in[i]
293+
q.AddLast(tsk)
295294
}
296295
require.Equal(t, len(tt.in), q.Length(), "Should add all tasks to the queue.")
297296

@@ -532,14 +531,13 @@ func Test_RemoveCurrentConvergeTasks(t *testing.T) {
532531

533532
// Fill queue from the test case.
534533
queues = append(queues, q)
535-
//nolint:govet
536-
for _, tsk := range tasks {
537-
tmpTsk := tsk
534+
for i := range tasks {
535+
tmpTsk := &tasks[i]
538536
// Set metadata to prevent "possible bug" errors.
539537
if tmpTsk.Metadata == nil {
540538
tmpTsk.Metadata = task.HookMetadata{}
541539
}
542-
q.AddLast(&tmpTsk)
540+
q.AddLast(tmpTsk)
543541
}
544542
require.Equal(t, len(tasks), q.Length(), "Should add all tasks to the queue.")
545543
}
@@ -660,14 +658,13 @@ func Test_RemoveCurrentConvergeTasksFromId(t *testing.T) {
660658
q := queue.NewTasksQueue().WithMetricStorage(metricStorage)
661659

662660
// Fill queue from the test case.
663-
//nolint:govet
664-
for _, tsk := range tt.initialTasks {
665-
tmpTsk := tsk
661+
for i := range tt.initialTasks {
662+
tmpTsk := &tt.initialTasks[i]
666663
// Set metadata to prevent "possible bug" errors.
667664
if tmpTsk.Metadata == nil {
668665
tmpTsk.Metadata = task.HookMetadata{}
669666
}
670-
q.AddLast(&tmpTsk)
667+
q.AddLast(tmpTsk)
671668
}
672669
require.Equal(t, len(tt.initialTasks), q.Length(), "Should add all tasks to the queue.")
673670

pkg/helm/helm3lib/helm3lib.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,16 @@ func (h *LibClient) newDryRunInstAction(namespace, releaseName string) *action.I
526526

527527
return inst
528528
}
529+
530+
// ListReleases retrieves all Helm releases regardless of their state.
531+
func (h *LibClient) ListReleases() ([]*release.Release, error) {
532+
l := action.NewList(actionConfig)
533+
// list all releases regardless of their state
534+
l.StateMask = action.ListAll
535+
list, err := l.Run()
536+
if err != nil {
537+
return nil, fmt.Errorf("helm list failed: %w", err)
538+
}
539+
540+
return list, nil
541+
}

0 commit comments

Comments
 (0)