@@ -104,9 +104,10 @@ func (h *ControlPlaneVirtualIP) Mutate(
104
104
func (obj * controlplanev1.KubeadmControlPlaneTemplate ) error {
105
105
if controlPlaneEndpointVar .VirtualIPSpec == nil {
106
106
log .V (5 ).Info ("ControlPlane VirtualIP not set" )
107
- // if VirtualIPSpec is not set, delete all template files
107
+ // if VirtualIPSpec is not set, delete all VirtualIP providers' template files
108
108
// as we do not want them to end up in the generated KCP
109
- deleteFiles (obj , providers .TemplateFileNames ... )
109
+ obj .Spec .Template .Spec .KubeadmConfigSpec .Files =
110
+ deleteFiles (obj .Spec .Template .Spec .KubeadmConfigSpec .Files , providers .VirtualIPProviderFileNames ... )
110
111
return nil
111
112
}
112
113
@@ -133,7 +134,8 @@ func (h *ControlPlaneVirtualIP) Mutate(
133
134
virtualIPProvider .Name (),
134
135
))
135
136
136
- mergeFiles (obj , files ... )
137
+ obj .Spec .Template .Spec .KubeadmConfigSpec .Files =
138
+ mergeFiles (obj .Spec .Template .Spec .KubeadmConfigSpec .Files , files ... )
137
139
138
140
if len (preKubeadmCommands ) > 0 {
139
141
log .WithValues (
@@ -168,35 +170,34 @@ func (h *ControlPlaneVirtualIP) Mutate(
168
170
)
169
171
}
170
172
171
- func deleteFiles (obj * controlplanev1. KubeadmControlPlaneTemplate , filePathsToDelete ... string ) {
172
- for i := len (obj . Spec . Template . Spec . KubeadmConfigSpec . Files ) - 1 ; i >= 0 ; i -- {
173
+ func deleteFiles (files []bootstrapv1. File , filePathsToDelete ... string ) []bootstrapv1. File {
174
+ for i := len (files ) - 1 ; i >= 0 ; i -- {
173
175
for _ , path := range filePathsToDelete {
174
- if obj .Spec .Template .Spec .KubeadmConfigSpec .Files [i ].Path == path {
175
- obj .Spec .Template .Spec .KubeadmConfigSpec .Files = slices .Delete (
176
- obj .Spec .Template .Spec .KubeadmConfigSpec .Files , i , i + 1 ,
177
- )
176
+ if files [i ].Path == path {
177
+ files = slices .Delete (files , i , i + 1 )
178
178
break
179
179
}
180
180
}
181
181
}
182
+
183
+ return files
182
184
}
183
185
184
186
// mergeFiles will merge the files into the KubeadmControlPlaneTemplate,
185
187
// overriding any file with the same path and appending the rest.
186
- func mergeFiles (obj * controlplanev1. KubeadmControlPlaneTemplate , filesToMerge ... bootstrapv1.File ) {
188
+ func mergeFiles (files []bootstrapv1. File , filesToMerge ... bootstrapv1.File ) []bootstrapv1. File {
187
189
// replace any existing files with the same path
188
190
for i := len (filesToMerge ) - 1 ; i >= 0 ; i -- {
189
- for j := range obj . Spec . Template . Spec . KubeadmConfigSpec . Files {
190
- if obj . Spec . Template . Spec . KubeadmConfigSpec . Files [j ].Path == filesToMerge [i ].Path {
191
- obj . Spec . Template . Spec . KubeadmConfigSpec . Files [j ] = filesToMerge [i ]
191
+ for j := range files {
192
+ if files [j ].Path == filesToMerge [i ].Path {
193
+ files [j ] = filesToMerge [i ]
192
194
filesToMerge = slices .Delete (filesToMerge , i , i + 1 )
193
195
break
194
196
}
195
197
}
196
198
}
197
199
// append the remaining files
198
- obj .Spec .Template .Spec .KubeadmConfigSpec .Files = append (
199
- obj .Spec .Template .Spec .KubeadmConfigSpec .Files ,
200
- filesToMerge ... ,
201
- )
200
+ files = append (files , filesToMerge ... )
201
+
202
+ return files
202
203
}
0 commit comments