diff --git a/cmd/aws-operator/main.go b/cmd/aws-operator/main.go deleted file mode 100644 index 8e9803eb8..000000000 --- a/cmd/aws-operator/main.go +++ /dev/null @@ -1,103 +0,0 @@ -package main - -import ( - "fmt" - homedir "github.com/mitchellh/go-homedir" - - "github.com/christopherhein/aws-operator/pkg/config" - - "github.com/spf13/cobra" - "github.com/spf13/viper" - "os" - "strings" -) - -var ( - // cfgFile, kubeConfig, awsRegion all help support passed in flags into the server - cfgFile, kubeconfig, awsRegion, logLevel, logFile, resources, clusterName, bucket, accountID string - - // rootCmd represents the base command when called without any subcommands - rootCmd = &cobra.Command{ - Use: "aws-operator", - Short: "AWS Operator manages your AWS Infrastructure using CRDs and Operators", - Long: `TODO WRITE THIS`, - Run: func(c *cobra.Command, _ []string) { - c.Help() - }, - } -) - -func main() { - cobra.OnInitialize(initConfig) - - if err := rootCmd.Execute(); err != nil { - fmt.Println(err) - os.Exit(1) - } -} - -func init() { - rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "f", "Config file (default is $HOME/.aws-operator.yaml)") - rootCmd.PersistentFlags().StringVarP(&kubeconfig, "kubeconfig", "k", "", "Path to local kubeconfig file (mainly used for development)") - rootCmd.PersistentFlags().StringVarP(&awsRegion, "region", "r", "us-west-2", "AWS Region for resources to be created in") - rootCmd.PersistentFlags().StringVarP(&logLevel, "loglevel", "l", "Info", "Log level for the CLI") - rootCmd.PersistentFlags().StringVarP(&logFile, "logfile", "", "", "Log level for the CLI") - rootCmd.PersistentFlags().StringVarP(&resources, "resources", "", "s3bucket,dynamodb", "Comma delimited list of CRDs to deploy") - rootCmd.PersistentFlags().StringVarP(&clusterName, "cluster-name", "i", "aws-operator", "Cluster name for the Application to run as, used to label the Cloudformation templated to avoid conflict") - rootCmd.PersistentFlags().StringVarP(&bucket, "bucket", "b", "aws-operator", "To configure the operator you need a base bucket to contain the resources") - rootCmd.PersistentFlags().StringVarP(&accountID, "account-id", "a", "", "AWS Account ID, this is used to configure outputs and operate on the proper account.") - - viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config")) - viper.BindPFlag("kubeconfig", rootCmd.PersistentFlags().Lookup("kubeconfig")) - viper.BindPFlag("region", rootCmd.PersistentFlags().Lookup("region")) - viper.BindPFlag("loglevel", rootCmd.PersistentFlags().Lookup("loglevel")) - viper.BindPFlag("logfile", rootCmd.PersistentFlags().Lookup("logfile")) - viper.BindPFlag("resources", rootCmd.PersistentFlags().Lookup("resources")) - viper.BindPFlag("clustername", rootCmd.PersistentFlags().Lookup("cluster-name")) - viper.BindPFlag("bucket", rootCmd.PersistentFlags().Lookup("bucket")) - viper.BindPFlag("accountid", rootCmd.PersistentFlags().Lookup("account-id")) -} - -// initConfig reads in config file and ENV variables if set. -func initConfig() { - if cfgFile != "" { - viper.SetConfigFile(cfgFile) - } else { - home, err := homedir.Dir() - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - viper.AddConfigPath(home) - viper.SetConfigName(".aws-operator") - } - - replacer := strings.NewReplacer(".", "_") - viper.SetEnvKeyReplacer(replacer) - viper.AutomaticEnv() - - if err := viper.ReadInConfig(); err == nil { - fmt.Println("Using config file:", viper.ConfigFileUsed()) - } -} - -func getConfig() (*config.Config, error) { - resourcesList := strings.Split(resources, ",") - config := &config.Config{ - Region: awsRegion, - Kubeconfig: kubeconfig, - LoggingConfig: &config.LoggingConfig{ - File: logFile, - Level: logLevel, - FullTimestamps: true, - DisableTimestamps: false, - }, - Resources: resourcesList, - ClusterName: clusterName, - Bucket: bucket, - AccountID: accountID, - } - - return config, nil -} diff --git a/cmd/aws-operator/server.go b/cmd/aws-operator/server.go deleted file mode 100644 index 6758404fd..000000000 --- a/cmd/aws-operator/server.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "github.com/christopherhein/aws-operator/pkg/logger" - "github.com/christopherhein/aws-operator/pkg/server" - "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - "os" - "os/signal" - "syscall" -) - -var serverCmd = &cobra.Command{ - Use: "server", - Short: "Run the operator", - Long: ``, - Run: func(cmd *cobra.Command, args []string) { - config, err := getConfig() - if err != nil { - logrus.Fatalf("%s", err) - } - - logger, err := logger.Configure(config.LoggingConfig) - if err != nil { - logrus.Fatalf("Failed to configure logging: '%s'" + err.Error()) - } - config.Logger = logger - - signalChan := make(chan os.Signal, 1) - stopChan := make(chan struct{}) - signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM) - - server.New(config).Run(stopChan) - - for { - select { - case <-signalChan: - logger.Info("shutdown signal received, exiting...") - close(stopChan) - return - } - } - - }, -} - -func init() { - rootCmd.AddCommand(serverCmd) -} diff --git a/cmd/aws-operator/version.go b/cmd/aws-operator/version.go deleted file mode 100644 index b413e44b0..000000000 --- a/cmd/aws-operator/version.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "fmt" - goVersion "github.com/christopherhein/go-version" - "github.com/spf13/cobra" -) - -var ( - shortened = false - version = "dev" - commit = "none" - date = "unknown" - versionCmd = &cobra.Command{ - Use: "version", - Short: "Version will output the current aws-operator build information", - Long: ``, - Run: func(_ *cobra.Command, _ []string) { - var response string - versionOutput := goVersion.New(version, commit, date) - - if shortened { - response = versionOutput.ToShortened() - } else { - response = versionOutput.ToJSON() - } - fmt.Printf("%+v", response) - return - }, - } -) - -func init() { - versionCmd.Flags().BoolVarP(&shortened, "short", "s", false, "Use shortened output for version information.") - rootCmd.AddCommand(versionCmd) -}