Skip to content

Commit 421fd4d

Browse files
Update dependencies and Go 1.25 (#173)
1 parent 11fd0e6 commit 421fd4d

File tree

19 files changed

+1206
-875
lines changed

19 files changed

+1206
-875
lines changed

.github/workflows/lint.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ permissions:
77
contents: read
88

99
env:
10-
GO_VERSION: "1.24"
10+
GO_VERSION: "1.25"
11+
GOLANGCI_LINT_VERSION: "v2.4.0"
1112

1213
jobs:
1314
lint:
@@ -21,4 +22,6 @@ jobs:
2122
- name: Download Dependencies
2223
run: go mod download
2324
- name: golangci-lint
24-
uses: golangci/golangci-lint-action@v6
25+
uses: golangci/golangci-lint-action@v8
26+
with:
27+
version: ${{ env.GOLANGCI_LINT_VERSION }}

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout
17-
uses: actions/checkout@v4
17+
uses: actions/checkout@v5
1818
- name: Collect Metadata
1919
id: meta
2020
uses: docker/metadata-action@v5

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ permissions:
99
contents: write
1010

1111
env:
12-
GO_VERSION: "1.24"
12+
GO_VERSION: "1.25"
1313
GOPRIVATE: "github:com/NCCloud/*"
1414

1515
jobs:
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
go-version: ${{ env.GO_VERSION }}
2424
- name: Checkout
25-
uses: actions/checkout@v4
25+
uses: actions/checkout@v5
2626
- name: Validate
2727
run: |
2828
./devops.sh generate

.golangci.yaml

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1+
version: "2"
2+
run:
3+
go: "1.25"
4+
tests: false
15
linters:
2-
enable-all: true
6+
default: all
37
disable:
4-
- exhaustruct # Disallows to left unused fields in structs
5-
- wrapcheck # Disallows to use non-wrapped errors
6-
- gochecknoinits # Disallows to use init functions
7-
- ireturn # Disallows to return Interfaces
8-
- gci # Disable gci import ordering checker since its buggy
9-
- forcetypeassert # Disallows to use type assertions without checking
10-
- depguard # Disallows to use non-listed packages
11-
- gochecknoglobals # We like global variables
12-
- tagalign # Buggy
13-
- lll
8+
- contextcheck
9+
- depguard
10+
- exhaustruct
11+
- forcetypeassert
1412
- funlen
13+
- gochecknoglobals
14+
- gochecknoinits
15+
- ireturn
16+
- lll
1517
- perfsprint
16-
- contextcheck
17-
linters-settings:
18-
cyclop:
19-
max-complexity: 12
20-
run:
21-
go: '1.24'
22-
timeout: 10m
23-
tests: false
24-
issues:
25-
exclude-dirs:
26-
- cmd/benchmark
18+
- tagalign
19+
- wrapcheck
20+
- revive
21+
- noinlineerr
22+
settings:
23+
cyclop:
24+
max-complexity: 12
25+
formatters:
26+
enable:
27+
- gofmt
28+
- gofumpt
29+
- goimports

.mockery.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
template: testify
2+
dir: "mocks"
3+
filename: "{{.SrcPackagePath}}/mock_{{.InterfaceName}}.go"
14
packages:
2-
sigs.k8s.io/controller-runtime/pkg/client:
5+
github.com/NCCloud/mayfly/pkg/common:
36
interfaces:
4-
Client:
5-
SubResourceClient:
7+
Scheduler: {}
68
sigs.k8s.io/controller-runtime/pkg/cache:
79
interfaces:
8-
Cache:
9-
sigs.k8s.io/controller-runtime/pkg/manager:
10+
Cache: {}
11+
sigs.k8s.io/controller-runtime/pkg/client:
1012
interfaces:
11-
Manager:
12-
github.com/NCCloud/mayfly/pkg/common:
13+
Client: {}
14+
SubResourceClient: {}
15+
sigs.k8s.io/controller-runtime/pkg/manager:
1316
interfaces:
14-
Scheduler:
17+
Manager: {}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.24 as builder
1+
FROM golang:1.25 as builder
22
WORKDIR /build
33

44
COPY . .

cmd/benchmark/benchmark.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"log"
67
time "time"
78

89
"github.com/NCCloud/mayfly/pkg/common"
@@ -20,7 +21,7 @@ func (b *Benchmark) Start() {
2021
}
2122

2223
func (b *Benchmark) CreateResources() {
23-
fmt.Println("Creating resources")
24+
log.Println("Creating resources")
2425
}
2526

2627
func (b *Benchmark) Listener() Result {
@@ -29,21 +30,24 @@ func (b *Benchmark) Listener() Result {
2930
for {
3031
kind := make(map[string]int)
3132
now := time.Now()
33+
3234
for _, resourceKind := range b.config.Resources {
3335
resourceList := common.NewResourceInstanceList(resourceKind)
3436

3537
resourcesListErr := b.mgrClient.List(context.Background(), resourceList)
3638
if resourcesListErr != nil {
3739
panic(resourcesListErr)
3840
}
41+
3942
for _, resource := range resourceList.Items {
4043
if resource.GetAnnotations()[b.config.ExpirationLabel] == "" {
4144
continue
4245
}
46+
4347
kind[resourceKind]++
4448
}
45-
4649
}
50+
4751
result.Points = append(result.Points, Point{
4852
time: now,
4953
kind: kind,
@@ -55,25 +59,28 @@ func (b *Benchmark) Listener() Result {
5559
if time.Since(b.startedAt) > 60*time.Minute {
5660
break
5761
}
62+
5863
time.Sleep(b.granularity)
5964
}
6065

6166
return result
6267
}
6368

6469
func (b *Benchmark) createSecrets() {
65-
for i := 0; i < b.count; i++ {
66-
id := i + b.offset
67-
secret := b.generateSecret(id)
70+
for i := range b.count {
71+
secretId := i + b.offset
72+
secret := b.generateSecret(secretId)
73+
6874
createErr := mgrClient.Create(context.Background(), secret)
6975
if createErr != nil {
70-
fmt.Println(createErr)
76+
log.Println(createErr)
7177
}
7278

73-
fmt.Printf("\nSecret %d has been created.", id)
79+
log.Printf("\nSecret %d has been created.", secretId)
7480
time.Sleep(b.delay)
7581
}
76-
fmt.Printf("\n")
82+
83+
log.Printf("\n")
7784
}
7885

7986
func (b *Benchmark) generateSecret(id int) *v1.Secret {

cmd/benchmark/main.go

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,63 +26,77 @@ var (
2626
)
2727

2828
func init() {
29-
scheme := runtime.NewScheme()
29+
var (
30+
scheme = runtime.NewScheme()
31+
mgrClientErr error
32+
)
33+
3034
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
3135

3236
config = common.NewConfig()
3337

34-
var mgrClientErr error
3538
mgrClient, mgrClientErr = client.New(ctrl.GetConfigOrDie(), client.Options{Scheme: scheme})
3639
if mgrClientErr != nil {
3740
panic(mgrClientErr)
3841
}
3942
}
4043

4144
func main() {
42-
benchmark := NewBenchmark(mgrClient, config, 10000).
43-
Delay(0)
44-
45+
itemCount := 1000
46+
benchmark := NewBenchmark(mgrClient, config, itemCount).Delay(0)
4547
benchmark.Start()
4648

47-
f, _ := os.Create(benchmarkHtml)
48-
_, writeStringErr := f.WriteString(" <meta http-equiv=\"refresh\" content=\"6\" />\nWaiting for Mayfly benchmark to start...")
49+
benchmarkFile, _ := os.Create(benchmarkHtml)
50+
51+
_, writeStringErr := benchmarkFile.WriteString(" <meta http-equiv=\"refresh\" content=\"6\" />\nWaiting for Mayfly benchmark to start...")
4952
if writeStringErr != nil {
5053
panic(writeStringErr)
5154
}
52-
openFilErr := browser.OpenFile(f.Name())
55+
56+
openFilErr := browser.OpenFile(benchmarkFile.Name())
5357
if openFilErr != nil {
5458
panic(openFilErr)
5559
}
5660

5761
for {
58-
time.Sleep(5 * time.Second)
59-
result := benchmark.GetResult()
60-
var durations []string
61-
data := map[string][]opts.LineData{}
62+
var (
63+
waitTimeSecond = 5
64+
result = benchmark.GetResult()
65+
durations []string
66+
data = map[string][]opts.LineData{}
67+
)
68+
69+
time.Sleep(time.Duration(waitTimeSecond) * time.Second)
70+
6271
for _, point := range result.Points {
6372
durations = append(durations, fmt.Sprintf("%.0fs", point.time.Sub(result.StartedAt).Seconds()))
73+
6474
for _, resource := range config.Resources {
6575
data[resource] = append(data[resource], opts.LineData{Name: resource, Value: point.kind[resource]})
6676
}
6777
}
68-
Render(CreateChart(durations, data))
6978

79+
Render(CreateChart(durations, data))
7080
}
7181
}
7282

7383
func Render(chart *charts.Line) {
74-
f, _ := os.Create(benchmarkHtml)
75-
_, writeStringErr := f.WriteString(" <meta http-equiv=\"refresh\" content=\"6\" />")
84+
benchFile, _ := os.Create(benchmarkHtml)
85+
86+
_, writeStringErr := benchFile.WriteString(" <meta http-equiv=\"refresh\" content=\"6\" />")
7687
if writeStringErr != nil {
7788
panic(writeStringErr)
7889
}
79-
renderErr := chart.Render(f)
90+
91+
renderErr := chart.Render(benchFile)
8092
if renderErr != nil {
8193
panic(renderErr)
8294
}
8395
}
8496

8597
func CreateChart(xAxis []string, yzAxis map[string][]opts.LineData) *charts.Line {
98+
var chartAreaOpacity float32 = 0.2
99+
86100
line := charts.NewLine()
87101
line.SetGlobalOptions(charts.WithTitleOpts(opts.Title{
88102
Title: pageTitle,
@@ -94,11 +108,13 @@ func CreateChart(xAxis []string, yzAxis map[string][]opts.LineData) *charts.Line
94108
Height: "800px",
95109
Theme: "infographic",
96110
}))
111+
97112
line.SetXAxis(xAxis)
113+
98114
for kind, value := range yzAxis {
99115
line.AddSeries(kind, value).SetSeriesOptions(
100116
charts.WithAreaStyleOpts(opts.AreaStyle{
101-
Opacity: 0.2,
117+
Opacity: opts.Float(chartAreaOpacity),
102118
}),
103119
charts.WithLineChartOpts(opts.LineChart{
104120
Smooth: opts.Bool(false),
@@ -107,5 +123,6 @@ func CreateChart(xAxis []string, yzAxis map[string][]opts.LineData) *charts.Line
107123
opts.MarkPointStyle{Label: &opts.Label{Show: opts.Bool(true)}}),
108124
)
109125
}
126+
110127
return line
111128
}

cmd/benchmark/types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ type Point struct {
3030
}
3131

3232
func NewBenchmark(mgrClient client.Client, config *common.Config, count int) *Benchmark {
33+
granularityInSeconds := 5
34+
3335
return &Benchmark{
34-
granularity: 5 * time.Second,
36+
granularity: time.Duration(granularityInSeconds) * time.Second,
3537
config: config,
3638
mgrClient: mgrClient,
3739
count: count,
@@ -42,15 +44,18 @@ func NewBenchmark(mgrClient client.Client, config *common.Config, count int) *Be
4244

4345
func (b *Benchmark) Granularity(granularity time.Duration) *Benchmark {
4446
b.granularity = granularity
47+
4548
return b
4649
}
4750

4851
func (b *Benchmark) Offset(offset int) *Benchmark {
4952
b.offset = offset
53+
5054
return b
5155
}
5256

5357
func (b *Benchmark) Delay(delay time.Duration) *Benchmark {
5458
b.delay = delay
59+
5560
return b
5661
}

deploy/crds/cloud.namecheap.com_scheduledresources.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.17.2
6+
controller-gen.kubebuilder.io/version: v0.18.0
77
name: scheduledresources.cloud.namecheap.com
88
spec:
99
group: cloud.namecheap.com

0 commit comments

Comments
 (0)