Skip to content

Commit

Permalink
Add log handling
Browse files Browse the repository at this point in the history
  • Loading branch information
arttii committed Aug 3, 2020
1 parent 5e62dde commit a8cda03
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
19 changes: 18 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [



{
"name": "Launch Namespace Custom",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"cwd": "/home/arti/workdir/vw-dap/dap-core",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}/main.go",

// "envFile": "${workspaceRoot}/.dev.env",
"args": ["apply-namespace","--dry-run", "-e","dev","--lint","dap-base"],
"showLog": true
},
{
"name": "Launch Namespace",
"type": "go",
Expand All @@ -15,6 +31,7 @@
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}/main.go",

// "envFile": "${workspaceRoot}/.dev.env",
"args": ["apply-namespace", "-e","dev","--lint","default"],
"showLog": true
Expand Down
19 changes: 14 additions & 5 deletions cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,24 @@ func templateApp(app string, inputFilePath string, appGroupDir string, lint bool
return nil
}

func deployAppGroup(group string, namespace string, workingDir string, appFilter string, lint bool, dryRun bool) error {
func getFinalOutputDir(outputDir string, isolated bool) string {
if isolated {
return utils.ConcatDirs(outputDir, execTime.Format("2006-01-02/15-04:05"))
}
return outputDir
}

log.V(0).Info("deploying", "group", group, "namespace", namespace, "app", appFilter, "lint", lint, "dry", dryRun)
func applyAppGroup(group string, namespace string, outputDir string, appFilter string, lint bool, dryRun bool) error {

log.V(0).Info("applying", "group", group, "namespace", namespace, "app", appFilter, "lint", lint, "dry", dryRun)
namespaceDir := utils.GetNamespaceDir(namespace)
if _, err := os.Stat(namespaceDir); os.IsNotExist(err) {
return fmt.Errorf("%s directory does not exist", namespaceDir)
}

appGroupDir := utils.ConcatDirs(namespaceDir, group)

targetAppGroupDir := utils.ConcatDirs(workingDir, execTime.Format("2006-01-02/15-04:05"), namespace, group)
targetAppGroupDir := utils.ConcatDirs(outputDir, namespace, group)

err := os.MkdirAll(targetAppGroupDir, os.ModePerm)
if err != nil {
Expand Down Expand Up @@ -120,9 +127,11 @@ var applyCmd = &cobra.Command{

appFilter, _ := cmd.Flags().GetString("app")

workingDir, _ := cmd.Flags().GetString("working-dir")
outputDir, _ := cmd.Flags().GetString("output-dir")

isolated, _ := cmd.Flags().GetBool("isolated")

err := deployAppGroup(args[0], namespace, workingDir, appFilter, lint, dryRun)
err := applyAppGroup(args[0], namespace, getFinalOutputDir(outputDir, isolated), appFilter, lint, dryRun)
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/applyNamespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ var namespaceCmd = &cobra.Command{

appFilter, _ := cmd.Flags().GetString("app")

workingDir, _ := cmd.Flags().GetString("working-dir")
outputDir, _ := cmd.Flags().GetString("output-dir")

isolated, _ := cmd.Flags().GetBool("isolated")

namespace := args[0]

Expand All @@ -49,7 +51,7 @@ var namespaceCmd = &cobra.Command{

if info.IsDir() && path != namespaceDir {
group := filepath.Base(path)
err := deployAppGroup(group, namespace, workingDir, appFilter, lint, dryRun)
err := applyAppGroup(group, namespace, getFinalOutputDir(outputDir, isolated), appFilter, lint, dryRun)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ func init() {
execTime = time.Now()
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().StringP("environment", "e", "", "Target environment")
rootCmd.PersistentFlags().StringP("environment", "e", "dev", "Target environment")

rootCmd.PersistentFlags().StringP("working-dir", "w", "/tmp/kapp", "Working directory")
rootCmd.PersistentFlags().StringP("output-dir", "o", "/tmp/kapp", "Working directory")
rootCmd.PersistentFlags().BoolP("isolate", "i", true, "By default all output is isolated by appending the time in the following format 2006-01-02/15-04:05")
rootCmd.PersistentFlags().StringP("app", "a", "", "only include this app")
rootCmd.PersistentFlags().StringP("template-engine", "t", "helmfile", "Template engine")

Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func InitZapLog(debug bool) logr.Logger {
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
config.EncoderConfig.TimeKey = "timestamp"
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
//config.DisableCaller = true
config.DisableCaller = true

zapLog, _ := config.Build()
logger := zapr.NewLogger(zapLog)
Expand Down

0 comments on commit a8cda03

Please sign in to comment.