Skip to content

Commit 798007a

Browse files
authored
Merge pull request #4780 from vincepri/enable-lint-test
🌱 Enable golanci-lint for test/ submodule
2 parents 1a539da + 01fb233 commit 798007a

File tree

12 files changed

+43
-33
lines changed

12 files changed

+43
-33
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ jobs:
99
golangci:
1010
name: lint
1111
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
working-directory:
15+
- ""
16+
- test
1217
steps:
1318
- uses: actions/checkout@v2
1419
- name: golangci-lint
1520
uses: golangci/golangci-lint-action@v2
1621
with:
1722
version: v1.40.1
23+
working-directory: ${{matrix.working-directory}}

.golangci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ issues:
9999
- linters:
100100
- revive
101101
text: exported (method|function|type|const) (.+) should have comment or be unexported
102-
path: .*test/(providers|framework|e2e).*.go
102+
path: cmd/clusterctl/internal/test/providers.*.go
103+
- linters:
104+
- revive
105+
text: exported (method|function|type|const) (.+) should have comment or be unexported
106+
path: "(framework|e2e|infrastructure/docker)/.*.go"
103107
# Disable unparam "always receives" which might not be really
104108
# useful when building libraries.
105109
- linters:
@@ -109,10 +113,10 @@ issues:
109113
# within test files.
110114
- path: _test\.go
111115
text: should not use dot imports
116+
- path: (framework|e2e)/.*.go
117+
text: should not use dot imports
112118
- path: _test\.go
113119
text: cyclomatic complexity
114-
- path: test/(framework|e2e).*.go
115-
text: should not use dot imports
116120
# Append should be able to assign to a different var/slice.
117121
- linters:
118122
- gocritic

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ e2e-framework: ## Builds the CAPI e2e framework
222222
.PHONY: lint
223223
lint: $(GOLANGCI_LINT) ## Lint codebase
224224
$(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS)
225+
cd $(TEST_DIR); $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS)
225226

226227
.PHONY: lint-fix
227228
lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter.

test/infrastructure/docker/cloudinit/runcmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"sigs.k8s.io/yaml"
2525
)
2626

27-
// Cmd.
27+
// Cmd defines a shell command.
2828
type Cmd struct {
2929
Cmd string
3030
Args []string

test/infrastructure/docker/cloudinit/writefiles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (a *writeFilesAction) Commands() ([]Cmd, error) {
7979
permissions := fixPermissions(f.Permissions)
8080
content, err := fixContent(f.Content, encodings)
8181
if path == kubeadmInitPath {
82-
content = content + kubeproxyComponentConfig
82+
content += kubeproxyComponentConfig
8383
}
8484
if err != nil {
8585
return commands, errors.Wrapf(err, "error decoding content for %s", path)

test/infrastructure/docker/controllers/dockercluster_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func patchDockerCluster(ctx context.Context, patchHelper *patch.Helper, dockerCl
135135
}
136136

137137
func (r *DockerClusterReconciler) reconcileNormal(ctx context.Context, dockerCluster *infrav1.DockerCluster, externalLoadBalancer *docker.LoadBalancer) (ctrl.Result, error) {
138-
//Create the docker container hosting the load balancer
138+
// Create the docker container hosting the load balancer.
139139
if err := externalLoadBalancer.Create(ctx); err != nil {
140140
conditions.MarkFalse(dockerCluster, infrav1.LoadBalancerAvailableCondition, infrav1.LoadBalancerProvisioningFailedReason, clusterv1.ConditionSeverityWarning, err.Error())
141141
return ctrl.Result{}, errors.Wrap(err, "failed to create load balancer")

test/infrastructure/docker/controllers/dockermachine_controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
. "github.com/onsi/gomega"
2323

24-
v1 "k8s.io/api/core/v1"
24+
corev1 "k8s.io/api/core/v1"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
2727
infrav1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1alpha4"
@@ -73,7 +73,7 @@ func newCluster(clusterName string, dockerCluster *infrav1.DockerCluster) *clust
7373
},
7474
}
7575
if dockerCluster != nil {
76-
cluster.Spec.InfrastructureRef = &v1.ObjectReference{
76+
cluster.Spec.InfrastructureRef = &corev1.ObjectReference{
7777
Name: dockerCluster.Name,
7878
Namespace: dockerCluster.Namespace,
7979
Kind: dockerCluster.Kind,
@@ -109,7 +109,7 @@ func newMachine(clusterName, machineName string, dockerMachine *infrav1.DockerMa
109109
},
110110
}
111111
if dockerMachine != nil {
112-
machine.Spec.InfrastructureRef = v1.ObjectReference{
112+
machine.Spec.InfrastructureRef = corev1.ObjectReference{
113113
Name: dockerMachine.Name,
114114
Namespace: dockerMachine.Namespace,
115115
Kind: dockerMachine.Kind,

test/infrastructure/docker/docker/machine.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,10 @@ func (m *Machine) CheckForBootstrapSuccess(ctx context.Context) error {
358358
cmd := m.container.Commander.Command("test", "-f", "/run/cluster-api/bootstrap-success.complete")
359359
cmd.SetStderr(&outErr)
360360
cmd.SetStdout(&outStd)
361-
err := cmd.Run(ctx)
362-
if err != nil {
361+
if err := cmd.Run(ctx); err != nil {
363362
log.Info("Failed running command", "command", "test -f /run/cluster-api/bootstrap-success.complete", "stdout", outStd.String(), "stderr", outErr.String())
364363
return errors.Wrap(errors.WithStack(err), "failed to run bootstrap check")
365364
}
366-
367365
return nil
368366
}
369367

@@ -447,7 +445,7 @@ func (m *Machine) machineImage(version *string) string {
447445
return defaultImage
448446
}
449447

450-
//TODO(fp) make this smarter
448+
// TODO(fp) make this smarter
451449
// - allows usage of custom docker repository & image names
452450
// - add v only for semantic versions
453451
versionString := *version

test/infrastructure/docker/docker/types/node.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type Node struct {
3737
InternalIP string
3838
Image string
3939
status string
40-
Commander *containerCmder
40+
Commander *ContainerCmder
4141
}
4242

4343
// NewNode returns a Node with defaults.
@@ -46,7 +46,7 @@ func NewNode(name, image, role string) *Node {
4646
Name: name,
4747
Image: image,
4848
ClusterRole: role,
49-
Commander: ContainerCmder(name),
49+
Commander: GetContainerCmder(name),
5050
}
5151
}
5252

@@ -131,26 +131,26 @@ func (n *Node) Kill(ctx context.Context, signal string) error {
131131
return errors.WithStack(cmd.Run())
132132
}
133133

134-
type containerCmder struct {
134+
type ContainerCmder struct {
135135
nameOrID string
136136
}
137137

138-
func ContainerCmder(containerNameOrID string) *containerCmder {
139-
return &containerCmder{
138+
func GetContainerCmder(containerNameOrID string) *ContainerCmder {
139+
return &ContainerCmder{
140140
nameOrID: containerNameOrID,
141141
}
142142
}
143143

144-
func (c *containerCmder) Command(command string, args ...string) *containerCmd {
145-
return &containerCmd{
144+
func (c *ContainerCmder) Command(command string, args ...string) *ContainerCmd {
145+
return &ContainerCmd{
146146
nameOrID: c.nameOrID,
147147
command: command,
148148
args: args,
149149
}
150150
}
151151

152-
// containerCmd implements exec.Cmd for docker containers.
153-
type containerCmd struct {
152+
// ContainerCmd implements exec.Cmd for docker containers.
153+
type ContainerCmd struct {
154154
nameOrID string // the container name or ID
155155
command string
156156
args []string
@@ -161,7 +161,7 @@ type containerCmd struct {
161161
}
162162

163163
// RunLoggingOutputOnFail runs the cmd, logging error output if Run returns an error.
164-
func (c *containerCmd) RunLoggingOutputOnFail(ctx context.Context) ([]string, error) {
164+
func (c *ContainerCmd) RunLoggingOutputOnFail(ctx context.Context) ([]string, error) {
165165
var buff bytes.Buffer
166166
c.SetStdout(&buff)
167167
c.SetStderr(&buff)
@@ -176,7 +176,7 @@ func (c *containerCmd) RunLoggingOutputOnFail(ctx context.Context) ([]string, er
176176
return out, errors.WithStack(err)
177177
}
178178

179-
func (c *containerCmd) Run(ctx context.Context) error {
179+
func (c *ContainerCmd) Run(ctx context.Context) error {
180180
args := []string{
181181
"exec",
182182
// run with privileges so we can remount etc..
@@ -218,18 +218,18 @@ func (c *containerCmd) Run(ctx context.Context) error {
218218
return errors.WithStack(cmd.Run())
219219
}
220220

221-
func (c *containerCmd) SetEnv(env ...string) {
221+
func (c *ContainerCmd) SetEnv(env ...string) {
222222
c.env = env
223223
}
224224

225-
func (c *containerCmd) SetStdin(r io.Reader) {
225+
func (c *ContainerCmd) SetStdin(r io.Reader) {
226226
c.stdin = r
227227
}
228228

229-
func (c *containerCmd) SetStdout(w io.Writer) {
229+
func (c *ContainerCmd) SetStdout(w io.Writer) {
230230
c.stdout = w
231231
}
232232

233-
func (c *containerCmd) SetStderr(w io.Writer) {
233+
func (c *ContainerCmd) SetStderr(w io.Writer) {
234234
c.stderr = w
235235
}

test/infrastructure/docker/exp/controllers/dockermachinepool_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type DockerMachinePoolReconciler struct {
5353
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=dockermachinepools/status,verbs=get;update;patch
5454
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=machinepools;machinepools/status,verbs=get;list;watch
5555
// +kubebuilder:rbac:groups="",resources=secrets;,verbs=get;list;watch
56+
5657
func (r *DockerMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.Result, rerr error) {
5758
log := ctrl.LoggerFrom(ctx, "docker-machine-pool", req.NamespacedName)
5859

test/infrastructure/docker/exp/docker/nodepool.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ type NodePool struct {
5353
}
5454

5555
// NewNodePool creates a new node pool instances.
56-
func NewNodePool(kClient client.Client, cluster *clusterv1.Cluster, mp *clusterv1exp.MachinePool, dmp *infrav1exp.DockerMachinePool) (*NodePool, error) {
56+
func NewNodePool(c client.Client, cluster *clusterv1.Cluster, mp *clusterv1exp.MachinePool, dmp *infrav1exp.DockerMachinePool) (*NodePool, error) {
5757
np := &NodePool{
58-
client: kClient,
58+
client: c,
5959
cluster: cluster,
6060
machinePool: mp,
6161
dockerMachinePool: dmp,
@@ -320,14 +320,14 @@ func (np *NodePool) reconcileMachine(ctx context.Context, machine *docker.Machin
320320
}
321321

322322
// getBootstrapData fetches the bootstrap data for the machine pool.
323-
func getBootstrapData(ctx context.Context, kClient client.Client, machinePool *clusterv1exp.MachinePool) (string, error) {
323+
func getBootstrapData(ctx context.Context, c client.Client, machinePool *clusterv1exp.MachinePool) (string, error) {
324324
if machinePool.Spec.Template.Spec.Bootstrap.DataSecretName == nil {
325325
return "", errors.New("error retrieving bootstrap data: linked MachinePool's bootstrap.dataSecretName is nil")
326326
}
327327

328328
s := &corev1.Secret{}
329329
key := client.ObjectKey{Namespace: machinePool.GetNamespace(), Name: *machinePool.Spec.Template.Spec.Bootstrap.DataSecretName}
330-
if err := kClient.Get(ctx, key, s); err != nil {
330+
if err := c.Get(ctx, key, s); err != nil {
331331
return "", errors.Wrapf(err, "failed to retrieve bootstrap data secret for DockerMachinePool instance %s/%s", machinePool.GetNamespace(), machinePool.GetName())
332332
}
333333

test/infrastructure/docker/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var (
5151
myscheme = runtime.NewScheme()
5252
setupLog = ctrl.Log.WithName("setup")
5353

54-
//flags.
54+
// flags.
5555
metricsBindAddr string
5656
enableLeaderElection bool
5757
syncPeriod time.Duration

0 commit comments

Comments
 (0)