Skip to content

Commit db5721c

Browse files
authored
Update debugging docs, GitHub Actions and golangci config #84
Update debugging docs, GitHub Actions and golangci config
2 parents 848ac99 + 5da36a7 commit db5721c

File tree

10 files changed

+191
-45
lines changed

10 files changed

+191
-45
lines changed

.github/workflows/build-docker-image.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ concurrency:
3535
jobs:
3636
build:
3737
if: github.repository == 'apache/cloudstack-kubernetes-provider'
38-
runs-on: ubuntu-22.04
38+
runs-on: ubuntu-latest
3939
steps:
4040
- name: Set Docker repository name
4141
run: echo "DOCKER_REPOSITORY=apache" >> $GITHUB_ENV
4242

43-
- uses: actions/checkout@v4
43+
- uses: actions/checkout@v6
4444
with:
4545
fetch-depth: 0
4646

.github/workflows/build.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
name: Test-Build
1919

20+
permissions:
21+
contents: read
22+
2023
on: [push, pull_request]
2124

2225
concurrency:
@@ -25,16 +28,21 @@ concurrency:
2528

2629
jobs:
2730
build:
28-
runs-on: ubuntu-22.04
31+
runs-on: ubuntu-latest
2932

3033
steps:
31-
- uses: actions/checkout@v4
34+
- uses: actions/checkout@v6
3235

3336
- name: Set up Go
34-
uses: actions/setup-go@v5
37+
uses: actions/setup-go@v6
3538
with:
3639
go-version-file: go.mod
3740

3841
- name: Run Script
3942
run: make test
4043

44+
- name: Upload coverage to Codecov
45+
uses: codecov/codecov-action@v5
46+
with:
47+
token: ${{ secrets.CODECOV_TOKEN }}
48+
files: coverage.txt
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: CodeQL Analysis
19+
on:
20+
push:
21+
branches: [main]
22+
pull_request:
23+
branches: [main]
24+
permissions:
25+
actions: read
26+
contents: read
27+
security-events: write
28+
jobs:
29+
codeql:
30+
name: CodeQL
31+
runs-on: ubuntu-latest
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: ["actions", "go"]
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v6
39+
- name: Initialize CodeQL
40+
uses: github/codeql-action/init@v4
41+
with:
42+
languages: ${{ matrix.language }}
43+
- name: Autobuild
44+
uses: github/codeql-action/autobuild@v4
45+
- name: Perform CodeQL Analysis
46+
uses: github/codeql-action/analyze@v4

.github/workflows/golangci-lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ jobs:
3030
name: lint
3131
runs-on: ubuntu-latest
3232
steps:
33-
- uses: actions/checkout@v4
34-
- uses: actions/setup-go@v5
33+
- uses: actions/checkout@v6
34+
- uses: actions/setup-go@v6
3535
with:
3636
go-version-file: go.mod
3737
- name: golangci-lint
38-
uses: golangci/golangci-lint-action@v6
38+
uses: golangci/golangci-lint-action@v9

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,31 @@
11
/cloudstack-ccm
22

3+
# Binaries for programs and plugins
4+
*.exe
5+
*.exe~
6+
*.dll
7+
*.so
8+
*.dylib
9+
10+
# Test binary, built with `go test -c`
11+
*.test
12+
13+
# Code coverage profiles and other test artifacts
14+
*.out
15+
coverage.*
16+
*.coverprofile
17+
profile.cov
18+
19+
# Dependency directories (remove the comment below to include it)
20+
# vendor/
21+
22+
# Go workspace file
23+
go.work
24+
go.work.sum
25+
26+
# env file
27+
.env
28+
29+
# Editor/IDE
30+
.idea/
31+
.vscode/

.golangci.yml

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,53 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
linters-settings:
19-
goheader:
20-
template: |-
21-
* Licensed to the Apache Software Foundation (ASF) under one
22-
* or more contributor license agreements. See the NOTICE file
23-
* distributed with this work for additional information
24-
* regarding copyright ownership. The ASF licenses this file
25-
* to you under the Apache License, Version 2.0 (the
26-
* "License"); you may not use this file except in compliance
27-
* with the License. You may obtain a copy of the License at
28-
*
29-
* http://www.apache.org/licenses/LICENSE-2.0
30-
*
31-
* Unless required by applicable law or agreed to in writing,
32-
* software distributed under the License is distributed on an
33-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
34-
* KIND, either express or implied. See the License for the
35-
* specific language governing permissions and limitations
36-
* under the License.
37-
18+
version: "2"
19+
run:
20+
modules-download-mode: readonly
21+
issues-exit-code: 1
3822
linters:
3923
enable:
4024
- goheader
4125
- gosec
42-
- gosimple
26+
- misspell
4327
- govet
4428
- ineffassign
45-
- misspell
4629
- staticcheck
47-
- typecheck
4830
- unused
49-
50-
run:
51-
modules-download-mode: readonly
52-
timeout: 5m
53-
issues-exit-code: 1
31+
settings:
32+
goheader:
33+
template: |-
34+
* Licensed to the Apache Software Foundation (ASF) under one
35+
* or more contributor license agreements. See the NOTICE file
36+
* distributed with this work for additional information
37+
* regarding copyright ownership. The ASF licenses this file
38+
* to you under the Apache License, Version 2.0 (the
39+
* "License"); you may not use this file except in compliance
40+
* with the License. You may obtain a copy of the License at
41+
*
42+
* http://www.apache.org/licenses/LICENSE-2.0
43+
*
44+
* Unless required by applicable law or agreed to in writing,
45+
* software distributed under the License is distributed on an
46+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
47+
* KIND, either express or implied. See the License for the
48+
* specific language governing permissions and limitations
49+
* under the License.
50+
exclusions:
51+
generated: lax
52+
presets:
53+
- comments
54+
- common-false-positives
55+
- legacy
56+
- std-error-handling
57+
paths:
58+
- third_party$
59+
- builtin$
60+
- examples$
61+
formatters:
62+
exclusions:
63+
generated: lax
64+
paths:
65+
- third_party$
66+
- builtin$
67+
- examples$

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
1919
ARG BUILDPLATFORM
2020
ARG TARGETOS
2121
ARG TARGETARCH
22-
COPY . /go/src/github.com/apache/cloudstack-kubernetes-provider
22+
2323
WORKDIR /go/src/github.com/apache/cloudstack-kubernetes-provider
24+
COPY go.mod /go/src/github.com/apache/cloudstack-kubernetes-provider/go.mod
25+
COPY go.sum /go/src/github.com/apache/cloudstack-kubernetes-provider/go.sum
26+
RUN go mod download
27+
28+
COPY . /go/src/github.com/apache/cloudstack-kubernetes-provider
2429
RUN make clean && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} make
2530

2631
FROM gcr.io/distroless/static:nonroot

Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,21 @@ clean:
4242
cloudstack-ccm: ${CMD_SRC}
4343
go build -ldflags ${LDFLAGS} -o $@ $^
4444

45-
test:
46-
go test -v
45+
test: gofmt
46+
go test -v -coverprofile=coverage.txt -covermode=atomic
4747
go vet
48-
@(echo "gofmt -l"; FMTFILES="$$(gofmt -l .)"; if test -n "$${FMTFILES}"; then echo "Go files that need to be reformatted (use 'go fmt'):\n$${FMTFILES}"; exit 1; fi)
4948

50-
docker:
49+
docker: gofmt
5150
docker build . -t apache/cloudstack-kubernetes-provider:${GIT_COMMIT_SHORT}
5251
docker tag apache/cloudstack-kubernetes-provider:${GIT_COMMIT_SHORT} apache/cloudstack-kubernetes-provider:latest
5352
ifneq (${GIT_IS_TAG},NOT_A_TAG)
5453
docker tag apache/cloudstack-kubernetes-provider:${GIT_COMMIT_SHORT} apache/cloudstack-kubernetes-provider:${GIT_TAG}
5554
endif
55+
56+
lint: gofmt
57+
@(echo "Running golangci-lint...")
58+
golangci-lint run
59+
60+
gofmt:
61+
@(echo "Running gofmt...")
62+
@(echo "gofmt -l"; FMTFILES="$$(gofmt -l .)"; if test -n "$${FMTFILES}"; then echo "Go files that need to be reformatted (use 'go fmt'):\n$${FMTFILES}"; exit 1; fi)

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Instead, it first obtains the name of the node from Kubernetes, then fetches inf
126126

127127
### Building
128128

129-
At least Go 1.21 is required to build cloudstack-ccm.
129+
At least Go 1.23 is required to build cloudstack-ccm.
130130

131131
To build the controller with correct versioning, some build flags need to be passed.
132132
A Makefile is provided that sets these build flags to automatically derived values.
@@ -151,13 +151,50 @@ The CCM supports the same cloud-config configuration file format used by [the cs
151151
so you can simply point it to that.
152152

153153
```bash
154-
./cloudstack-ccm --cloud-provider external-cloudstack --cloud-config ~/.cloud-config --master k8s-apiserver
154+
./cloudstack-ccm --cloud-provider external-cloudstack --cloud-config ./cloud-config --kubeconfig ~/.kube/config
155155
```
156156

157157
Replace k8s-apiserver with the host name of your Kubernetes development clusters's API server.
158158

159159
If you don't have a 'real' CloudStack installation, you can also launch a local [simulator instance](https://hub.docker.com/r/cloudstack/simulator) instead. This is very useful for dry-run testing.
160160

161+
### Debugging
162+
163+
You can use the VSCode extension [Go](https://marketplace.visualstudio.com/items?itemName=golang.go) to debug the CCM.
164+
Add the following configuration to the `.vscode/launch.json` file to launch the CCM and debug it.
165+
166+
```json
167+
{
168+
"version": "0.2.0",
169+
"configurations": [
170+
{
171+
"name": "Launch CloudStack CCM",
172+
"type": "go",
173+
"request": "launch",
174+
"mode": "auto",
175+
"program": "${workspaceFolder}/cmd/cloudstack-ccm",
176+
"env": {},
177+
"args": [
178+
"--cloud-provider=external-cloudstack",
179+
"--cloud-config=${workspaceFolder}/cloud-config",
180+
"--kubeconfig=${env:HOME}/.kube/config",
181+
"--leader-elect=false",
182+
"--v=4"
183+
],
184+
"showLog": true,
185+
"trace": "verbose"
186+
},
187+
{
188+
"name": "Attach to Process",
189+
"type": "go",
190+
"request": "attach",
191+
"mode": "local",
192+
"processId": 0
193+
}
194+
]
195+
}
196+
```
197+
161198
## Copyright
162199

163200
Copyright 2019 The Apache Software Foundation

cloudstack_loadbalancer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ func (cs *CSCloud) EnsureLoadBalancer(ctx context.Context, clusterName string, s
201201
for _, lbRule := range lb.rules {
202202
protocol := ProtocolFromLoadBalancer(lbRule.Protocol)
203203
if protocol == LoadBalancerProtocolInvalid {
204-
return nil, fmt.Errorf("Error parsing protocol %v: %v", lbRule.Protocol, err)
204+
return nil, fmt.Errorf("error parsing protocol %v: %v", lbRule.Protocol, err)
205205
}
206206
port, err := strconv.ParseInt(lbRule.Publicport, 10, 32)
207207
if err != nil {
208-
return nil, fmt.Errorf("Error parsing port %s: %v", lbRule.Publicport, err)
208+
return nil, fmt.Errorf("error parsing port %s: %v", lbRule.Publicport, err)
209209
}
210210

211211
klog.V(4).Infof("Deleting firewall rules associated with load balancer rule: %v (%v:%v:%v)", lbRule.Name, protocol, lbRule.Publicip, port)

0 commit comments

Comments
 (0)