Skip to content

Commit 143b16e

Browse files
authored
Update integration test workflow and add golangci lint check (#2197)
* Update integration test workflow Signed-off-by: Yi Chen <[email protected]> * Update golangci lint config Signed-off-by: Yi Chen <[email protected]> --------- Signed-off-by: Yi Chen <[email protected]>
1 parent 1972fb7 commit 143b16e

File tree

21 files changed

+200
-121
lines changed

21 files changed

+200
-121
lines changed

.github/workflows/integration.yaml

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,71 @@ concurrency:
1616
cancel-in-progress: true
1717

1818
jobs:
19-
build-api-docs:
19+
code-check:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- name: Checkout source code
2323
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
2426

2527
- name: Set up Go
2628
uses: actions/setup-go@v5
2729
with:
2830
go-version-file: go.mod
2931

30-
- name: The API documentation hasn't changed
32+
- name: Run go mod tidy
3133
run: |
32-
make build-api-docs
33-
if ! git diff --quiet -- docs/api-docs.md; then
34-
echo "Need to re-run 'make build-api-docs' and commit the changes"
35-
git diff -- docs/api-docs.md;
34+
go mod tidy
35+
if ! git diff --quiet; then
36+
echo "Please run 'go mod tidy' and commit the changes."
37+
git diff
3638
false
3739
fi
3840
39-
build-sparkctl:
41+
- name: Run go fmt check
42+
run: |
43+
make go-fmt
44+
if ! git diff --quiet; then
45+
echo "Need to re-run 'make go-fmt' and commit the changes."
46+
git diff
47+
false
48+
fi
49+
50+
- name: Run go vet check
51+
run: |
52+
make go-vet
53+
if ! git diff --quiet; then
54+
echo "Need to re-run 'make go-vet' and commit the changes."
55+
git diff
56+
false
57+
fi
58+
59+
- name: Run golangci-lint
60+
run: |
61+
make go-lint
62+
63+
build-api-docs:
4064
runs-on: ubuntu-latest
4165
steps:
4266
- name: Checkout source code
4367
uses: actions/checkout@v4
68+
with:
69+
fetch-depth: 0
4470

4571
- name: Set up Go
4672
uses: actions/setup-go@v5
4773
with:
4874
go-version-file: go.mod
4975

50-
- name: build sparkctl
51-
run: make build-sparkctl
76+
- name: Build API docs
77+
run: |
78+
make build-api-docs
79+
if ! git diff --quiet; then
80+
echo "Need to re-run 'make build-api-docs' and commit the changes."
81+
git diff
82+
false
83+
fi
5284
5385
build-spark-operator:
5486
runs-on: ubuntu-latest
@@ -63,18 +95,28 @@ jobs:
6395
with:
6496
go-version-file: go.mod
6597

66-
- name: Run go fmt check
67-
run: make go-fmt
68-
69-
- name: Run go vet check
70-
run: make go-vet
71-
72-
- name: Run unit tests
98+
- name: Run go unit tests
7399
run: make unit-test
74100

75101
- name: Build Spark operator
76102
run: make build-operator
77103

104+
build-sparkctl:
105+
runs-on: ubuntu-latest
106+
steps:
107+
- name: Checkout source code
108+
uses: actions/checkout@v4
109+
with:
110+
fetch-depth: 0
111+
112+
- name: Set up Go
113+
uses: actions/setup-go@v5
114+
with:
115+
go-version-file: go.mod
116+
117+
- name: Build sparkctl
118+
run: make build-sparkctl
119+
78120
build-helm-chart:
79121
runs-on: ubuntu-latest
80122
steps:
@@ -128,7 +170,7 @@ jobs:
128170
run: |
129171
make helm-docs
130172
if ! git diff --quiet -- charts/spark-operator-chart/README.md; then
131-
echo "Need to re-run 'make helm-docs' and commit the changes"
173+
echo "Need to re-run 'make helm-docs' and commit the changes."
132174
false
133175
fi
134176

.golangci.yaml

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,66 @@
11
run:
2-
deadline: 5m
2+
# Timeout for analysis, e.g. 30s, 5m.
3+
# Default: 1m
4+
timeout: 1m
35

46
linters:
7+
# Enable specific linters.
8+
# https://golangci-lint.run/usage/linters/#enabled-by-default
59
enable:
6-
- revive
7-
- gci
8-
- depguard
9-
- godot
10-
- testifylint
11-
- unconvert
10+
# Detects places where loop variables are copied.
11+
- copyloopvar
12+
# Checks for duplicate words in the source code.
13+
- dupword
14+
# Tool for detection of FIXME, TODO and other comment keywords.
15+
# - godox
16+
# Check import statements are formatted according to the 'goimport' command.
17+
- goimports
18+
# Enforces consistent import aliases.
19+
- importas
20+
# Find code that shadows one of Go's predeclared identifiers.
21+
- predeclared
22+
# Check that struct tags are well aligned.
23+
- tagalign
24+
# Remove unnecessary type conversions.
25+
- unconvert
26+
# Checks Go code for unused constants, variables, functions and types.
27+
- unused
1228

1329
issues:
14-
exclude-rules:
15-
# Disable errcheck linter for test files.
16-
- path: _test.go
17-
linters:
18-
- errcheck
30+
# Which dirs to exclude: issues from them won't be reported.
31+
# Can use regexp here: `generated.*`, regexp is applied on full path,
32+
# including the path prefix if one is set.
33+
# Default dirs are skipped independently of this option's value (see exclude-dirs-use-default).
34+
# "/" will be replaced by current OS file path separator to properly work on Windows.
35+
# Default: []
36+
exclude-dirs:
37+
- sparkctl
38+
# Maximum issues count per one linter.
39+
# Set to 0 to disable.
40+
# Default: 50
41+
max-issues-per-linter: 50
42+
# Maximum count of issues with the same text.
43+
# Set to 0 to disable.
44+
# Default: 3
45+
max-same-issues: 3
1946

2047
linters-settings:
21-
gci:
22-
sections:
23-
- standard
24-
- default
25-
- prefix(github.com/kubeflow/spark-operator)
26-
depguard:
27-
Main:
28-
files:
29-
- $all
30-
- "!$test"
31-
listMode: Lax
32-
deny:
33-
reflect: Please don't use reflect package
34-
Test:
35-
files:
36-
- $test
37-
listMode: Lax
38-
deny:
39-
reflect: Please don't use reflect package
48+
importas:
49+
# List of aliases
50+
alias:
51+
- pkg: k8s.io/api/admissionregistration/v1
52+
alias: admissionregistrationv1
53+
- pkg: k8s.io/api/apps/v1
54+
alias: appsv1
55+
- pkg: k8s.io/api/batch/v1
56+
alias: batchv1
57+
- pkg: k8s.io/api/core/v1
58+
alias: corev1
59+
- pkg: k8s.io/api/extensions/v1beta1
60+
alias: extensionsv1beta1
61+
- pkg: k8s.io/api/networking/v1
62+
alias: networkingv1
63+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
64+
alias: metav1
65+
- pkg: sigs.k8s.io/controller-runtime
66+
alias: ctrl

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ KIND_VERSION ?= v0.23.0
5555
ENVTEST_VERSION ?= release-0.18
5656
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5757
ENVTEST_K8S_VERSION ?= 1.29.3
58-
GOLANGCI_LINT_VERSION ?= v1.57.2
58+
GOLANGCI_LINT_VERSION ?= v1.61.0
5959
GEN_CRD_API_REFERENCE_DOCS_VERSION ?= v0.3.0
6060
HELM_VERSION ?= v3.15.3
6161
HELM_UNITTEST_VERSION ?= 0.5.1
@@ -139,13 +139,13 @@ go-vet: ## Run go vet against code.
139139
@echo "Running go vet..."
140140
go vet ./...
141141

142-
.PHONY: lint
143-
lint: golangci-lint ## Run golangci-lint linter.
142+
.PHONY: go-lint
143+
go-lint: golangci-lint ## Run golangci-lint linter.
144144
@echo "Running golangci-lint run..."
145145
$(GOLANGCI_LINT) run
146146

147-
.PHONY: lint-fix
148-
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes.
147+
.PHONY: go-lint-fix
148+
go-lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes.
149149
@echo "Running golangci-lint run --fix..."
150150
$(GOLANGCI_LINT) run --fix
151151

api/v1beta1/sparkapplication_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ type SparkApplicationSpec struct {
7070
// spark-submit.
7171
// Optional.
7272
SparkConf map[string]string `json:"sparkConf,omitempty"`
73-
// HadoopConf carries user-specified Hadoop configuration properties as they would use the the "--conf" option
74-
// in spark-submit. The SparkApplication controller automatically adds prefix "spark.hadoop." to Hadoop
73+
// HadoopConf carries user-specified Hadoop configuration properties as they would use the "--conf" option
74+
// in spark-submit. The SparkApplication controller automatically adds prefix "spark.hadoop." to Hadoop
7575
// configuration properties.
7676
// Optional.
7777
HadoopConf map[string]string `json:"hadoopConf,omitempty"`

api/v1beta2/defaults.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func SetSparkApplicationDefaults(app *SparkApplication) {
5454
}
5555

5656
func setDriverSpecDefaults(spec *DriverSpec, sparkConf map[string]string) {
57-
5857
if _, exists := sparkConf["spark.driver.cores"]; !exists && spec.Cores == nil {
5958
spec.Cores = new(int32)
6059
*spec.Cores = 1

api/v1beta2/defaults_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ func TestSetSparkApplicationDefaultsOnFailureRestartPolicyShouldSetDefaultValueF
121121
}
122122

123123
func TestSetSparkApplicationDefaultsDriverSpecDefaults(t *testing.T) {
124-
125124
//Case1: Driver config not set.
126125
app := &SparkApplication{
127126
Spec: SparkApplicationSpec{},

api/v1beta2/doc.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ limitations under the License.
1515
*/
1616

1717
// +k8s:deepcopy-gen=package,register
18-
// go:generate controller-gen crd:trivialVersions=true paths=. output:dir=.
1918

2019
// Package v1beta2 is the v1beta2 version of the API.
2120
// +groupName=sparkoperator.k8s.io

api/v1beta2/sparkapplication_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ type SparkApplicationSpec struct {
7171
// spark-submit.
7272
// +optional
7373
SparkConf map[string]string `json:"sparkConf,omitempty"`
74-
// HadoopConf carries user-specified Hadoop configuration properties as they would use the the "--conf" option
75-
// in spark-submit. The SparkApplication controller automatically adds prefix "spark.hadoop." to Hadoop
74+
// HadoopConf carries user-specified Hadoop configuration properties as they would use the "--conf" option
75+
// in spark-submit. The SparkApplication controller automatically adds prefix "spark.hadoop." to Hadoop
7676
// configuration properties.
7777
// +optional
7878
HadoopConf map[string]string `json:"hadoopConf,omitempty"`

cmd/operator/controller/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func start() {
248248

249249
// Register kube-schedulers.
250250
for _, name := range kubeSchedulerNames {
251-
registry.Register(name, kubescheduler.Factory)
251+
_ = registry.Register(name, kubescheduler.Factory)
252252
}
253253

254254
schedulerNames := registry.GetRegisteredSchedulerNames()

docs/api-docs.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,8 +1939,8 @@ map[string]string
19391939
</td>
19401940
<td>
19411941
<em>(Optional)</em>
1942-
<p>HadoopConf carries user-specified Hadoop configuration properties as they would use the the &ldquo;&ndash;conf&rdquo; option
1943-
in spark-submit. The SparkApplication controller automatically adds prefix &ldquo;spark.hadoop.&rdquo; to Hadoop
1942+
<p>HadoopConf carries user-specified Hadoop configuration properties as they would use the &ldquo;&ndash;conf&rdquo; option
1943+
in spark-submit. The SparkApplication controller automatically adds prefix &ldquo;spark.hadoop.&rdquo; to Hadoop
19441944
configuration properties.</p>
19451945
</td>
19461946
</tr>
@@ -2381,8 +2381,8 @@ map[string]string
23812381
</td>
23822382
<td>
23832383
<em>(Optional)</em>
2384-
<p>HadoopConf carries user-specified Hadoop configuration properties as they would use the the &ldquo;&ndash;conf&rdquo; option
2385-
in spark-submit. The SparkApplication controller automatically adds prefix &ldquo;spark.hadoop.&rdquo; to Hadoop
2384+
<p>HadoopConf carries user-specified Hadoop configuration properties as they would use the &ldquo;&ndash;conf&rdquo; option
2385+
in spark-submit. The SparkApplication controller automatically adds prefix &ldquo;spark.hadoop.&rdquo; to Hadoop
23862386
configuration properties.</p>
23872387
</td>
23882388
</tr>

0 commit comments

Comments
 (0)