You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hal/cmd/cluster.go

60 lines
1.1 KiB

package cmd
import (
"context"
"git.jfdev.de/JonasFranzDEV/hal/hal"
"git.jfdev.de/JonasFranzDEV/hal/parser"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
)
var clusterCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Use: "cluster [config file]",
RunE: runClusterCommand,
}
func init() {
rootCommand.AddCommand(clusterCmd)
}
func runClusterCommand(cmd *cobra.Command, args []string) error {
configFile := args[0]
// Parse config
if stats, err := os.Stat(configFile); err != nil || stats.IsDir() {
return err
}
file, err := ioutil.ReadFile(configFile)
if err != nil {
return err
}
config := &hal.ClusterConfig{}
if err := yaml.Unmarshal(file, config); err != nil {
return err
}
logger, err := hal.NewPageErrorLogger("page_errors")
if err != nil {
return err
}
defer logger.Close()
// Parse modules
modules, err := parser.GetModulesFromConfig(config, debug, logger)
if err != nil {
return err
}
// Create the cluster
cluster, err := config.BuildCluster(modules)
if err != nil {
return err
}
// Run
return cluster.Run(context.Background())
}