Skip to content

Commit d9fb5b0

Browse files
committed
Rename to targetDir and tmpDir
1 parent 56d178c commit d9fb5b0

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

pkg/operator/staticpod/certsyncpod/certsync_controller.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ var realFS = fileSystem{
262262
func writeFiles[C string | []byte](
263263
fs *fileSystem, eventRecorder events.Recorder,
264264
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,
266266
) error {
267267
// We are doing to prepare a tmp directory and write all files into that directory.
268268
// Then we are going to atomically swap the new data directory for the old one.
@@ -276,28 +276,28 @@ func writeFiles[C string | []byte](
276276
// This would all just increase complexity and require atomic swap on the OS level anyway.
277277

278278
// 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) {
281281
eventRecorder.Warningf("CertificateUpdateFailed", "Failed creating content directory for %s: %s/%s: %v", typeName, o.Namespace, o.Name, err)
282282
return err
283283
}
284284

285285
// 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)+"-*")
288288
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)
290290
return err
291291
}
292292
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)
295295
}
296296
}()
297297

298298
// Populate the tmp directory with files.
299299
for filename, content := range files {
300-
fullFilename := filepath.Join(srcDir, filename)
300+
fullFilename := filepath.Join(tmpDir, filename)
301301
klog.Infof("Writing %s manifest %q ...", typeName, fullFilename)
302302

303303
if err := fs.WriteFile(fullFilename, []byte(content), filePerm); err != nil {
@@ -307,9 +307,9 @@ func writeFiles[C string | []byte](
307307
}
308308

309309
// 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)
313313
return err
314314
}
315315

0 commit comments

Comments
 (0)