Skip to content

Commit 8228fc4

Browse files
committed
enable the kubernetes api linter starting with comment linting
1 parent 7177085 commit 8228fc4

28 files changed

+1143
-774
lines changed

.custom-gcl.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: v2.4.0
2+
name: golangci-lint-kube-api-linter
3+
destination: ./bin
4+
plugins:
5+
- module: 'sigs.k8s.io/kube-api-linter'
6+
version: v0.0.0-20250819121536-a575e84f4ce8

.github/workflows/go-analyze.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,8 @@ jobs:
7171
with:
7272
version: latest
7373

74+
- name: lint-api
75+
run: make lint-api
76+
7477
- name: Nilcheck
7578
run: make nilcheck

.golangci-kal.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: "2"
2+
run:
3+
issues-exit-code: 1
4+
output:
5+
formats:
6+
text:
7+
path: stdout
8+
linters:
9+
default: none
10+
enable:
11+
- kubeapilinter # linter for Kube API conventions
12+
settings:
13+
custom:
14+
kubeapilinter:
15+
type: "module"
16+
description: Kube API LInter lints Kube like APIs based on API conventions and best practices.
17+
settings:
18+
linters:
19+
enable:
20+
- "commentstart"
21+
disable:
22+
- "*"
23+
lintersConfig: { }
24+
exclusions:
25+
rules:
26+
- path-except: "^api/"
27+
linters:
28+
- kubeapilinter
29+
issues:
30+
max-issues-per-linter: 0
31+
max-same-issues: 0
32+
new: false

Makefile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ gosec: ## Run gosec against code.
129129

130130
.PHONY: lint
131131
lint: ## Run lint against code.
132-
docker run --rm -w /workdir -v $(PWD):/workdir golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) golangci-lint run -c .golangci.yml --fix
132+
$(GOLANGCI_LINT) run -c .golangci.yml
133+
134+
.PHONY: lint
135+
lint-api: golangci-lint-kal ## Run lint against code.
136+
$(GOLANGCI_LINT_KAL) run -c .golangci-kal.yml
133137

134138
.PHONY: nilcheck
135139
nilcheck: nilaway ## Run nil check against code.
@@ -356,6 +360,8 @@ NILAWAY ?= $(LOCALBIN)/nilaway
356360
GOVULNC ?= $(LOCALBIN)/govulncheck
357361
MOCKGEN ?= $(LOCALBIN)/mockgen
358362
GOWRAP ?= $(CACHE_BIN)/gowrap
363+
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
364+
GOLANGCI_LINT_KAL ?= $(CACHE_BIN)/golangci-lint-kube-api-linter
359365
S5CMD ?= $(CACHE_BIN)/s5cmd
360366

361367
## Tool Versions
@@ -450,12 +456,15 @@ envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
450456
$(ENVTEST): $(CACHE_BIN)
451457
GOBIN=$(CACHE_BIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
452458

453-
.PHONY: husky
454-
husky: $(HUSKY) ## Download husky locally if necessary.
455-
@echo Execute install command to enable git hooks: ./bin/husky install
456-
@echo Set any value for SKIP_GIT_PUSH_HOOK env variable to skip git hook execution.
457-
$(HUSKY): $(LOCALBIN)
458-
GOBIN=$(LOCALBIN) go install github.com/automation-co/husky@$(HUSKY_VERSION)
459+
.phony: golangci-lint
460+
golangci-lint: $(GOLANGCI_LINT)
461+
$(GOLANGCI_LINT): # Build golangci-lint from tools folder.
462+
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
463+
464+
.phony: golangci-lint-kal
465+
golangci-lint-kal: $(GOLANGCI_LINT_KAL)
466+
$(GOLANGCI_LINT_KAL): $(GOLANGCI_LINT) # Build golangci-lint-kal from custom configuration.
467+
$(GOLANGCI_LINT) custom
459468

460469
.PHONY: nilaway
461470
nilaway: $(NILAWAY) ## Download nilaway locally if necessary.

api/v1alpha2/addressset_types.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import (
2222

2323
// AddressSetSpec defines the desired state of AddressSet
2424
type AddressSetSpec struct {
25+
// ipv4 defines a list of IPv4 address strings
2526
IPv4 *[]string `json:"ipv4,omitempty"`
27+
// ipv6 defines a list of IPv6 address strings
2628
IPv6 *[]string `json:"ipv6,omitempty"`
2729
}
2830

@@ -37,20 +39,24 @@ type AddressSetStatus struct {
3739

3840
// AddressSet is the Schema for the addresssets API
3941
type AddressSet struct {
40-
metav1.TypeMeta `json:",inline"`
42+
metav1.TypeMeta `json:",inline"`
43+
// metadata is the standard object's metadata.
4144
metav1.ObjectMeta `json:"metadata,omitempty"`
42-
43-
Spec AddressSetSpec `json:"spec,omitempty"`
45+
// spec is the desired state of the AddressSet
46+
Spec AddressSetSpec `json:"spec,omitempty"`
47+
// status is the observed state of the AddressSet
4448
Status AddressSetStatus `json:"status,omitempty"`
4549
}
4650

47-
//+kubebuilder:object:root=true
51+
// +kubebuilder:object:root=true
4852

4953
// AddressSetList contains a list of AddressSet
5054
type AddressSetList struct {
5155
metav1.TypeMeta `json:",inline"`
56+
// metadata is the standard object's metadata.
5257
metav1.ListMeta `json:"metadata,omitempty"`
53-
Items []AddressSet `json:"items"`
58+
// items is a list of AddressSet
59+
Items []AddressSet `json:"items"`
5460
}
5561

5662
func init() {

api/v1alpha2/firewallrule_types.go

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,60 +22,67 @@ import (
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
)
2424

25-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
26-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
27-
28-
// FirewallRuleSpec defines the desired state of FirewallRule
25+
// FirewallRuleSpec defines the desired state of FirewallRule.
2926
type FirewallRuleSpec struct {
30-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
31-
// Important: Run "make" to regenerate code after modifying this file
32-
Action string `json:"action"`
33-
Label string `json:"label"`
27+
// action is the action to take when the rule matches.
28+
Action string `json:"action"`
29+
// label is the label of the rule.
30+
Label string `json:"label"`
31+
// description is the description of the rule.
3432
Description string `json:"description,omitempty"`
35-
Ports string `json:"ports,omitempty"`
33+
// ports is the ports to apply the rule to.
34+
Ports string `json:"ports,omitempty"`
35+
// protocol is the protocol to apply the rule to.
3636
// +kubebuilder:validation:Enum=TCP;UDP;ICMP;IPENCAP
37-
Protocol linodego.NetworkProtocol `json:"protocol"`
38-
Addresses *NetworkAddresses `json:"addresses,omitempty"`
39-
// AddressSetRefs is a list of references to AddressSets as an alternative to
40-
// using Addresses but can be used in conjunction with it
37+
Protocol linodego.NetworkProtocol `json:"protocol"`
38+
// addresses is a list of addresses to apply the rule to.
39+
Addresses *NetworkAddresses `json:"addresses,omitempty"`
40+
// addressSetRefs is a list of references to AddressSets as an alternative to
41+
// using Addresses but can be used in conjunction with it.
4142
AddressSetRefs []*corev1.ObjectReference `json:"addressSetRefs,omitempty"`
4243
}
4344

44-
// NetworkAddresses holds a list of IPv4 and IPv6 addresses
45+
// NetworkAddresses holds a list of IPv4 and IPv6 addresses.
4546
// We don't use linodego here since kubebuilder can't generate DeepCopyInto
4647
// for linodego.NetworkAddresses
4748
type NetworkAddresses struct {
49+
// ipv4 defines a list of IPv4 address strings.
4850
IPv4 *[]string `json:"ipv4,omitempty"`
51+
// ipv6 defines a list of IPv6 address strings.
4952
IPv6 *[]string `json:"ipv6,omitempty"`
5053
}
5154

52-
// FirewallRuleStatus defines the observed state of FirewallRule
55+
// FirewallRuleStatus defines the observed state of FirewallRule.
5356
type FirewallRuleStatus struct {
5457
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
5558
// Important: Run "make" to regenerate code after modifying this file
5659
}
5760

58-
//+kubebuilder:object:root=true
59-
//+kubebuilder:resource:path=firewallrules,scope=Namespaced,categories=cluster-api,shortName=fwr
60-
//+kubebuilder:subresource:status
61+
// +kubebuilder:object:root=true
62+
// +kubebuilder:resource:path=firewallrules,scope=Namespaced,categories=cluster-api,shortName=fwr
63+
// +kubebuilder:subresource:status
6164
// +kubebuilder:metadata:labels="clusterctl.cluster.x-k8s.io/move-hierarchy=true"
6265

6366
// FirewallRule is the Schema for the firewallrules API
6467
type FirewallRule struct {
65-
metav1.TypeMeta `json:",inline"`
68+
metav1.TypeMeta `json:",inline"`
69+
// metadata is the standard object's metadata.
6670
metav1.ObjectMeta `json:"metadata,omitempty"`
67-
68-
Spec FirewallRuleSpec `json:"spec,omitempty"`
71+
// spec is the desired state of the FirewallRule.
72+
Spec FirewallRuleSpec `json:"spec,omitempty"`
73+
// status is the observed state of the FirewallRule.
6974
Status FirewallRuleStatus `json:"status,omitempty"`
7075
}
7176

72-
//+kubebuilder:object:root=true
77+
// +kubebuilder:object:root=true
7378

7479
// FirewallRuleList contains a list of FirewallRule
7580
type FirewallRuleList struct {
7681
metav1.TypeMeta `json:",inline"`
82+
// metadata is the standard object's metadata.
7783
metav1.ListMeta `json:"metadata,omitempty"`
78-
Items []FirewallRule `json:"items"`
84+
// items is a list of FirewallRule.
85+
Items []FirewallRule `json:"items"`
7986
}
8087

8188
func init() {

0 commit comments

Comments
 (0)