Skip to content

Commit aa27fb3

Browse files
🌱 Test changes planned to comply optionalrequired linter (#12414)
* Test changes planned to comply optionalrequired linter * Address feedback
1 parent 246c6fd commit aa27fb3

14 files changed

+928
-43
lines changed

internal/topology/upgrade/clusterctl_upgrade_test.go

Lines changed: 223 additions & 34 deletions
Large diffs are not rendered by default.

internal/topology/upgrade/test/t1/crd/test.cluster.x-k8s.io_testresources.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ spec:
3939
spec:
4040
description: TestResourceSpec defines the resource spec.
4141
properties:
42+
boolToPtrBool:
43+
type: boolean
44+
int32ToPtrInt32:
45+
format: int32
46+
minimum: 0
47+
type: integer
4248
machineTemplate:
4349
description: |-
4450
TestResourceMachineTemplateSpec define the spec for machineTemplate in a resource.
@@ -102,9 +108,26 @@ spec:
102108
type: object
103109
omittable:
104110
type: string
111+
ptrStringToString:
112+
maxLength: 256
113+
minLength: 1
114+
type: string
105115
replicas:
106116
format: int32
107117
type: integer
118+
structWithOnlyOptionalFields:
119+
description: StructWithOnlyOptionalFields is a struct with only optional
120+
fields, where the zero value (empty struct) does not make sense.
121+
properties:
122+
a:
123+
maxLength: 256
124+
minLength: 1
125+
type: string
126+
b:
127+
maxLength: 256
128+
minLength: 1
129+
type: string
130+
type: object
108131
version:
109132
type: string
110133
required:

internal/topology/upgrade/test/t1/crd/test.cluster.x-k8s.io_testresourcetemplates.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ spec:
4646
spec:
4747
description: TestResourceSpec defines the resource spec.
4848
properties:
49+
boolToPtrBool:
50+
type: boolean
51+
int32ToPtrInt32:
52+
format: int32
53+
minimum: 0
54+
type: integer
4955
machineTemplate:
5056
description: |-
5157
TestResourceMachineTemplateSpec define the spec for machineTemplate in a resource.
@@ -109,9 +115,27 @@ spec:
109115
type: object
110116
omittable:
111117
type: string
118+
ptrStringToString:
119+
maxLength: 256
120+
minLength: 1
121+
type: string
112122
replicas:
113123
format: int32
114124
type: integer
125+
structWithOnlyOptionalFields:
126+
description: StructWithOnlyOptionalFields is a struct with
127+
only optional fields, where the zero value (empty struct)
128+
does not make sense.
129+
properties:
130+
a:
131+
maxLength: 256
132+
minLength: 1
133+
type: string
134+
b:
135+
maxLength: 256
136+
minLength: 1
137+
type: string
138+
type: object
115139
version:
116140
type: string
117141
required:

internal/topology/upgrade/test/t1/v1beta1/types.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,40 @@ type TestResourceSpec struct {
8686
// +required
8787
MachineTemplate TestResourceMachineTemplateSpec `json:"machineTemplate"`
8888

89-
// General purpose fields to be used in different test scenario.
89+
// Field for testing impact of dropping the DropDefaulterRemoveUnknownOrOmittableFields options in webhooks.
9090

9191
// +optional
9292
Omittable string `json:"omittable,omitempty"`
93+
94+
// Field for testing impact of API changes to comply with optionalrequired KAL linter.
95+
96+
// +optional
97+
BoolToPtrBool bool `json:"boolToPtrBool,omitempty"`
98+
99+
// +optional
100+
// +kubebuilder:validation:MinLength=1
101+
// +kubebuilder:validation:MaxLength=256
102+
PtrStringToString *string `json:"ptrStringToString,omitempty"`
103+
104+
// +optional
105+
// +kubebuilder:validation:Minimum=0
106+
Int32ToPtrInt32 int32 `json:"int32ToPtrInt32,omitempty"`
107+
108+
// +optional
109+
StructWithOnlyOptionalFields StructWithOnlyOptionalFields `json:"structWithOnlyOptionalFields,omitempty"`
110+
}
111+
112+
// StructWithOnlyOptionalFields is a struct with only optional fields, where the zero value (empty struct) does not make sense.
113+
type StructWithOnlyOptionalFields struct {
114+
// +optional
115+
// +kubebuilder:validation:MinLength=1
116+
// +kubebuilder:validation:MaxLength=256
117+
A string `json:"a,omitempty"`
118+
119+
// +optional
120+
// +kubebuilder:validation:MinLength=1
121+
// +kubebuilder:validation:MaxLength=256
122+
B string `json:"b,omitempty"`
93123
}
94124

95125
// TestResourceMachineTemplateSpec define the spec for machineTemplate in a resource.

internal/topology/upgrade/test/t1/v1beta1/zz_generated.deepcopy.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/topology/upgrade/test/t2/crd/test.cluster.x-k8s.io_testresources.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ spec:
3939
spec:
4040
description: TestResourceSpec defines the resource spec.
4141
properties:
42+
boolToPtrBool:
43+
type: boolean
44+
int32ToPtrInt32:
45+
format: int32
46+
minimum: 0
47+
type: integer
4248
machineTemplate:
4349
description: |-
4450
TestResourceMachineTemplateSpec define the spec for machineTemplate in a resource.
@@ -102,9 +108,26 @@ spec:
102108
type: object
103109
omittable:
104110
type: string
111+
ptrStringToString:
112+
maxLength: 256
113+
minLength: 1
114+
type: string
105115
replicas:
106116
format: int32
107117
type: integer
118+
structWithOnlyOptionalFields:
119+
description: StructWithOnlyOptionalFields is a struct with only optional
120+
fields, where the zero value (empty struct) does not make sense.
121+
properties:
122+
a:
123+
maxLength: 256
124+
minLength: 1
125+
type: string
126+
b:
127+
maxLength: 256
128+
minLength: 1
129+
type: string
130+
type: object
108131
version:
109132
type: string
110133
required:
@@ -138,6 +161,12 @@ spec:
138161
spec:
139162
description: TestResourceSpec defines the resource spec.
140163
properties:
164+
boolToPtrBool:
165+
type: boolean
166+
int32ToPtrInt32:
167+
format: int32
168+
minimum: 0
169+
type: integer
141170
machineTemplate:
142171
description: |-
143172
TestResourceMachineTemplateSpec define the spec for machineTemplate in a resource.
@@ -201,9 +230,27 @@ spec:
201230
type: object
202231
omittable:
203232
type: string
233+
ptrStringToString:
234+
maxLength: 256
235+
minLength: 1
236+
type: string
204237
replicas:
205238
format: int32
206239
type: integer
240+
structWithOnlyOptionalFields:
241+
description: StructWithOnlyOptionalFields is a struct with only optional
242+
fields, where the zero value (empty struct) does not make sense.
243+
minProperties: 1
244+
properties:
245+
a:
246+
maxLength: 256
247+
minLength: 1
248+
type: string
249+
b:
250+
maxLength: 256
251+
minLength: 1
252+
type: string
253+
type: object
207254
version:
208255
type: string
209256
required:

internal/topology/upgrade/test/t2/crd/test.cluster.x-k8s.io_testresourcetemplates.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ spec:
4646
spec:
4747
description: TestResourceSpec defines the resource spec.
4848
properties:
49+
boolToPtrBool:
50+
type: boolean
51+
int32ToPtrInt32:
52+
format: int32
53+
minimum: 0
54+
type: integer
4955
machineTemplate:
5056
description: |-
5157
TestResourceMachineTemplateSpec define the spec for machineTemplate in a resource.
@@ -109,9 +115,27 @@ spec:
109115
type: object
110116
omittable:
111117
type: string
118+
ptrStringToString:
119+
maxLength: 256
120+
minLength: 1
121+
type: string
112122
replicas:
113123
format: int32
114124
type: integer
125+
structWithOnlyOptionalFields:
126+
description: StructWithOnlyOptionalFields is a struct with
127+
only optional fields, where the zero value (empty struct)
128+
does not make sense.
129+
properties:
130+
a:
131+
maxLength: 256
132+
minLength: 1
133+
type: string
134+
b:
135+
maxLength: 256
136+
minLength: 1
137+
type: string
138+
type: object
115139
version:
116140
type: string
117141
required:
@@ -158,6 +182,12 @@ spec:
158182
spec:
159183
description: TestResourceSpec defines the resource spec.
160184
properties:
185+
boolToPtrBool:
186+
type: boolean
187+
int32ToPtrInt32:
188+
format: int32
189+
minimum: 0
190+
type: integer
161191
machineTemplate:
162192
description: |-
163193
TestResourceMachineTemplateSpec define the spec for machineTemplate in a resource.
@@ -221,9 +251,28 @@ spec:
221251
type: object
222252
omittable:
223253
type: string
254+
ptrStringToString:
255+
maxLength: 256
256+
minLength: 1
257+
type: string
224258
replicas:
225259
format: int32
226260
type: integer
261+
structWithOnlyOptionalFields:
262+
description: StructWithOnlyOptionalFields is a struct with
263+
only optional fields, where the zero value (empty struct)
264+
does not make sense.
265+
minProperties: 1
266+
properties:
267+
a:
268+
maxLength: 256
269+
minLength: 1
270+
type: string
271+
b:
272+
maxLength: 256
273+
minLength: 1
274+
type: string
275+
type: object
227276
version:
228277
type: string
229278
required:

0 commit comments

Comments
 (0)