Skip to content

Commit e340ae4

Browse files
committed
Add MaxLength markers to API fields
Signed-off-by: Stefan Büringer buringerst@vmware.com
1 parent 346f861 commit e340ae4

File tree

42 files changed

+784
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+784
-6
lines changed

.golangci-kal.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ issues:
7878
text: "maxlength"
7979
linters:
8080
- kal
81-
- path: "api/v1beta1/*"
82-
text: "must have a maximum length, add (kubebuilder:validation:MaxLength|kubebuilder:validation:items:MaxLength) marker"
83-
linters:
84-
- kal
8581
# controller-gen does not allow to add MaxItems to Schemaless fields
8682
- path: "api/v1beta1/*"
8783
text: "maxlength: field (AllOf|OneOf|AnyOf) must have a maximum items, add kubebuilder:validation:MaxItems marker"

api/v1beta1/cluster_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ type ClusterAvailabilityGate struct {
541541
// Topology encapsulates the information of the managed resources.
542542
type Topology struct {
543543
// class is the name of the ClusterClass object to create the topology.
544+
// +kubebuilder:validation:MinLength=1
545+
// +kubebuilder:validation:MaxLength=253
544546
Class string `json:"class"`
545547

546548
// classNamespace is the namespace of the ClusterClass object to create the topology.
@@ -553,6 +555,7 @@ type Topology struct {
553555
ClassNamespace string `json:"classNamespace,omitempty"`
554556

555557
// version is the Kubernetes version of the cluster.
558+
// +kubebuilder:validation:MaxLength=256
556559
Version string `json:"version"`
557560

558561
// rolloutAfter performs a rollout of the entire cluster one component at a time,
@@ -669,17 +672,20 @@ type MachineDeploymentTopology struct {
669672
// class is the name of the MachineDeploymentClass used to create the set of worker nodes.
670673
// This should match one of the deployment classes defined in the ClusterClass object
671674
// mentioned in the `Cluster.Spec.Class` field.
675+
// +kubebuilder:validation:MaxLength=256
672676
Class string `json:"class"`
673677

674678
// name is the unique identifier for this MachineDeploymentTopology.
675679
// The value is used with other unique identifiers to create a MachineDeployment's Name
676680
// (e.g. cluster's name, etc). In case the name is greater than the allowed maximum length,
677681
// the values are hashed together.
682+
// +kubebuilder:validation:MaxLength=256
678683
Name string `json:"name"`
679684

680685
// failureDomain is the failure domain the machines will be created in.
681686
// Must match a key in the FailureDomains map stored on the cluster object.
682687
// +optional
688+
// +kubebuilder:validation:MaxLength=256
683689
FailureDomain *string `json:"failureDomain,omitempty"`
684690

685691
// replicas is the number of worker nodes belonging to this set.
@@ -772,18 +778,21 @@ type MachinePoolTopology struct {
772778
// class is the name of the MachinePoolClass used to create the pool of worker nodes.
773779
// This should match one of the deployment classes defined in the ClusterClass object
774780
// mentioned in the `Cluster.Spec.Class` field.
781+
// +kubebuilder:validation:MaxLength=256
775782
Class string `json:"class"`
776783

777784
// name is the unique identifier for this MachinePoolTopology.
778785
// The value is used with other unique identifiers to create a MachinePool's Name
779786
// (e.g. cluster's name, etc). In case the name is greater than the allowed maximum length,
780787
// the values are hashed together.
788+
// +kubebuilder:validation:MaxLength=256
781789
Name string `json:"name"`
782790

783791
// failureDomains is the list of failure domains the machine pool will be created in.
784792
// Must match a key in the FailureDomains map stored on the cluster object.
785793
// +optional
786794
// +kubebuilder:validation:MaxItems=100
795+
// +kubebuilder:validation:items:MaxLength=256
787796
FailureDomains []string `json:"failureDomains,omitempty"`
788797

789798
// nodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
@@ -826,13 +835,15 @@ type MachinePoolTopology struct {
826835
// Variable definition in the ClusterClass `status` variables.
827836
type ClusterVariable struct {
828837
// name of the variable.
838+
// +kubebuilder:validation:MaxLength=256
829839
Name string `json:"name"`
830840

831841
// definitionFrom specifies where the definition of this Variable is from.
832842
//
833843
// Deprecated: This field is deprecated, must not be set anymore and is going to be removed in the next apiVersion.
834844
//
835845
// +optional
846+
// +kubebuilder:validation:MaxLength=256
836847
DefinitionFrom string `json:"definitionFrom,omitempty"`
837848

838849
// value of the variable.
@@ -897,6 +908,7 @@ type ClusterNetwork struct {
897908

898909
// serviceDomain is the domain name for services.
899910
// +optional
911+
// +kubebuilder:validation:MaxLength=253
900912
ServiceDomain string `json:"serviceDomain,omitempty"`
901913
}
902914

@@ -908,6 +920,7 @@ type ClusterNetwork struct {
908920
type NetworkRanges struct {
909921
// cidrBlocks is a list of CIDR blocks.
910922
// +kubebuilder:validation:MaxItems=100
923+
// +kubebuilder:validation:items:MaxLength=256
911924
CIDRBlocks []string `json:"cidrBlocks"`
912925
}
913926

@@ -943,11 +956,13 @@ type ClusterStatus struct {
943956
// Deprecated: This field is deprecated and is going to be removed in the next apiVersion. Please see https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more details.
944957
//
945958
// +optional
959+
// +kubebuilder:validation:MaxLength=10240
946960
FailureMessage *string `json:"failureMessage,omitempty"`
947961

948962
// phase represents the current phase of cluster actuation.
949963
// E.g. Pending, Running, Terminating, Failed etc.
950964
// +optional
965+
// +kubebuilder:validation:MaxLength=50
951966
Phase string `json:"phase,omitempty"`
952967

953968
// infrastructureReady is the state of the infrastructure provider.
@@ -1073,6 +1088,7 @@ func (c *ClusterStatus) GetTypedPhase() ClusterPhase {
10731088
// APIEndpoint represents a reachable Kubernetes API endpoint.
10741089
type APIEndpoint struct {
10751090
// host is the hostname on which the API server is serving.
1091+
// +kubebuilder:validation:MaxLength=512
10761092
Host string `json:"host"`
10771093

10781094
// port is the port on which the API server is serving.

api/v1beta1/clusterclass_types.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ type ControlPlaneClassNamingStrategy struct {
214214
// * `.cluster.name`: The name of the cluster object.
215215
// * `.random`: A random alphanumeric string, without vowels, of length 5.
216216
// +optional
217+
// +kubebuilder:validation:MaxLength=512
217218
Template *string `json:"template,omitempty"`
218219
}
219220

@@ -227,6 +228,7 @@ type InfrastructureNamingStrategy struct {
227228
// * `.cluster.name`: The name of the cluster object.
228229
// * `.random`: A random alphanumeric string, without vowels, of length 5.
229230
// +optional
231+
// +kubebuilder:validation:MaxLength=512
230232
Template *string `json:"template,omitempty"`
231233
}
232234

@@ -255,6 +257,7 @@ type MachineDeploymentClass struct {
255257
// class denotes a type of worker node present in the cluster,
256258
// this name MUST be unique within a ClusterClass and can be referenced
257259
// in the Cluster to create a managed MachineDeployment.
260+
// +kubebuilder:validation:MaxLength=256
258261
Class string `json:"class"`
259262

260263
// template is a local struct containing a collection of templates for creation of
@@ -269,6 +272,7 @@ type MachineDeploymentClass struct {
269272
// Must match a key in the FailureDomains map stored on the cluster object.
270273
// NOTE: This value can be overridden while defining a Cluster.Topology using this MachineDeploymentClass.
271274
// +optional
275+
// +kubebuilder:validation:MaxLength=256
272276
FailureDomain *string `json:"failureDomain,omitempty"`
273277

274278
// namingStrategy allows changing the naming pattern used when creating the MachineDeployment.
@@ -350,6 +354,7 @@ type MachineDeploymentClassNamingStrategy struct {
350354
// * `.random`: A random alphanumeric string, without vowels, of length 5.
351355
// * `.machineDeployment.topologyName`: The name of the MachineDeployment topology (Cluster.spec.topology.workers.machineDeployments[].name).
352356
// +optional
357+
// +kubebuilder:validation:MaxLength=512
353358
Template *string `json:"template,omitempty"`
354359
}
355360

@@ -377,6 +382,7 @@ type MachineHealthCheckClass struct {
377382
// (b) there are at most 5 unhealthy machines
378383
// +optional
379384
// +kubebuilder:validation:Pattern=^\[[0-9]+-[0-9]+\]$
385+
// +kubebuilder:validation:MaxLength=32
380386
UnhealthyRange *string `json:"unhealthyRange,omitempty"`
381387

382388
// nodeStartupTimeout allows to set the maximum time for MachineHealthCheck
@@ -410,6 +416,7 @@ type MachinePoolClass struct {
410416
// class denotes a type of machine pool present in the cluster,
411417
// this name MUST be unique within a ClusterClass and can be referenced
412418
// in the Cluster to create a managed MachinePool.
419+
// +kubebuilder:validation:MaxLength=256
413420
Class string `json:"class"`
414421

415422
// template is a local struct containing a collection of templates for creation of
@@ -421,6 +428,7 @@ type MachinePoolClass struct {
421428
// NOTE: This value can be overridden while defining a Cluster.Topology using this MachinePoolClass.
422429
// +optional
423430
// +kubebuilder:validation:MaxItems=100
431+
// +kubebuilder:validation:items:MaxLength=256
424432
FailureDomains []string `json:"failureDomains,omitempty"`
425433

426434
// namingStrategy allows changing the naming pattern used when creating the MachinePool.
@@ -483,6 +491,7 @@ type MachinePoolClassNamingStrategy struct {
483491
// * `.random`: A random alphanumeric string, without vowels, of length 5.
484492
// * `.machinePool.topologyName`: The name of the MachinePool topology (Cluster.spec.topology.workers.machinePools[].name).
485493
// +optional
494+
// +kubebuilder:validation:MaxLength=512
486495
Template *string `json:"template,omitempty"`
487496
}
488497

@@ -495,6 +504,7 @@ func (m MachineHealthCheckClass) IsZero() bool {
495504
// be configured in the Cluster topology and used in patches.
496505
type ClusterClassVariable struct {
497506
// name of the variable.
507+
// +kubebuilder:validation:MaxLength=256
498508
Name string `json:"name"`
499509

500510
// required specifies if the variable is required.
@@ -549,6 +559,7 @@ type VariableSchema struct {
549559
// which are not supported in CAPI have been removed.
550560
type JSONSchemaProps struct {
551561
// description is a human-readable description of this variable.
562+
// +kubebuilder:validation:MaxLength=512
552563
Description string `json:"description,omitempty"`
553564

554565
// example is an example for this variable.
@@ -557,6 +568,7 @@ type JSONSchemaProps struct {
557568
// type is the type of the variable.
558569
// Valid values are: object, array, string, integer, number or boolean.
559570
// +optional
571+
// +kubebuilder:validation:MaxLength=16
560572
Type string `json:"type,omitempty"`
561573

562574
// properties specifies fields of an object.
@@ -593,6 +605,7 @@ type JSONSchemaProps struct {
593605
// NOTE: Can only be set if type is object.
594606
// +optional
595607
// +kubebuilder:validation:MaxItems=1000
608+
// +kubebuilder:validation:items:MaxLength=256
596609
Required []string `json:"required,omitempty"`
597610

598611
// items specifies fields of an array.
@@ -624,6 +637,7 @@ type JSONSchemaProps struct {
624637
// https://github.com/kubernetes/apiextensions-apiserver/blob/master/pkg/apiserver/validation/formats.go
625638
// NOTE: Can only be set if type is string.
626639
// +optional
640+
// +kubebuilder:validation:MaxLength=32
627641
Format string `json:"format,omitempty"`
628642

629643
// maxLength is the max length of a string variable.
@@ -639,6 +653,7 @@ type JSONSchemaProps struct {
639653
// pattern is the regex which a string variable must match.
640654
// NOTE: Can only be set if type is string.
641655
// +optional
656+
// +kubebuilder:validation:MaxLength=512
642657
Pattern string `json:"pattern,omitempty"`
643658

644659
// maximum is the maximum of an integer or number variable.
@@ -809,12 +824,14 @@ type ValidationRule struct {
809824
// skipped if an old value could not be found.
810825
//
811826
// +required
827+
// +kubebuilder:validation:MaxLength=512
812828
Rule string `json:"rule"`
813829
// message represents the message displayed when validation fails. The message is required if the Rule contains
814830
// line breaks. The message must not contain line breaks.
815831
// If unset, the message is "failed rule: {Rule}".
816832
// e.g. "must be a URL with the host matching spec.host"
817833
// +optional
834+
// +kubebuilder:validation:MaxLength=512
818835
Message string `json:"message,omitempty"`
819836
// messageExpression declares a CEL expression that evaluates to the validation failure message that is returned when this rule fails.
820837
// Since messageExpression is used as a failure message, it must evaluate to a string.
@@ -826,6 +843,7 @@ type ValidationRule struct {
826843
// Example:
827844
// "x must be less than max ("+string(self.max)+")"
828845
// +optional
846+
// +kubebuilder:validation:MaxLength=512
829847
MessageExpression string `json:"messageExpression,omitempty"`
830848
// reason provides a machine-readable validation failure reason that is returned to the caller when a request fails this validation rule.
831849
// The currently supported reasons are: "FieldValueInvalid", "FieldValueForbidden", "FieldValueRequired", "FieldValueDuplicate".
@@ -846,6 +864,7 @@ type ValidationRule struct {
846864
// For field name which contains special characters, use `['specialName']` to refer the field name.
847865
// e.g. for attribute `foo.34$` appears in a list `testList`, the fieldPath could be set to `.testList['foo.34$']`
848866
// +optional
867+
// +kubebuilder:validation:MaxLength=512
849868
FieldPath string `json:"fieldPath,omitempty"`
850869
}
851870

@@ -871,9 +890,11 @@ const (
871890
// ClusterClassPatch defines a patch which is applied to customize the referenced templates.
872891
type ClusterClassPatch struct {
873892
// name of the patch.
893+
// +kubebuilder:validation:MaxLength=256
874894
Name string `json:"name"`
875895

876896
// description is a human-readable description of this patch.
897+
// +kubebuilder:validation:MaxLength=512
877898
Description string `json:"description,omitempty"`
878899

879900
// enabledIf is a Go template to be used to calculate if a patch should be enabled.
@@ -882,6 +903,7 @@ type ClusterClassPatch struct {
882903
// be disabled.
883904
// If EnabledIf is not set, the patch will be enabled per default.
884905
// +optional
906+
// +kubebuilder:validation:MaxLength=256
885907
EnabledIf *string `json:"enabledIf,omitempty"`
886908

887909
// definitions define inline patches.
@@ -916,9 +938,11 @@ type PatchDefinition struct {
916938
// Note: The results of selection based on the individual fields are ANDed.
917939
type PatchSelector struct {
918940
// apiVersion filters templates by apiVersion.
941+
// +kubebuilder:validation:MaxLength=512
919942
APIVersion string `json:"apiVersion"`
920943

921944
// kind filters templates by kind.
945+
// +kubebuilder:validation:MaxLength=256
922946
Kind string `json:"kind"`
923947

924948
// matchResources selects templates based on where they are referenced.
@@ -956,6 +980,7 @@ type PatchSelectorMatchMachineDeploymentClass struct {
956980
// names selects templates by class names.
957981
// +optional
958982
// +kubebuilder:validation:MaxItems=100
983+
// +kubebuilder:validation:items:MaxLength=256
959984
Names []string `json:"names,omitempty"`
960985
}
961986

@@ -965,20 +990,23 @@ type PatchSelectorMatchMachinePoolClass struct {
965990
// names selects templates by class names.
966991
// +optional
967992
// +kubebuilder:validation:MaxItems=100
993+
// +kubebuilder:validation:items:MaxLength=256
968994
Names []string `json:"names,omitempty"`
969995
}
970996

971997
// JSONPatch defines a JSON patch.
972998
type JSONPatch struct {
973999
// op defines the operation of the patch.
9741000
// Note: Only `add`, `replace` and `remove` are supported.
1001+
// +kubebuilder:validation:MaxLength=8
9751002
Op string `json:"op"`
9761003

9771004
// path defines the path of the patch.
9781005
// Note: Only the spec of a template can be patched, thus the path has to start with /spec/.
9791006
// Note: For now the only allowed array modifications are `append` and `prepend`, i.e.:
9801007
// * for op: `add`: only index 0 (prepend) and - (append) are allowed
9811008
// * for op: `replace` or `remove`: no indexes are allowed
1009+
// +kubebuilder:validation:MaxLength=512
9821010
Path string `json:"path"`
9831011

9841012
// value defines the value of the patch.
@@ -1004,12 +1032,14 @@ type JSONPatchValue struct {
10041032
// variable is the variable to be used as value.
10051033
// Variable can be one of the variables defined in .spec.variables or a builtin variable.
10061034
// +optional
1035+
// +kubebuilder:validation:MaxLength=256
10071036
Variable *string `json:"variable,omitempty"`
10081037

10091038
// template is the Go template to be used to calculate the value.
10101039
// A template can reference variables defined in .spec.variables and builtin variables.
10111040
// Note: The template must evaluate to a valid YAML or JSON value.
10121041
// +optional
1042+
// +kubebuilder:validation:MaxLength=10240
10131043
Template *string `json:"template,omitempty"`
10141044
}
10151045

@@ -1018,14 +1048,17 @@ type JSONPatchValue struct {
10181048
type ExternalPatchDefinition struct {
10191049
// generateExtension references an extension which is called to generate patches.
10201050
// +optional
1051+
// +kubebuilder:validation:MaxLength=512
10211052
GenerateExtension *string `json:"generateExtension,omitempty"`
10221053

10231054
// validateExtension references an extension which is called to validate the topology.
10241055
// +optional
1056+
// +kubebuilder:validation:MaxLength=512
10251057
ValidateExtension *string `json:"validateExtension,omitempty"`
10261058

10271059
// discoverVariablesExtension references an extension which is called to discover variables.
10281060
// +optional
1061+
// +kubebuilder:validation:MaxLength=512
10291062
DiscoverVariablesExtension *string `json:"discoverVariablesExtension,omitempty"`
10301063

10311064
// settings defines key value pairs to be passed to the extensions.
@@ -1079,6 +1112,7 @@ type ClusterClassV1Beta2Status struct {
10791112
// ClusterClassStatusVariable defines a variable which appears in the status of a ClusterClass.
10801113
type ClusterClassStatusVariable struct {
10811114
// name is the name of the variable.
1115+
// +kubebuilder:validation:MaxLength=256
10821116
Name string `json:"name"`
10831117

10841118
// definitionsConflict specifies whether or not there are conflicting definitions for a single variable name.
@@ -1095,6 +1129,7 @@ type ClusterClassStatusVariableDefinition struct {
10951129
// from specifies the origin of the variable definition.
10961130
// This will be `inline` for variables defined in the ClusterClass or the name of a patch defined in the ClusterClass
10971131
// for variables discovered from a DiscoverVariables runtime extensions.
1132+
// +kubebuilder:validation:MaxLength=256
10981133
From string `json:"from"`
10991134

11001135
// required specifies if the variable is required.

0 commit comments

Comments
 (0)