From f91491a7eac6c238371d7ad7e0c780441a5ebf24 Mon Sep 17 00:00:00 2001 From: Joshua Novick Date: Thu, 29 Feb 2024 12:06:58 +0200 Subject: [PATCH] Create directory automatically * When writing to a new file, create the directory for the file if it does not already exist * This is useful if writing `helmvalues` to a new directory that is solely used for updating the image version. The ArgoCD Application can add a second source and reference the file with the `ignoreMissingValueFiles` flag turned on as an additional values file * If the directory already exists, this command does nothing. Signed-off-by: Joshua Novick --- pkg/argocd/git.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/argocd/git.go b/pkg/argocd/git.go index 1764a454..d3216d98 100644 --- a/pkg/argocd/git.go +++ b/pkg/argocd/git.go @@ -291,6 +291,12 @@ func writeOverrides(app *v1alpha1.Application, wbc *WriteBackConfig, gitC git.Cl } } + dir := filepath.Dir(targetFile) + err = os.MkdirAll(dir, 0700) + if err != nil { + return + } + err = os.WriteFile(targetFile, override, 0600) if err != nil { return