@@ -63,7 +63,7 @@ func (c *KubeadmConfig) ValidateDelete() error {
63
63
}
64
64
65
65
func (c * KubeadmConfigSpec ) validate (name string ) error {
66
- allErrs := c .Validate ()
66
+ allErrs := c .Validate (field . NewPath ( "spec" ) )
67
67
68
68
if len (allErrs ) == 0 {
69
69
return nil
@@ -73,16 +73,16 @@ func (c *KubeadmConfigSpec) validate(name string) error {
73
73
}
74
74
75
75
// Validate ensures the KubeadmConfigSpec is valid.
76
- func (c * KubeadmConfigSpec ) Validate () field.ErrorList {
76
+ func (c * KubeadmConfigSpec ) Validate (pathPrefix * field. Path ) field.ErrorList {
77
77
var allErrs field.ErrorList
78
78
79
- allErrs = append (allErrs , c .validateFiles ()... )
80
- allErrs = append (allErrs , c .validateIgnition ()... )
79
+ allErrs = append (allErrs , c .validateFiles (pathPrefix )... )
80
+ allErrs = append (allErrs , c .validateIgnition (pathPrefix )... )
81
81
82
82
return allErrs
83
83
}
84
84
85
- func (c * KubeadmConfigSpec ) validateFiles () field.ErrorList {
85
+ func (c * KubeadmConfigSpec ) validateFiles (pathPrefix * field. Path ) field.ErrorList {
86
86
var allErrs field.ErrorList
87
87
88
88
knownPaths := map [string ]struct {}{}
@@ -93,7 +93,7 @@ func (c *KubeadmConfigSpec) validateFiles() field.ErrorList {
93
93
allErrs = append (
94
94
allErrs ,
95
95
field .Invalid (
96
- field . NewPath ( "spec" , "files" ).Index (i ),
96
+ pathPrefix . Child ( "files" ).Index (i ),
97
97
file ,
98
98
conflictingFileSourceMsg ,
99
99
),
@@ -107,7 +107,7 @@ func (c *KubeadmConfigSpec) validateFiles() field.ErrorList {
107
107
allErrs = append (
108
108
allErrs ,
109
109
field .Invalid (
110
- field . NewPath ( "spec" , "files" ).Index (i ).Child ("contentFrom" , "secret" , "name" ),
110
+ pathPrefix . Child ( "files" ).Index (i ).Child ("contentFrom" , "secret" , "name" ),
111
111
file ,
112
112
missingSecretNameMsg ,
113
113
),
@@ -117,7 +117,7 @@ func (c *KubeadmConfigSpec) validateFiles() field.ErrorList {
117
117
allErrs = append (
118
118
allErrs ,
119
119
field .Invalid (
120
- field . NewPath ( "spec" , "files" ).Index (i ).Child ("contentFrom" , "secret" , "key" ),
120
+ pathPrefix . Child ( "files" ).Index (i ).Child ("contentFrom" , "secret" , "key" ),
121
121
file ,
122
122
missingSecretKeyMsg ,
123
123
),
@@ -129,7 +129,7 @@ func (c *KubeadmConfigSpec) validateFiles() field.ErrorList {
129
129
allErrs = append (
130
130
allErrs ,
131
131
field .Invalid (
132
- field . NewPath ( "spec" , "files" ).Index (i ).Child ("path" ),
132
+ pathPrefix . Child ( "files" ).Index (i ).Child ("path" ),
133
133
file ,
134
134
pathConflictMsg ,
135
135
),
@@ -141,18 +141,18 @@ func (c *KubeadmConfigSpec) validateFiles() field.ErrorList {
141
141
return allErrs
142
142
}
143
143
144
- func (c * KubeadmConfigSpec ) validateIgnition () field.ErrorList {
144
+ func (c * KubeadmConfigSpec ) validateIgnition (pathPrefix * field. Path ) field.ErrorList {
145
145
var allErrs field.ErrorList
146
146
147
147
if ! feature .Gates .Enabled (feature .KubeadmBootstrapFormatIgnition ) {
148
148
if c .Format == Ignition {
149
149
allErrs = append (allErrs , field .Forbidden (
150
- field . NewPath ( "spec" , "format" ), kubeadmBootstrapFormatIgnitionFeatureDisabledMsg ))
150
+ pathPrefix . Child ( "format" ), kubeadmBootstrapFormatIgnitionFeatureDisabledMsg ))
151
151
}
152
152
153
153
if c .Ignition != nil {
154
154
allErrs = append (allErrs , field .Forbidden (
155
- field . NewPath ( "spec" , "ignition" ), kubeadmBootstrapFormatIgnitionFeatureDisabledMsg ))
155
+ pathPrefix . Child ( "ignition" ), kubeadmBootstrapFormatIgnitionFeatureDisabledMsg ))
156
156
}
157
157
158
158
return allErrs
@@ -163,7 +163,7 @@ func (c *KubeadmConfigSpec) validateIgnition() field.ErrorList {
163
163
allErrs = append (
164
164
allErrs ,
165
165
field .Invalid (
166
- field . NewPath ( "spec" , "format" ),
166
+ pathPrefix . Child ( "format" ),
167
167
c .Format ,
168
168
fmt .Sprintf ("must be set to %q if spec.ignition is set" , Ignition ),
169
169
),
@@ -178,7 +178,7 @@ func (c *KubeadmConfigSpec) validateIgnition() field.ErrorList {
178
178
allErrs = append (
179
179
allErrs ,
180
180
field .Forbidden (
181
- field . NewPath ( "spec" , "users" ).Index (i ).Child ("inactive" ),
181
+ pathPrefix . Child ( "users" ).Index (i ).Child ("inactive" ),
182
182
cannotUseWithIgnition ,
183
183
),
184
184
)
@@ -189,7 +189,7 @@ func (c *KubeadmConfigSpec) validateIgnition() field.ErrorList {
189
189
allErrs = append (
190
190
allErrs ,
191
191
field .Forbidden (
192
- field . NewPath ( "spec" , "useExperimentalRetryJoin" ),
192
+ pathPrefix . Child ( "useExperimentalRetryJoin" ),
193
193
cannotUseWithIgnition ,
194
194
),
195
195
)
@@ -204,7 +204,7 @@ func (c *KubeadmConfigSpec) validateIgnition() field.ErrorList {
204
204
allErrs = append (
205
205
allErrs ,
206
206
field .Invalid (
207
- field . NewPath ( "spec" , "diskSetup" , "partitions" ).Index (i ).Child ("tableType" ),
207
+ pathPrefix . Child ( "diskSetup" , "partitions" ).Index (i ).Child ("tableType" ),
208
208
* partition .TableType ,
209
209
fmt .Sprintf (
210
210
"only partition type %q is supported when spec.format is set to %q" ,
@@ -221,7 +221,7 @@ func (c *KubeadmConfigSpec) validateIgnition() field.ErrorList {
221
221
allErrs = append (
222
222
allErrs ,
223
223
field .Forbidden (
224
- field . NewPath ( "spec" , "diskSetup" , "filesystems" ).Index (i ).Child ("replaceFS" ),
224
+ pathPrefix . Child ( "diskSetup" , "filesystems" ).Index (i ).Child ("replaceFS" ),
225
225
cannotUseWithIgnition ,
226
226
),
227
227
)
@@ -231,7 +231,7 @@ func (c *KubeadmConfigSpec) validateIgnition() field.ErrorList {
231
231
allErrs = append (
232
232
allErrs ,
233
233
field .Forbidden (
234
- field . NewPath ( "spec" , "diskSetup" , "filesystems" ).Index (i ).Child ("partition" ),
234
+ pathPrefix . Child ( "diskSetup" , "filesystems" ).Index (i ).Child ("partition" ),
235
235
cannotUseWithIgnition ,
236
236
),
237
237
)
0 commit comments