Files
kubeshark/cli/cmd/config.go
M. Mert Yildiran 8c97c4a120 🔥 Delete the ui directory and deploy kubeshark/front in a pod named front (#1246)
* Remove the `ui` directory

* Deploy the UI in a separate pod named `front`

* Fix the port number

* Fix the port forwarding

* Call `postFrontStarted` only after `kubeshark-api-server` and `front` are ready

* Fix linter

* Fix `yaml` comments
2022-11-24 00:13:04 +03:00

56 lines
1.6 KiB
Go

package cmd
import (
"fmt"
"github.com/creasty/defaults"
"github.com/kubeshark/kubeshark/cli/config"
"github.com/kubeshark/kubeshark/cli/config/configStructs"
"github.com/kubeshark/kubeshark/cli/uiUtils"
"github.com/kubeshark/kubeshark/logger"
"github.com/spf13/cobra"
)
var configCmd = &cobra.Command{
Use: "config",
Short: "Generate config with default values",
RunE: func(cmd *cobra.Command, args []string) error {
configWithDefaults, err := config.GetConfigWithDefaults()
if err != nil {
logger.Log.Errorf("Failed generating config with defaults, err: %v", err)
return nil
}
if config.Config.Config.Regenerate {
if err := config.WriteConfig(configWithDefaults); err != nil {
logger.Log.Errorf("Failed writing config with defaults, err: %v", err)
return nil
}
logger.Log.Infof(fmt.Sprintf("Template File written to %s", fmt.Sprintf(uiUtils.Purple, config.Config.ConfigFilePath)))
} else {
template, err := uiUtils.PrettyYaml(configWithDefaults)
if err != nil {
logger.Log.Errorf("Failed converting config with defaults to yaml, err: %v", err)
return nil
}
logger.Log.Debugf("Writing template config.\n%v", template)
fmt.Printf("%v", template)
}
return nil
},
}
func init() {
rootCmd.AddCommand(configCmd)
defaultConfig := config.CreateDefaultConfig()
if err := defaults.Set(&defaultConfig); err != nil {
logger.Log.Debug(err)
}
configCmd.Flags().BoolP(configStructs.RegenerateConfigName, "r", defaultConfig.Config.Regenerate, fmt.Sprintf("Regenerate the config file with default values to path %s or to chosen path using --%s", defaultConfig.ConfigFilePath, config.ConfigFilePathCommandName))
}