Skip to content

Commit

Permalink
Fix generation of kustomization.yaml for macOS if absent
Browse files Browse the repository at this point in the history
Signed-off-by: Sanskar Jaiswal <sanskar.jaiswal@weave.works>
  • Loading branch information
Sanskar Jaiswal committed Apr 21, 2022
1 parent 65d0fe9 commit b13ff9f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 1 addition & 2 deletions controllers/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (r *KustomizationReconciler) reconcile(
revision := source.GetArtifact().Revision

// create tmp dir
tmpDir, err := os.MkdirTemp("", "kustomization-")
tmpDir, err := CreateAbsTempDir()
if err != nil {
err = fmt.Errorf("tmp dir error: %w", err)
return kustomizev1.KustomizationNotReady(
Expand All @@ -310,7 +310,6 @@ func (r *KustomizationReconciler) reconcile(
err.Error(),
), err
}
defer os.RemoveAll(tmpDir)

// download artifact and extract files
err = r.download(source.GetArtifact(), tmpDir)
Expand Down
25 changes: 25 additions & 0 deletions controllers/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package controllers

import (
"fmt"
"os"
"path/filepath"
)

// CreateAbsTempDir creates a tmp dir and returns the absolute path to the dir.
// This is required since macOS creates temporary files in
// `/private/var` to which `/var` is a symlink to.
func CreateAbsTempDir() (string, error) {
// create tmp dir
tmpDir, err := os.MkdirTemp("", "kustomization-")
defer os.RemoveAll(tmpDir)
if err != nil {
return "", err
}

tmpDir, err = filepath.EvalSymlinks(tmpDir)
if err != nil {
return "", fmt.Errorf("error evaluating symlink: %w", err)
}
return tmpDir, nil
}

0 comments on commit b13ff9f

Please sign in to comment.