Skip to content

Commit

Permalink
fix: fix temporary files written to '/dev/shm' not cleaned up (#568) (#…
Browse files Browse the repository at this point in the history
…569)

Signed-off-by: Jonathan West <jonwest@redhat.com>
  • Loading branch information
jgwest authored Apr 11, 2024
1 parent 3de3136 commit 1ade3a1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/utils/io/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

var (
// TempDir is set to '/dev/shm' if exists, otherwise is "", which defaults to os.TempDir() when passed to os.CreateTemp()
TempDir string
)

Expand Down
1 change: 1 addition & 0 deletions pkg/utils/kube/ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ func (k *KubectlCmd) ManageResources(config *rest.Config, openAPISchema openapi.
_ = f.Close()
err = WriteKubeConfig(config, "", f.Name())
if err != nil {
utils.DeleteFile(f.Name())
return nil, nil, fmt.Errorf("failed to write kubeconfig: %v", err)
}
fact := kubeCmdFactory(f.Name(), "", config)
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/kube/resource_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ func (k *kubectlResourceOperations) runResourceCommand(ctx context.Context, obj
if err != nil {
return "", fmt.Errorf("Failed to generate temp file for manifest: %v", err)
}
defer io.DeleteFile(manifestFile.Name())
if _, err = manifestFile.Write(manifestBytes); err != nil {
return "", fmt.Errorf("Failed to write manifest: %v", err)
}
if err = manifestFile.Close(); err != nil {
return "", fmt.Errorf("Failed to close manifest: %v", err)
}
defer io.DeleteFile(manifestFile.Name())

// log manifest
if k.log.V(1).Enabled() {
Expand Down

0 comments on commit 1ade3a1

Please sign in to comment.