@@ -262,7 +262,7 @@ var realFS = fileSystem{
262
262
func writeFiles [C string | []byte ](
263
263
fs * fileSystem , eventRecorder events.Recorder ,
264
264
typeName string , o metav1.ObjectMeta ,
265
- contentDir string , files map [string ]C , filePerm os.FileMode ,
265
+ targetDir string , files map [string ]C , filePerm os.FileMode ,
266
266
) error {
267
267
// We are doing to prepare a tmp directory and write all files into that directory.
268
268
// Then we are going to atomically swap the new data directory for the old one.
@@ -276,28 +276,28 @@ func writeFiles[C string | []byte](
276
276
// This would all just increase complexity and require atomic swap on the OS level anyway.
277
277
278
278
// In case the target directory does not exist, create it so that the directory not existing is not a special case.
279
- klog .Infof ("Ensuring target directory %q exists ..." , contentDir )
280
- if err := fs .MkdirAll (contentDir , 0755 ); err != nil && ! os .IsExist (err ) {
279
+ klog .Infof ("Ensuring target directory %q exists ..." , targetDir )
280
+ if err := fs .MkdirAll (targetDir , 0755 ); err != nil && ! os .IsExist (err ) {
281
281
eventRecorder .Warningf ("CertificateUpdateFailed" , "Failed creating content directory for %s: %s/%s: %v" , typeName , o .Namespace , o .Name , err )
282
282
return err
283
283
}
284
284
285
285
// Create a tmp source directory to be swapped.
286
- klog .Infof ("Ensuring source directory %q exists ..." , contentDir )
287
- srcDir , err := fs .MkdirTemp (filepath .Dir (contentDir ), filepath .Base (contentDir )+ "-*" )
286
+ klog .Infof ("Ensuring source directory %q exists ..." , targetDir )
287
+ tmpDir , err := fs .MkdirTemp (filepath .Dir (targetDir ), filepath .Base (targetDir )+ "-*" )
288
288
if err != nil {
289
- eventRecorder .Warningf ("CertificateUpdateFailed" , "Failed to create source directory for %s: %s/%s: %v" , typeName , o .Namespace , o .Name , err )
289
+ eventRecorder .Warningf ("CertificateUpdateFailed" , "Failed to create temporary directory for %s: %s/%s: %v" , typeName , o .Namespace , o .Name , err )
290
290
return err
291
291
}
292
292
defer func () {
293
- if err := fs .RemoveAll (srcDir ); err != nil {
294
- klog .Errorf ("Failed to remove source directory %q during cleanup: %v" , srcDir , err )
293
+ if err := fs .RemoveAll (tmpDir ); err != nil {
294
+ klog .Errorf ("Failed to remove temporary directory %q during cleanup: %v" , tmpDir , err )
295
295
}
296
296
}()
297
297
298
298
// Populate the tmp directory with files.
299
299
for filename , content := range files {
300
- fullFilename := filepath .Join (srcDir , filename )
300
+ fullFilename := filepath .Join (tmpDir , filename )
301
301
klog .Infof ("Writing %s manifest %q ..." , typeName , fullFilename )
302
302
303
303
if err := fs .WriteFile (fullFilename , []byte (content ), filePerm ); err != nil {
@@ -307,9 +307,9 @@ func writeFiles[C string | []byte](
307
307
}
308
308
309
309
// Swap directories atomically.
310
- klog .Infof ("Atomically swapping target directory %q with source directory %q for %s: %s/%s ..." , contentDir , srcDir , typeName , o .Namespace , o .Name )
311
- if err := fs .SwapDirectoriesAtomic (contentDir , srcDir ); err != nil {
312
- eventRecorder .Warningf ("CertificateUpdateFailed" , "Failed to swap target directory %q with source directory %q for %s: %s/%s: %v" , contentDir , srcDir , typeName , o .Namespace , o .Name , err )
310
+ klog .Infof ("Atomically swapping target directory %q with temporary directory %q for %s: %s/%s ..." , targetDir , tmpDir , typeName , o .Namespace , o .Name )
311
+ if err := fs .SwapDirectoriesAtomic (targetDir , tmpDir ); err != nil {
312
+ eventRecorder .Warningf ("CertificateUpdateFailed" , "Failed to swap target directory %q with temporary directory %q for %s: %s/%s: %v" , targetDir , tmpDir , typeName , o .Namespace , o .Name , err )
313
313
return err
314
314
}
315
315
0 commit comments