@@ -79,7 +79,7 @@ func (c *KubeadmConfig) ValidateDelete() error {
79
79
}
80
80
81
81
func (c * KubeadmConfigSpec ) validate (name string ) error {
82
- allErrs := c .Validate ()
82
+ allErrs := c .Validate (field . NewPath ( "spec" ) )
83
83
84
84
if len (allErrs ) == 0 {
85
85
return nil
@@ -89,16 +89,16 @@ func (c *KubeadmConfigSpec) validate(name string) error {
89
89
}
90
90
91
91
// Validate ensures the KubeadmConfigSpec is valid.
92
- func (c * KubeadmConfigSpec ) Validate () field.ErrorList {
92
+ func (c * KubeadmConfigSpec ) Validate (pathPrefix * field. Path ) field.ErrorList {
93
93
var allErrs field.ErrorList
94
94
95
- allErrs = append (allErrs , c .validateFiles ()... )
96
- allErrs = append (allErrs , c .validateIgnition ()... )
95
+ allErrs = append (allErrs , c .validateFiles (pathPrefix )... )
96
+ allErrs = append (allErrs , c .validateIgnition (pathPrefix )... )
97
97
98
98
return allErrs
99
99
}
100
100
101
- func (c * KubeadmConfigSpec ) validateFiles () field.ErrorList {
101
+ func (c * KubeadmConfigSpec ) validateFiles (pathPrefix * field. Path ) field.ErrorList {
102
102
var allErrs field.ErrorList
103
103
104
104
knownPaths := map [string ]struct {}{}
@@ -109,7 +109,7 @@ func (c *KubeadmConfigSpec) validateFiles() field.ErrorList {
109
109
allErrs = append (
110
110
allErrs ,
111
111
field .Invalid (
112
- field . NewPath ( "spec" , "files" ).Index (i ),
112
+ pathPrefix . Child ( "files" ).Index (i ),
113
113
file ,
114
114
conflictingFileSourceMsg ,
115
115
),
@@ -122,19 +122,17 @@ func (c *KubeadmConfigSpec) validateFiles() field.ErrorList {
122
122
if file .ContentFrom .Secret .Name == "" {
123
123
allErrs = append (
124
124
allErrs ,
125
- field .Invalid (
126
- field .NewPath ("spec" , "files" ).Index (i ).Child ("contentFrom" , "secret" , "name" ),
127
- file ,
125
+ field .Required (
126
+ pathPrefix .Child ("files" ).Index (i ).Child ("contentFrom" , "secret" , "name" ),
128
127
missingSecretNameMsg ,
129
128
),
130
129
)
131
130
}
132
131
if file .ContentFrom .Secret .Key == "" {
133
132
allErrs = append (
134
133
allErrs ,
135
- field .Invalid (
136
- field .NewPath ("spec" , "files" ).Index (i ).Child ("contentFrom" , "secret" , "key" ),
137
- file ,
134
+ field .Required (
135
+ pathPrefix .Child ("files" ).Index (i ).Child ("contentFrom" , "secret" , "key" ),
138
136
missingSecretKeyMsg ,
139
137
),
140
138
)
@@ -145,7 +143,7 @@ func (c *KubeadmConfigSpec) validateFiles() field.ErrorList {
145
143
allErrs = append (
146
144
allErrs ,
147
145
field .Invalid (
148
- field . NewPath ( "spec" , "files" ).Index (i ).Child ("path" ),
146
+ pathPrefix . Child ( "files" ).Index (i ).Child ("path" ),
149
147
file ,
150
148
pathConflictMsg ,
151
149
),
@@ -157,18 +155,18 @@ func (c *KubeadmConfigSpec) validateFiles() field.ErrorList {
157
155
return allErrs
158
156
}
159
157
160
- func (c * KubeadmConfigSpec ) validateIgnition () field.ErrorList {
158
+ func (c * KubeadmConfigSpec ) validateIgnition (pathPrefix * field. Path ) field.ErrorList {
161
159
var allErrs field.ErrorList
162
160
163
161
if ! feature .Gates .Enabled (feature .KubeadmBootstrapFormatIgnition ) {
164
162
if c .Format == Ignition {
165
163
allErrs = append (allErrs , field .Forbidden (
166
- field . NewPath ( "spec" , "format" ), kubeadmBootstrapFormatIgnitionFeatureDisabledMsg ))
164
+ pathPrefix . Child ( "format" ), kubeadmBootstrapFormatIgnitionFeatureDisabledMsg ))
167
165
}
168
166
169
167
if c .Ignition != nil {
170
168
allErrs = append (allErrs , field .Forbidden (
171
- field . NewPath ( "spec" , "ignition" ), kubeadmBootstrapFormatIgnitionFeatureDisabledMsg ))
169
+ pathPrefix . Child ( "ignition" ), kubeadmBootstrapFormatIgnitionFeatureDisabledMsg ))
172
170
}
173
171
174
172
return allErrs
@@ -179,7 +177,7 @@ func (c *KubeadmConfigSpec) validateIgnition() field.ErrorList {
179
177
allErrs = append (
180
178
allErrs ,
181
179
field .Invalid (
182
- field . NewPath ( "spec" , "format" ),
180
+ pathPrefix . Child ( "format" ),
183
181
c .Format ,
184
182
fmt .Sprintf ("must be set to %q if spec.ignition is set" , Ignition ),
185
183
),
@@ -194,7 +192,7 @@ func (c *KubeadmConfigSpec) validateIgnition() field.ErrorList {
194
192
allErrs = append (
195
193
allErrs ,
196
194
field .Forbidden (
197
- field . NewPath ( "spec" , "users" ).Index (i ).Child ("inactive" ),
195
+ pathPrefix . Child ( "users" ).Index (i ).Child ("inactive" ),
198
196
cannotUseWithIgnition ,
199
197
),
200
198
)
@@ -205,7 +203,7 @@ func (c *KubeadmConfigSpec) validateIgnition() field.ErrorList {
205
203
allErrs = append (
206
204
allErrs ,
207
205
field .Forbidden (
208
- field . NewPath ( "spec" , "useExperimentalRetryJoin" ),
206
+ pathPrefix . Child ( "useExperimentalRetryJoin" ),
209
207
cannotUseWithIgnition ,
210
208
),
211
209
)
@@ -220,7 +218,7 @@ func (c *KubeadmConfigSpec) validateIgnition() field.ErrorList {
220
218
allErrs = append (
221
219
allErrs ,
222
220
field .Invalid (
223
- field . NewPath ( "spec" , "diskSetup" , "partitions" ).Index (i ).Child ("tableType" ),
221
+ pathPrefix . Child ( "diskSetup" , "partitions" ).Index (i ).Child ("tableType" ),
224
222
* partition .TableType ,
225
223
fmt .Sprintf (
226
224
"only partition type %q is supported when spec.format is set to %q" ,
@@ -237,7 +235,7 @@ func (c *KubeadmConfigSpec) validateIgnition() field.ErrorList {
237
235
allErrs = append (
238
236
allErrs ,
239
237
field .Forbidden (
240
- field . NewPath ( "spec" , "diskSetup" , "filesystems" ).Index (i ).Child ("replaceFS" ),
238
+ pathPrefix . Child ( "diskSetup" , "filesystems" ).Index (i ).Child ("replaceFS" ),
241
239
cannotUseWithIgnition ,
242
240
),
243
241
)
@@ -247,7 +245,7 @@ func (c *KubeadmConfigSpec) validateIgnition() field.ErrorList {
247
245
allErrs = append (
248
246
allErrs ,
249
247
field .Forbidden (
250
- field . NewPath ( "spec" , "diskSetup" , "filesystems" ).Index (i ).Child ("partition" ),
248
+ pathPrefix . Child ( "diskSetup" , "filesystems" ).Index (i ).Child ("partition" ),
251
249
cannotUseWithIgnition ,
252
250
),
253
251
)
0 commit comments