Skip to content

Commit

Permalink
Use temporary directory in /var/lib/gardener-node-agent/tmp (garden…
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranzke authored Dec 3, 2023
1 parent cd7d990 commit 2f5526e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cmd/gardener-node-agent/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ func run(ctx context.Context, cancel context.CancelFunc, log logr.Logger, cfg *c
dbus = dbus.New()
)

log.Info("Creating directory for temporary files", "path", nodeagentv1alpha1.TempDir)
if err := fs.MkdirAll(nodeagentv1alpha1.TempDir, os.ModeDir); err != nil {
return fmt.Errorf("unable to create directory for temporary files %q: %w", nodeagentv1alpha1.TempDir, err)
}

log.Info("Adding runnables to manager")
if err := mgr.Add(&controllerutils.ControlledRunner{
Manager: mgr,
Expand Down
2 changes: 2 additions & 0 deletions pkg/nodeagent/apis/config/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (
BaseDir = "/var/lib/gardener-node-agent"
// CredentialsDir is the directory on the worker node that contains credentials for the gardener-node-agent.
CredentialsDir = BaseDir + "/credentials"
// TempDir is the directory on the worker node that contains temporary directories of files.
TempDir = BaseDir + "/tmp"
// BinaryDir is the directory on the worker node that contains the binary for the gardener-node-agent.
BinaryDir = "/opt/bin"

Expand Down
4 changes: 3 additions & 1 deletion pkg/nodeagent/bootstrap/kubelet_data_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/go-logr/logr"
"github.com/spf13/afero"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

nodeagentv1alpha1 "github.com/gardener/gardener/pkg/nodeagent/apis/config/v1alpha1"
)

var (
Expand All @@ -50,7 +52,7 @@ func formatKubeletDataDevice(log logr.Logger, fs afero.Afero, kubeletDataVolumeS
}

log.Info("Creating temporary file")
tmpFile, err := fs.TempFile("", "format-kubelet-data-volume-*")
tmpFile, err := fs.TempFile(nodeagentv1alpha1.TempDir, "format-kubelet-data-volume-")
if err != nil {
return fmt.Errorf("unable to create temporary directory: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ var (
)

func (r *Reconciler) applyChangedFiles(ctx context.Context, log logr.Logger, files []extensionsv1alpha1.File) error {
tmpDir, err := r.FS.TempDir("", "gardener-node-agent-*")
tmpDir, err := r.FS.TempDir(nodeagentv1alpha1.TempDir, "osc-reconciliation-file-")
if err != nil {
return fmt.Errorf("unable to create temporary directory: %w", err)
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/nodeagent/registry/containerd_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
"github.com/opencontainers/image-spec/identity"
"github.com/spf13/afero"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

nodeagentv1alpha1 "github.com/gardener/gardener/pkg/nodeagent/apis/config/v1alpha1"
)

type containerdExtractor struct{}
Expand Down Expand Up @@ -76,7 +78,7 @@ func (e *containerdExtractor) CopyFromImage(ctx context.Context, imageRef string

snapshotter := client.SnapshotService(containerd.DefaultSnapshotter)

imageMountDirectory, err := fs.TempDir("", "node-agent-")
imageMountDirectory, err := fs.TempDir(nodeagentv1alpha1.TempDir, "mount-image-")
if err != nil {
return fmt.Errorf("error creating temp directory: %w", err)
}
Expand Down Expand Up @@ -157,7 +159,7 @@ func CopyFile(fs afero.Afero, sourceFile, destinationFile string, permissions os
return fmt.Errorf("destination directory %q could not be created", path.Dir(destinationFile))
}

tempDir, err := fs.TempDir("", "copy-image-")
tempDir, err := fs.TempDir(nodeagentv1alpha1.TempDir, "copy-image-")
if err != nil {
return fmt.Errorf("error creating temp directory: %w", err)
}
Expand Down

0 comments on commit 2f5526e

Please sign in to comment.