Skip to content

Commit 02de4e0

Browse files
authored
feat: bump/migrate deps (#288)
* feat: bump/migrate go deps Signed-off-by: Mike Nguyen <hey@mike.ee> * fix(ci): update Go version source and use golangci-lint v2 Signed-off-by: Mike Nguyen <hey@mike.ee> * fix: refactors Signed-off-by: Mike Nguyen <hey@mike.ee> * chore: node deps Signed-off-by: Mike Nguyen <hey@mike.ee> * fix: improve error handling on resource closure in webserver and instances Signed-off-by: Mike Nguyen <hey@mike.ee> --------- Signed-off-by: Mike Nguyen <hey@mike.ee>
1 parent 36f61ac commit 02de4e0

File tree

9 files changed

+4058
-3597
lines changed

9 files changed

+4058
-3597
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ jobs:
3333
name: Build ${{ matrix.target_os }}_${{ matrix.target_arch }} binaries
3434
runs-on: ${{ matrix.os }}
3535
env:
36-
GOVER: 1.21
37-
GOLANGCILINT_VER: 1.56.2
36+
GOLANGCILINT_VER: 'v2.7.1'
3837
GOOS: ${{ matrix.target_os }}
3938
GOARCH: ${{ matrix.target_arch }}
4039
GOPROXY: https://proxy.golang.org
@@ -59,22 +58,23 @@ jobs:
5958
- os: windows-latest
6059
target_arch: arm64
6160
steps:
61+
- name: Check out code into the Go module directory
62+
uses: actions/checkout@v6
6263
- name: Setup node ${{ env.NODE_VERSION }} and npm
6364
uses: actions/setup-node@v1
6465
with:
6566
node-version: ${{ env.NODE_VERSION }}
6667
- name: Install angular cli
6768
run: npm install -g @angular/cli
68-
- name: Set up Go ${{ env.GOVER }}
69-
uses: actions/setup-go@v2
69+
- name: Set up Go (using root 'go.mod' version)
70+
uses: actions/setup-go@v6
7071
with:
71-
go-version: ${{ env.GOVER }}
72-
- name: Install golangci-lint
73-
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
74-
run: |
75-
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${{ env.GOROOT }}/bin" v${{ env.GOLANGCILINT_VER }}
76-
- name: Check out code into the Go module directory
77-
uses: actions/checkout@v2
72+
go-version-file: 'go.mod'
73+
- name: golangci-lint
74+
uses: golangci/golangci-lint-action@v9
75+
with:
76+
version: ${{ env.GOLANGCILINT_VER }}
77+
skip-cache: true
7878
- name: Parse release version and set REL_VERSION
7979
run: python ./.github/scripts/get_release_version.py
8080
- name: Run make lint

cmd/webserver.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,11 @@ func getLogStreamsHandler(w http.ResponseWriter, r *http.Request) {
249249
http.Error(w, err.Error(), http.StatusInternalServerError)
250250
return
251251
}
252-
defer c.Close()
252+
defer func() {
253+
if err := c.Close(); err != nil {
254+
log.Println("websocket close:", err)
255+
}
256+
}()
253257
streams, err := inst.GetLogStream(scope, id, container)
254258
if err != nil {
255259
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -258,7 +262,11 @@ func getLogStreamsHandler(w http.ResponseWriter, r *http.Request) {
258262

259263
var readStreams []io.Reader
260264
for _, stream := range streams {
261-
defer stream.Close()
265+
defer func(s io.Closer) {
266+
if err := s.Close(); err != nil {
267+
log.Println("fail to close stream:", err)
268+
}
269+
}(stream)
262270
readStreams = append(readStreams, stream)
263271
}
264272
reader := io.MultiReader(readStreams...)

go.mod

Lines changed: 138 additions & 138 deletions
Large diffs are not rendered by default.

go.sum

Lines changed: 303 additions & 353 deletions
Large diffs are not rendered by default.

pkg/components/components.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ func NewComponents(platform platforms.Platform, daprClient scheme.Interface, com
4747
c := components{}
4848
c.platform = platform
4949

50-
if platform == platforms.Kubernetes {
50+
switch platform {
51+
case platforms.Kubernetes:
5152
c.getComponentsFn = c.getKubernetesComponents
5253
c.daprClient = daprClient
53-
} else if platform == platforms.Standalone {
54+
case platforms.Standalone:
5455
c.getComponentsFn = c.getStandaloneComponents
55-
} else if platform == platforms.DockerCompose {
56+
case platforms.DockerCompose:
5657
c.getComponentsFn = c.getDockerComposeComponents
5758
c.componentsPath = componentsPath
5859
}

pkg/configurations/configurations.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ func NewConfigurations(platform platforms.Platform, daprClient scheme.Interface,
4646
c := configurations{}
4747
c.platform = platform
4848

49-
if platform == platforms.Kubernetes {
49+
switch platform {
50+
case platforms.Kubernetes:
5051
c.getConfigurationsFn = c.getKubernetesConfigurations
5152
c.daprClient = daprClient
52-
} else if platform == platforms.Standalone {
53+
case platforms.Standalone:
5354
c.getConfigurationsFn = c.getStandaloneConfigurations
54-
} else if platform == platforms.DockerCompose {
55+
case platforms.DockerCompose:
5556
c.getConfigurationsFn = c.getDockerComposeConfigurations
5657
c.configPath = configPath
5758
}

pkg/instances/instances.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ func NewInstances(platform platforms.Platform, kubeClient *kubernetes.Clientset,
9393
i.metadataClient = http.Client{}
9494
i.daprApiToken = os.Getenv("DAPR_API_TOKEN")
9595

96-
if i.platform == platforms.Kubernetes {
96+
switch i.platform {
97+
case platforms.Kubernetes:
9798
i.getInstancesFn = i.getKubernetesInstances
9899
i.getScopesFn = i.getKubernetesScopes
99100
i.kubeClient = kubeClient
100-
} else if i.platform == platforms.Standalone {
101+
case platforms.Standalone:
101102
i.getInstancesFn = i.getStandaloneInstances
102103
i.getScopesFn = i.getStandaloneScopes
103-
} else if i.platform == platforms.DockerCompose {
104+
case platforms.DockerCompose:
104105
i.getInstancesFn = i.getDockerComposeInstances
105106
i.getScopesFn = i.getDockerComposeScopes
106107
i.dockerComposePath = dockerComposePath
@@ -214,7 +215,7 @@ func (i *instances) GetLogStream(scope, id, containerName string) ([]io.ReadClos
214215
var logstreams []io.ReadCloser
215216

216217
for _, p := range pods.Items {
217-
name := p.ObjectMeta.Name
218+
name := p.Name
218219

219220
for _, container := range p.Spec.Containers {
220221
if container.Name == containerName {
@@ -259,7 +260,7 @@ func (i *instances) GetLogStream(scope, id, containerName string) ([]io.ReadClos
259260
var logstreams []io.ReadCloser
260261

261262
for _, p := range pods.Items {
262-
name := p.ObjectMeta.Name
263+
name := p.Name
263264

264265
for _, container := range p.Spec.Containers {
265266
if container.Name == containerName {
@@ -314,8 +315,8 @@ func (i *instances) GetDeploymentConfiguration(scope string, id string) string {
314315
if len(pods.Items) > 0 {
315316
p := pods.Items[0]
316317

317-
name := p.ObjectMeta.Name
318-
nspace := p.ObjectMeta.Namespace
318+
name := p.Name
319+
nspace := p.Namespace
319320

320321
restClient := i.kubeClient.CoreV1().RESTClient()
321322
if err != nil {
@@ -372,8 +373,8 @@ func (i *instances) GetDeploymentConfiguration(scope string, id string) string {
372373
if len(pods.Items) > 0 {
373374
p := pods.Items[0]
374375

375-
name := p.ObjectMeta.Name
376-
nspace := p.ObjectMeta.Namespace
376+
name := p.Name
377+
nspace := p.Namespace
377378

378379
restClient := i.kubeClient.CoreV1().RESTClient()
379380
if err != nil {
@@ -642,7 +643,11 @@ func (i *instances) getMetadataOutputFromURLs(primaryURL string, secondaryURL st
642643
return MetadataOutput{}
643644
}
644645

645-
defer resp.Body.Close()
646+
defer func() {
647+
if err := resp.Body.Close(); err != nil {
648+
log.Println("failed to close response body:", err)
649+
}
650+
}()
646651
body, err := io.ReadAll(resp.Body)
647652
if err != nil {
648653
log.Println(err)

pkg/instances/instances_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
func newTestSimpleK8s(objects ...runtime.Object) instances {
3131
client := instances{}
32-
client.kubeClient = fake.NewSimpleClientset(objects...)
32+
client.kubeClient = fake.NewSimpleClientset(objects...) //nolint:staticcheck
3333
return client
3434
}
3535

0 commit comments

Comments
 (0)