Skip to content

Commit 7931667

Browse files
committed
enable optionalorrequired linter
Signed-off-by: sivchari <[email protected]>
1 parent bfb2649 commit 7931667

31 files changed

+365
-34
lines changed

.golangci-kal.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ linters-settings:
2525
- "nofloats" # Ensure floats are not used.
2626
- "requiredfields" # Required fields should not be pointers, and should not have `omitempty`.
2727
- "statussubresource" # All root objects that have a `status` field should have a status subresource.
28+
- "optionalorrequired" # Every field should be marked as `+optional` or `+required`.
2829

2930
# Per discussion in July 2024, we are keeping phase fields for now.
3031
# See https://github.com/kubernetes-sigs/cluster-api/pull/10897#discussion_r1685929508
3132
# and https://github.com/kubernetes-sigs/cluster-api/pull/10897#discussion_r1685919394.
3233
# - "nophase" # Phase fields are discouraged by the Kube API conventions, use conditions instead.
3334

3435
# Linters below this line are disabled, pending conversation on how and when to enable them.
35-
# - "optionalorrequired" # Every field should be marked as `+optional` or `+required`.
3636
disable:
3737
- "*" # We will manually enable new linters after understanding the impact. Disable all by default.
3838
lintersConfig:
@@ -87,3 +87,12 @@ issues:
8787
text: "field (XPreserveUnknownFields|XPreserveUnknownFields|XValidations|XMetadata|XIntOrString) json tag does not match pattern"
8888
linters:
8989
- kal
90+
# The following rules are disabled until we migrate to the new API.
91+
- path: "bootstrap/kubeadm/api/v1beta1/kubeadm_types.go"
92+
text: "field Token is marked as required, should not be a pointer"
93+
linters:
94+
- kal
95+
- path: "api/v1beta1/clusterclass_types.go"
96+
text: "field Ref is marked as required, should not be a pointer"
97+
linters:
98+
- kal

api/v1beta1/cluster_types.go

+16
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ type ClusterAvailabilityGate struct {
519519
// Topology encapsulates the information of the managed resources.
520520
type Topology struct {
521521
// class is the name of the ClusterClass object to create the topology.
522+
// +required
522523
Class string `json:"class"`
523524

524525
// classNamespace is the namespace of the ClusterClass object to create the topology.
@@ -531,6 +532,7 @@ type Topology struct {
531532
ClassNamespace string `json:"classNamespace,omitempty"`
532533

533534
// version is the Kubernetes version of the cluster.
535+
// +required
534536
Version string `json:"version"`
535537

536538
// rolloutAfter performs a rollout of the entire cluster one component at a time,
@@ -644,12 +646,14 @@ type MachineDeploymentTopology struct {
644646
// class is the name of the MachineDeploymentClass used to create the set of worker nodes.
645647
// This should match one of the deployment classes defined in the ClusterClass object
646648
// mentioned in the `Cluster.Spec.Class` field.
649+
// +required
647650
Class string `json:"class"`
648651

649652
// name is the unique identifier for this MachineDeploymentTopology.
650653
// The value is used with other unique identifiers to create a MachineDeployment's Name
651654
// (e.g. cluster's name, etc). In case the name is greater than the allowed maximum length,
652655
// the values are hashed together.
656+
// +required
653657
Name string `json:"name"`
654658

655659
// failureDomain is the failure domain the machines will be created in.
@@ -747,12 +751,14 @@ type MachinePoolTopology struct {
747751
// class is the name of the MachinePoolClass used to create the pool of worker nodes.
748752
// This should match one of the deployment classes defined in the ClusterClass object
749753
// mentioned in the `Cluster.Spec.Class` field.
754+
// +required
750755
Class string `json:"class"`
751756

752757
// name is the unique identifier for this MachinePoolTopology.
753758
// The value is used with other unique identifiers to create a MachinePool's Name
754759
// (e.g. cluster's name, etc). In case the name is greater than the allowed maximum length,
755760
// the values are hashed together.
761+
// +required
756762
Name string `json:"name"`
757763

758764
// failureDomains is the list of failure domains the machine pool will be created in.
@@ -800,6 +806,7 @@ type MachinePoolTopology struct {
800806
// Variable definition in the ClusterClass `status` variables.
801807
type ClusterVariable struct {
802808
// name of the variable.
809+
// +required
803810
Name string `json:"name"`
804811

805812
// definitionFrom specifies where the definition of this Variable is from.
@@ -816,6 +823,7 @@ type ClusterVariable struct {
816823
// hard-coded schema for apiextensionsv1.JSON which cannot be produced by another type via controller-tools,
817824
// i.e. it is not possible to have no type field.
818825
// Ref: https://github.com/kubernetes-sigs/controller-tools/blob/d0e03a142d0ecdd5491593e941ee1d6b5d91dba6/pkg/crd/known_types.go#L106-L111
826+
// +required
819827
Value apiextensionsv1.JSON `json:"value"`
820828
}
821829

@@ -878,6 +886,7 @@ type ClusterNetwork struct {
878886
// NetworkRanges represents ranges of network addresses.
879887
type NetworkRanges struct {
880888
// cidrBlocks is a list of CIDR blocks.
889+
// +required
881890
CIDRBlocks []string `json:"cidrBlocks"`
882891
}
883892

@@ -1043,9 +1052,11 @@ func (c *ClusterStatus) GetTypedPhase() ClusterPhase {
10431052
// APIEndpoint represents a reachable Kubernetes API endpoint.
10441053
type APIEndpoint struct {
10451054
// host is the hostname on which the API server is serving.
1055+
// +required
10461056
Host string `json:"host"`
10471057

10481058
// port is the port on which the API server is serving.
1059+
// +required
10491060
Port int32 `json:"port"`
10501061
}
10511062

@@ -1080,11 +1091,14 @@ type Cluster struct {
10801091
metav1.TypeMeta `json:",inline"`
10811092
// metadata is the standard object's metadata.
10821093
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
1094+
// +optional
10831095
metav1.ObjectMeta `json:"metadata,omitempty"`
10841096

10851097
// spec is the desired state of Cluster.
1098+
// +optional
10861099
Spec ClusterSpec `json:"spec,omitempty"`
10871100
// status is the observed state of Cluster.
1101+
// +optional
10881102
Status ClusterStatus `json:"status,omitempty"`
10891103
}
10901104

@@ -1218,8 +1232,10 @@ type ClusterList struct {
12181232
metav1.TypeMeta `json:",inline"`
12191233
// metadata is the standard list's metadata.
12201234
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#lists-and-simple-kinds
1235+
// +optional
12211236
metav1.ListMeta `json:"metadata,omitempty"`
12221237
// items is the list of Clusters.
1238+
// +optional
12231239
Items []Cluster `json:"items"`
12241240
}
12251241

api/v1beta1/clusterclass_types.go

+37
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ type ClusterClass struct {
7575
metav1.TypeMeta `json:",inline"`
7676
// metadata is the standard object's metadata.
7777
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
78+
// +optional
7879
metav1.ObjectMeta `json:"metadata,omitempty"`
7980

8081
// spec is the desired state of ClusterClass.
82+
// +optional
8183
Spec ClusterClassSpec `json:"spec,omitempty"`
8284
// status is the observed state of ClusterClass.
85+
// +optional
8386
Status ClusterClassStatus `json:"status,omitempty"`
8487
}
8588

@@ -251,10 +254,12 @@ type MachineDeploymentClass struct {
251254
// class denotes a type of worker node present in the cluster,
252255
// this name MUST be unique within a ClusterClass and can be referenced
253256
// in the Cluster to create a managed MachineDeployment.
257+
// +required
254258
Class string `json:"class"`
255259

256260
// template is a local struct containing a collection of templates for creation of
257261
// MachineDeployment objects representing a set of worker nodes.
262+
// +required
258263
Template MachineDeploymentClassTemplate `json:"template"`
259264

260265
// machineHealthCheck defines a MachineHealthCheck for this MachineDeploymentClass.
@@ -296,6 +301,7 @@ type MachineDeploymentClass struct {
296301
// Defaults to 0 (machine will be considered available as soon as it
297302
// is ready)
298303
// NOTE: This value can be overridden while defining a Cluster.Topology using this MachineDeploymentClass.
304+
// +optional
299305
MinReadySeconds *int32 `json:"minReadySeconds,omitempty"`
300306

301307
// readinessGates specifies additional conditions to include when evaluating Machine Ready condition.
@@ -315,6 +321,7 @@ type MachineDeploymentClass struct {
315321
// strategy is the deployment strategy to use to replace existing machines with
316322
// new ones.
317323
// NOTE: This value can be overridden while defining a Cluster.Topology using this MachineDeploymentClass.
324+
// +optional
318325
Strategy *MachineDeploymentStrategy `json:"strategy,omitempty"`
319326
}
320327

@@ -328,10 +335,12 @@ type MachineDeploymentClassTemplate struct {
328335

329336
// bootstrap contains the bootstrap template reference to be used
330337
// for the creation of worker Machines.
338+
// +required
331339
Bootstrap LocalObjectTemplate `json:"bootstrap"`
332340

333341
// infrastructure contains the infrastructure template reference to be used
334342
// for the creation of worker Machines.
343+
// +required
335344
Infrastructure LocalObjectTemplate `json:"infrastructure"`
336345
}
337346

@@ -405,10 +414,12 @@ type MachinePoolClass struct {
405414
// class denotes a type of machine pool present in the cluster,
406415
// this name MUST be unique within a ClusterClass and can be referenced
407416
// in the Cluster to create a managed MachinePool.
417+
// +required
408418
Class string `json:"class"`
409419

410420
// template is a local struct containing a collection of templates for creation of
411421
// MachinePools objects representing a pool of worker nodes.
422+
// +required
412423
Template MachinePoolClassTemplate `json:"template"`
413424

414425
// failureDomains is the list of failure domains the MachinePool should be attached to.
@@ -446,6 +457,7 @@ type MachinePoolClass struct {
446457
// Defaults to 0 (machine will be considered available as soon as it
447458
// is ready)
448459
// NOTE: This value can be overridden while defining a Cluster.Topology using this MachinePoolClass.
460+
// +optional
449461
MinReadySeconds *int32 `json:"minReadySeconds,omitempty"`
450462
}
451463

@@ -459,10 +471,12 @@ type MachinePoolClassTemplate struct {
459471

460472
// bootstrap contains the bootstrap template reference to be used
461473
// for the creation of the Machines in the MachinePool.
474+
// +required
462475
Bootstrap LocalObjectTemplate `json:"bootstrap"`
463476

464477
// infrastructure contains the infrastructure template reference to be used
465478
// for the creation of the MachinePool.
479+
// +required
466480
Infrastructure LocalObjectTemplate `json:"infrastructure"`
467481
}
468482

@@ -489,12 +503,14 @@ func (m MachineHealthCheckClass) IsZero() bool {
489503
// be configured in the Cluster topology and used in patches.
490504
type ClusterClassVariable struct {
491505
// name of the variable.
506+
// +required
492507
Name string `json:"name"`
493508

494509
// required specifies if the variable is required.
495510
// Note: this applies to the variable as a whole and thus the
496511
// top-level object defined in the schema. If nested fields are
497512
// required, this will be specified inside the schema.
513+
// +required
498514
Required bool `json:"required"`
499515

500516
// metadata is the metadata of a variable.
@@ -507,6 +523,7 @@ type ClusterClassVariable struct {
507523
Metadata ClusterClassVariableMetadata `json:"metadata,omitempty"`
508524

509525
// schema defines the schema of the variable.
526+
// +required
510527
Schema VariableSchema `json:"schema"`
511528
}
512529

@@ -533,6 +550,7 @@ type VariableSchema struct {
533550
// openAPIV3Schema defines the schema of a variable via OpenAPI v3
534551
// schema. The schema is a subset of the schema used in
535552
// Kubernetes CRDs.
553+
// +required
536554
OpenAPIV3Schema JSONSchemaProps `json:"openAPIV3Schema"`
537555
}
538556

@@ -543,9 +561,11 @@ type VariableSchema struct {
543561
// which are not supported in CAPI have been removed.
544562
type JSONSchemaProps struct {
545563
// description is a human-readable description of this variable.
564+
// +optional
546565
Description string `json:"description,omitempty"`
547566

548567
// example is an example for this variable.
568+
// +optional
549569
Example *apiextensionsv1.JSON `json:"example,omitempty"`
550570

551571
// type is the type of the variable.
@@ -862,9 +882,11 @@ const (
862882
// ClusterClassPatch defines a patch which is applied to customize the referenced templates.
863883
type ClusterClassPatch struct {
864884
// name of the patch.
885+
// +required
865886
Name string `json:"name"`
866887

867888
// description is a human-readable description of this patch.
889+
// +optional
868890
Description string `json:"description,omitempty"`
869891

870892
// enabledIf is a Go template to be used to calculate if a patch should be enabled.
@@ -890,11 +912,13 @@ type ClusterClassPatch struct {
890912
// PatchDefinition defines a patch which is applied to customize the referenced templates.
891913
type PatchDefinition struct {
892914
// selector defines on which templates the patch should be applied.
915+
// +required
893916
Selector PatchSelector `json:"selector"`
894917

895918
// jsonPatches defines the patches which should be applied on the templates
896919
// matching the selector.
897920
// Note: Patches will be applied in the order of the array.
921+
// +required
898922
JSONPatches []JSONPatch `json:"jsonPatches"`
899923
}
900924

@@ -905,12 +929,15 @@ type PatchDefinition struct {
905929
// Note: The results of selection based on the individual fields are ANDed.
906930
type PatchSelector struct {
907931
// apiVersion filters templates by apiVersion.
932+
// +required
908933
APIVersion string `json:"apiVersion"`
909934

910935
// kind filters templates by kind.
936+
// +required
911937
Kind string `json:"kind"`
912938

913939
// matchResources selects templates based on where they are referenced.
940+
// +required
914941
MatchResources PatchSelectorMatch `json:"matchResources"`
915942
}
916943

@@ -959,13 +986,15 @@ type PatchSelectorMatchMachinePoolClass struct {
959986
type JSONPatch struct {
960987
// op defines the operation of the patch.
961988
// Note: Only `add`, `replace` and `remove` are supported.
989+
// +required
962990
Op string `json:"op"`
963991

964992
// path defines the path of the patch.
965993
// Note: Only the spec of a template can be patched, thus the path has to start with /spec/.
966994
// Note: For now the only allowed array modifications are `append` and `prepend`, i.e.:
967995
// * for op: `add`: only index 0 (prepend) and - (append) are allowed
968996
// * for op: `replace` or `remove`: no indexes are allowed
997+
// +required
969998
Path string `json:"path"`
970999

9711000
// value defines the value of the patch.
@@ -1026,6 +1055,7 @@ type ExternalPatchDefinition struct {
10261055
type LocalObjectTemplate struct {
10271056
// ref is a required reference to a custom resource
10281057
// offered by a provider.
1058+
// +required
10291059
Ref *corev1.ObjectReference `json:"ref"`
10301060
}
10311061

@@ -1065,13 +1095,15 @@ type ClusterClassV1Beta2Status struct {
10651095
// ClusterClassStatusVariable defines a variable which appears in the status of a ClusterClass.
10661096
type ClusterClassStatusVariable struct {
10671097
// name is the name of the variable.
1098+
// +required
10681099
Name string `json:"name"`
10691100

10701101
// definitionsConflict specifies whether or not there are conflicting definitions for a single variable name.
10711102
// +optional
10721103
DefinitionsConflict bool `json:"definitionsConflict"`
10731104

10741105
// definitions is a list of definitions for a variable.
1106+
// +required
10751107
Definitions []ClusterClassStatusVariableDefinition `json:"definitions"`
10761108
}
10771109

@@ -1080,12 +1112,14 @@ type ClusterClassStatusVariableDefinition struct {
10801112
// from specifies the origin of the variable definition.
10811113
// This will be `inline` for variables defined in the ClusterClass or the name of a patch defined in the ClusterClass
10821114
// for variables discovered from a DiscoverVariables runtime extensions.
1115+
// +required
10831116
From string `json:"from"`
10841117

10851118
// required specifies if the variable is required.
10861119
// Note: this applies to the variable as a whole and thus the
10871120
// top-level object defined in the schema. If nested fields are
10881121
// required, this will be specified inside the schema.
1122+
// +required
10891123
Required bool `json:"required"`
10901124

10911125
// metadata is the metadata of a variable.
@@ -1098,6 +1132,7 @@ type ClusterClassStatusVariableDefinition struct {
10981132
Metadata ClusterClassVariableMetadata `json:"metadata,omitempty"`
10991133

11001134
// schema defines the schema of the variable.
1135+
// +required
11011136
Schema VariableSchema `json:"schema"`
11021137
}
11031138

@@ -1136,8 +1171,10 @@ type ClusterClassList struct {
11361171
metav1.TypeMeta `json:",inline"`
11371172
// metadata is the standard list's metadata.
11381173
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#lists-and-simple-kinds
1174+
// +optional
11391175
metav1.ListMeta `json:"metadata,omitempty"`
11401176
// items is the list of ClusterClasses.
1177+
// +optional
11411178
Items []ClusterClass `json:"items"`
11421179
}
11431180

api/v1beta1/common_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,11 @@ const (
284284
// MachineAddress contains information for the node's address.
285285
type MachineAddress struct {
286286
// type is the machine address type, one of Hostname, ExternalIP, InternalIP, ExternalDNS or InternalDNS.
287+
// +required
287288
Type MachineAddressType `json:"type"`
288289

289290
// address is the machine address.
291+
// +required
290292
Address string `json:"address"`
291293
}
292294

0 commit comments

Comments
 (0)