This repository has been archived by the owner on Nov 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**This change addresses the need by:** * closes #95 Signed-off-by: Christopher Hein <me@christopherhein.com>
- Loading branch information
1 parent
0ae16c9
commit 18707f0
Showing
7 changed files
with
198 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/aws-operator | ||
/aws-service-operator | ||
pod-role.json | ||
.DS_Store | ||
aws-operator.yaml | ||
/aws-service-operator.yaml | ||
kubeconfig | ||
dist/ | ||
.envrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
FROM alpine | ||
MAINTAINER Christopher Hein <me@christopherhein.com> | ||
MAINTAINER Christopher Hein <heichris@amazon.com> | ||
|
||
RUN apk --no-cache add openssl musl-dev ca-certificates | ||
COPY aws-operator /usr/local/bin/ | ||
COPY aws-service-operator /usr/local/bin/ | ||
|
||
ENTRYPOINT ["/usr/local/bin/aws-operator"] | ||
ENTRYPOINT ["/usr/local/bin/aws-service-operator"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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) | ||
} |