Skip to content

Commit

Permalink
export improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pthomison committed May 24, 2024
1 parent 4c3490f commit 9fab19f
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

var (
exportDirectory string
onlyControllers bool
onlyDeployments bool
)

var ExportCmd = &cobra.Command{
Expand All @@ -25,6 +27,8 @@ var ExportCmd = &cobra.Command{

func init() {
ExportCmd.PersistentFlags().StringVarP(&exportDirectory, "export-directory", "e", ".", "Export Directory")
ExportCmd.PersistentFlags().BoolVar(&onlyControllers, "only-controllers", false, "")
ExportCmd.PersistentFlags().BoolVar(&onlyDeployments, "only-deployments", false, "")

}

Expand All @@ -37,40 +41,45 @@ func k3AutoExport(cmd *cobra.Command, args []string) {
osfs := afero.OsFs{}
embedfs := afero.FromIOFS{FS: defaults.DefaultDeployments}

afero.Walk(embedfs, ".", func(path string, info fs.FileInfo, err error) error {
checkError(err)

p := filepath.Join(exportDirectory, path)
cp := filepath.Clean(strings.Replace(p, defaults.DefaultDeploymentsFolder, "", -1))

if !info.IsDir() {
b, err := afero.ReadFile(embedfs, path)
if !onlyControllers {
afero.Walk(embedfs, ".", func(path string, info fs.FileInfo, err error) error {
checkError(err)

if exists, _ := afero.Exists(osfs, cp); exists {
err = osfs.Remove(cp)
p := filepath.Join(exportDirectory, path)
cp := filepath.Clean(strings.Replace(p, defaults.DefaultDeploymentsFolder, "", -1))

if !info.IsDir() {
b, err := afero.ReadFile(embedfs, path)
checkError(err)
}

err = afero.WriteFile(osfs, cp, b, info.Mode())
checkError(err)
} else {
err := osfs.Mkdir(cp, 0755)
if !errors.Is(err, afero.ErrFileExists) {
if exists, _ := afero.Exists(osfs, cp); exists {
err = osfs.Remove(cp)
checkError(err)
}

err = afero.WriteFile(osfs, cp, b, info.Mode())
checkError(err)
} else {
err := osfs.Mkdir(cp, 0755)
if !errors.Is(err, afero.ErrFileExists) {
checkError(err)
}
}
}

return nil
})
return nil
})
}

if !onlyDeployments {
manifests, err := flux.GenerateManifests(k3aConfig.FluxVersion)
checkError(err)

manifests, err := flux.GenerateManifests("v2.3.0")
checkError(err)
p := filepath.Join(exportDirectory, manifests.Path)

p := filepath.Join(exportDirectory, manifests.Path)
osfs.MkdirAll(filepath.Dir(p), 0755)

osfs.MkdirAll(filepath.Dir(p), 0755)
err = afero.WriteFile(osfs, p, []byte(manifests.Content), 0644)
checkError(err)
}

err = afero.WriteFile(osfs, p, []byte(manifests.Content), 0644)
checkError(err)
}

0 comments on commit 9fab19f

Please sign in to comment.