Skip to content

Commit fdf4db6

Browse files
committed
Enable KAL linter
Signed-off-by: Prajyot-Parab <prajyot.parab2@ibm.com>
1 parent 8e88e79 commit fdf4db6

16 files changed

+310
-197
lines changed

.golangci-kal.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
version: "2"
2+
run:
3+
go: "1.24"
4+
allow-parallel-runners: true
5+
linters:
6+
default: none
7+
enable:
8+
- kubeapilinter # linter for Kube API conventions
9+
settings:
10+
custom:
11+
kubeapilinter:
12+
type: module
13+
description: KAL is the Kube-API-Linter and lints Kube like APIs based on API conventions and best practices.
14+
settings:
15+
linters:
16+
enable:
17+
- "commentstart" # Ensure comments start with the serialized version of the field name.
18+
- "conditions" # Ensure conditions have the correct json tags and markers.
19+
- "conflictingmarkers"
20+
- "duplicatemarkers" # Ensure there are no exact duplicate markers. for types and fields.
21+
- "integers" # Ensure only int32 and int64 are used for integers.
22+
- "jsontags" # Ensure every field has a json tag.
23+
- "nodurations" # Prevents usage of `Duration` types.
24+
- "nofloats" # Ensure floats are not used.
25+
- "nonullable" # Ensure that types and fields do not have the nullable marker.
26+
- "notimestamp" # Prevents usage of 'Timestamp' fields
27+
- "statussubresource" # All root objects that have a `status` field should have a status subresource.
28+
- "uniquemarkers" # Ensure that types and fields do not contain more than a single definition of a marker that should only be present once.
29+
30+
# Linters below this line are disabled, pending conversation on how and when to enable them.
31+
disable:
32+
- "*" # We will manually enable new linters after understanding the impact. Disable all by default.
33+
34+
lintersConfig:
35+
conflictingmarkers:
36+
conflicts:
37+
- name: "default_vs_required"
38+
sets:
39+
- ["default", "kubebuilder:default"]
40+
- ["required", "kubebuilder:validation:Required", "k8s:required"]
41+
description: "A field with a default value cannot be required"
42+
conditions:
43+
isFirstField: Warn # Require conditions to be the first field in the status struct.
44+
usePatchStrategy: Forbid # Forbid patchStrategy markers on the Conditions field.
45+
useProtobuf: Forbid # We don't use protobuf, so protobuf tags are not required.
46+
47+
exclusions:
48+
generated: strict
49+
paths:
50+
- zz_generated.*\.go$
51+
- vendored_openapi\.go$
52+
- ".*_test.go" # Exclude test files.
53+
rules:
54+
## KAL should only run on API folders.
55+
- path-except: "api//*"
56+
linters:
57+
- kubeapilinter
58+
59+
## Excludes for old apiVersions that can be removed once the apiVersions are dropped (we don't want to make any changes to these APIs).
60+
- path: "api/powervs/v1beta2"
61+
linters:
62+
- kubeapilinter
63+
64+
## Excludes for VPC apiVersions.
65+
- path: "api/vpc"
66+
linters:
67+
- kubeapilinter
68+
69+
## Exclude deprecated v1beta2 status structs from conditions linter (backward compatibility)
70+
- text: "Conditions field in .*V1Beta2DeprecatedStatus must be a slice of metav1.Condition"
71+
linters:
72+
- kubeapilinter
73+
74+
issues:
75+
max-same-issues: 0
76+
max-issues-per-linter: 0

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ TEMPLATES_DIR := $(REPO_ROOT)/templates
3838

3939
GO_APIDIFF := $(TOOLS_BIN_DIR)/go-apidiff
4040
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
41+
GOLANGCI_LINT_KAL := $(TOOLS_BIN_DIR)/golangci-lint-kube-api-linter
4142
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
4243
GOJQ := $(TOOLS_BIN_DIR)/gojq
4344
CONVERSION_GEN := $(TOOLS_BIN_DIR)/conversion-gen
@@ -502,6 +503,14 @@ lint: $(GOLANGCI_LINT) ## Lint codebase
502503
lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter
503504
GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE) lint
504505

506+
.PHONY: lint-api
507+
lint-api: $(GOLANGCI_LINT_KAL)
508+
$(GOLANGCI_LINT_KAL) run -v --config ./.golangci-kal.yml $(GOLANGCI_LINT_EXTRA_ARGS)
509+
510+
.PHONY: lint-api-fix
511+
lint-api-fix: $(GOLANGCI_LINT_KAL)
512+
GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE) lint-api
513+
505514
APIDIFF_OLD_COMMIT ?= $(shell git rev-parse origin/main)
506515

507516
.PHONY: apidiff

api/powervs/v1beta3/ibmpowervscluster_types.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ func init() {
3535

3636
// IBMPowerVSClusterSpec defines the desired state of IBMPowerVSCluster.
3737
type IBMPowerVSClusterSpec struct {
38-
// Deprecated: use ServiceInstance instead
38+
// serviceInstanceID is the id of the power cloud instance where the vsi instance will get deployed.
3939
//
40-
// ServiceInstanceID is the id of the power cloud instance where the vsi instance will get deployed.
40+
// Deprecated: use ServiceInstance instead
4141
ServiceInstanceID string `json:"serviceInstanceID"`
4242

43-
// Network is the reference to the Network to use for this cluster.
43+
// network is the reference to the Network to use for this cluster.
4444
// when the field is omitted, A DHCP service will be created in the Power VS workspace and its private network will be used.
4545
// the DHCP service created network will have the following name format
4646
// 1. in the case of DHCPServer.Name is not set the name will be DHCPSERVER<CLUSTER_NAME>_Private.
@@ -56,7 +56,7 @@ type IBMPowerVSClusterSpec struct {
5656
// +optional
5757
DHCPServer *DHCPServer `json:"dhcpServer,omitempty"`
5858

59-
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
59+
// controlPlaneEndpoint represents the endpoint used to communicate with the control plane.
6060
// +optional
6161
ControlPlaneEndpoint clusterv1beta1.APIEndpoint `json:"controlPlaneEndpoint"`
6262

@@ -108,7 +108,7 @@ type IBMPowerVSClusterSpec struct {
108108
// +optional
109109
VPCSubnets []Subnet `json:"vpcSubnets,omitempty"`
110110

111-
// VPCSecurityGroups to attach it to the VPC resource
111+
// vpcSecurityGroups to attach it to the VPC resource
112112
// +optional
113113
VPCSecurityGroups []VPCSecurityGroup `json:"vpcSecurityGroups,omitempty"`
114114

@@ -141,14 +141,15 @@ type IBMPowerVSClusterSpec struct {
141141
// +optional
142142
CosInstance *CosInstance `json:"cosInstance,omitempty"`
143143

144-
// Ignition defined options related to the bootstrapping systems where Ignition is used.
144+
// ignition defined options related to the bootstrapping systems where Ignition is used.
145145
// +optional
146146
Ignition *Ignition `json:"ignition,omitempty"`
147147
}
148148

149149
// IBMPowerVSClusterStatus defines the observed state of IBMPowerVSCluster.
150150
type IBMPowerVSClusterStatus struct {
151151
// conditions represents the observations of a IBMPowerVSCluster's current state.
152+
// +optional
152153
// +listType=map
153154
// +listMapKey=type
154155
// +kubebuilder:validation:MaxItems=32
@@ -158,13 +159,13 @@ type IBMPowerVSClusterStatus struct {
158159
// +kubebuilder:default=false
159160
Ready bool `json:"ready"`
160161

161-
// ResourceGroup is the reference to the Power VS resource group under which the resources will be created.
162+
// resourceGroupID is the reference to the Power VS resource group under which the resources will be created.
162163
ResourceGroup *ResourceReference `json:"resourceGroupID,omitempty"`
163164

164165
// serviceInstance is the reference to the Power VS service on which the server instance(VM) will be created.
165166
ServiceInstance *ResourceReference `json:"serviceInstance,omitempty"`
166167

167-
// networkID is the reference to the Power VS network to use for this cluster.
168+
// network is the reference to the Power VS network to use for this cluster.
168169
Network *ResourceReference `json:"network,omitempty"`
169170

170171
// dhcpServer is the reference to the Power VS DHCP server.
@@ -231,20 +232,20 @@ type IBMPowerVSClusterList struct {
231232

232233
// DHCPServer contains the DHCP server configurations.
233234
type DHCPServer struct {
234-
// Optional cidr for DHCP private network
235+
// cidr for DHCP private network
235236
Cidr *string `json:"cidr,omitempty"`
236237

237-
// Optional DNS Server for DHCP service
238+
// dnsServer for DHCP service
238239
// +kubebuilder:default="1.1.1.1"
239240
DNSServer *string `json:"dnsServer,omitempty"`
240241

241-
// Optional name of DHCP Service. Only alphanumeric characters and dashes are allowed.
242+
// name of DHCP Service. Only alphanumeric characters and dashes are allowed.
242243
Name *string `json:"name,omitempty"`
243244

244-
// Optional id of the existing DHCPServer
245+
// id of the existing DHCPServer
245246
ID *string `json:"id,omitempty"`
246247

247-
// Optional indicates if SNAT will be enabled for DHCP service
248+
// snat indicates if SNAT will be enabled for DHCP service
248249
// +kubebuilder:default=true
249250
Snat *bool `json:"snat,omitempty"`
250251
}
@@ -309,7 +310,7 @@ type CosInstance struct {
309310

310311
// Ignition defines options related to the bootstrapping systems where Ignition is used.
311312
type Ignition struct {
312-
// Version defines which version of Ignition will be used to generate bootstrap data.
313+
// version defines which version of Ignition will be used to generate bootstrap data.
313314
//
314315
// +optional
315316
// +kubebuilder:default="2.3"
@@ -321,17 +322,17 @@ type Ignition struct {
321322
type ResourceReference struct {
322323
// id represents the id of the resource.
323324
ID *string `json:"id,omitempty"`
324-
// +kubebuilder:default=false
325325
// controllerCreated indicates whether the resource is created by the controller.
326+
// +kubebuilder:default=false
326327
ControllerCreated *bool `json:"controllerCreated,omitempty"`
327328
}
328329

329330
// TransitGatewayStatus defines the status of transit gateway as well as it's connection's status.
330331
type TransitGatewayStatus struct {
331332
// id represents the id of the resource.
332333
ID *string `json:"id,omitempty"`
333-
// +kubebuilder:default=false
334334
// controllerCreated indicates whether the resource is created by the controller.
335+
// +kubebuilder:default=false
335336
ControllerCreated *bool `json:"controllerCreated,omitempty"`
336337
// vpcConnection defines the vpc connection status in transit gateway.
337338
VPCConnection *ResourceReference `json:"vpcConnection,omitempty"`

api/powervs/v1beta3/ibmpowervsclustertemplate_types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func init() {
2828

2929
// IBMPowerVSClusterTemplateSpec defines the desired state of IBMPowerVSClusterTemplate.
3030
type IBMPowerVSClusterTemplateSpec struct {
31+
// template is the IBMPowerVSClusterTemplateResource.
3132
Template IBMPowerVSClusterTemplateResource `json:"template"`
3233
}
3334

@@ -60,9 +61,10 @@ type IBMPowerVSClusterTemplateList struct {
6061

6162
// IBMPowerVSClusterTemplateResource describes the data needed to create an IBMPowerVSCluster from a template.
6263
type IBMPowerVSClusterTemplateResource struct {
63-
// Standard object's metadata.
64+
// metadata is the standard object's metadata.
6465
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
6566
// +optional
6667
ObjectMeta clusterv1beta1.ObjectMeta `json:"metadata,omitempty"`
67-
Spec IBMPowerVSClusterSpec `json:"spec"`
68+
// spec is the IBMPowerVSClusterSpec.
69+
Spec IBMPowerVSClusterSpec `json:"spec"`
6870
}

api/powervs/v1beta3/ibmpowervsimage_types.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ func init() {
3434

3535
// IBMPowerVSImageSpec defines the desired state of IBMPowerVSImage.
3636
type IBMPowerVSImageSpec struct {
37-
// ClusterName is the name of the Cluster this object belongs to.
37+
// clusterName is the name of the Cluster this object belongs to.
3838
// +kubebuilder:validation:MinLength=1
3939
ClusterName string `json:"clusterName"`
4040

41-
// Deprecated: use ServiceInstance instead
41+
// serviceInstanceID is the id of the power cloud instance where the image will get imported.
4242
//
43-
// ServiceInstanceID is the id of the power cloud instance where the image will get imported.
43+
// Deprecated: use ServiceInstance instead
4444
ServiceInstanceID string `json:"serviceInstanceID"`
4545

4646
// serviceInstance is the reference to the Power VS workspace on which the server instance(VM) will be created.
@@ -53,22 +53,22 @@ type IBMPowerVSImageSpec struct {
5353
// +optional
5454
ServiceInstance *IBMPowerVSResourceReference `json:"serviceInstance,omitempty"`
5555

56-
// Cloud Object Storage bucket name; bucket-name[/optional/folder]
56+
// bucket is the Cloud Object Storage bucket name; bucket-name[/optional/folder]
5757
Bucket *string `json:"bucket"`
5858

59-
// Cloud Object Storage image filename.
59+
// object is the Cloud Object Storage image filename.
6060
Object *string `json:"object"`
6161

62-
// Cloud Object Storage region.
62+
// region is the Cloud Object Storage region.
6363
Region *string `json:"region"`
6464

65-
// Type of storage, storage pool with the most available space will be selected.
65+
// storageType is the type of storage, storage pool with the most available space will be selected.
6666
// +kubebuilder:default=tier1
6767
// +kubebuilder:validation:Enum=tier0;tier1;tier3
6868
// +optional
6969
StorageType string `json:"storageType,omitempty"`
7070

71-
// DeletePolicy defines the policy used to identify images to be preserved beyond the lifecycle of associated cluster.
71+
// deletePolicy defines the policy used to identify images to be preserved beyond the lifecycle of associated cluster.
7272
// +kubebuilder:default=delete
7373
// +kubebuilder:validation:Enum=delete;retain
7474
// +optional
@@ -84,18 +84,18 @@ type IBMPowerVSImageStatus struct {
8484
// +kubebuilder:validation:MaxItems=32
8585
Conditions []metav1.Condition `json:"conditions,omitempty"`
8686

87-
// Ready is true when the provider resource is ready.
87+
// ready is true when the provider resource is ready.
8888
// +optional
8989
Ready bool `json:"ready"`
9090

91-
// ImageID is the id of the imported image.
91+
// imageID is the id of the imported image.
9292
ImageID string `json:"imageID,omitempty"`
9393

94-
// ImageState is the status of the imported image.
94+
// imageState is the status of the imported image.
9595
// +optional
9696
ImageState PowerVSImageState `json:"imageState,omitempty"`
9797

98-
// JobID is the job ID of an import operation.
98+
// jobID is the job ID of an import operation.
9999
// +optional
100100
JobID string `json:"jobID,omitempty"`
101101

0 commit comments

Comments
 (0)