diff --git a/contrib/pkg/utils/generic.go b/contrib/pkg/utils/generic.go index 31240ad2241..c460267d540 100644 --- a/contrib/pkg/utils/generic.go +++ b/contrib/pkg/utils/generic.go @@ -3,6 +3,7 @@ package utils import ( "context" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -159,6 +160,10 @@ func ProjectToDir(obj client.Object, dir string, keys ...string) { return } path := filepath.Join(dir, filename) + // Unlink if present, in case this is a recycled pod + if err := os.Remove(path); err != nil && !errors.Is(err, os.ErrNotExist) { + log.WithError(err).WithField("path", path).Fatal("Failed to remove existing file") + } if err := os.WriteFile(path, bytes, 0400); err != nil { log.WithError(err).WithField("path", path).Fatal("Failed to write file") }