Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.

Commit 18707f0

Browse files
Using AWS Service Operator Name
**This change addresses the need by:** * closes #95 Signed-off-by: Christopher Hein <[email protected]>
1 parent 0ae16c9 commit 18707f0

File tree

7 files changed

+198
-10
lines changed

7 files changed

+198
-10
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/aws-operator
1+
/aws-service-operator
22
pod-role.json
33
.DS_Store
4-
aws-operator.yaml
4+
/aws-service-operator.yaml
55
kubeconfig
66
dist/
77
.envrc

.goreleaser.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project_name: aws-operator
1+
project_name: aws-service-operator
22

33
# This will be useful in making sure that all files are updated before
44
# a release is made.
@@ -8,8 +8,8 @@ before:
88

99
# Builds the binary for each platform
1010
builds:
11-
- binary: aws-operator
12-
main: ./cmd/aws-operator/
11+
- binary: aws-service-operator
12+
main: ./cmd/aws-service-operator/
1313
goos:
1414
- darwin
1515
- windows
@@ -43,7 +43,7 @@ release:
4343
# Creates a Docker container with the operator packaged into it for distribution
4444
dockers:
4545
- image: awsserviceoperator/aws-service-operator
46-
binary: aws-operator
46+
binary: aws-service-operator
4747
dockerfile: Dockerfile
4848
tag_templates:
4949
- "{{ .Tag }}"

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM alpine
2-
MAINTAINER Christopher Hein <me@christopherhein.com>
2+
MAINTAINER Christopher Hein <heichris@amazon.com>
33

44
RUN apk --no-cache add openssl musl-dev ca-certificates
5-
COPY aws-operator /usr/local/bin/
5+
COPY aws-service-operator /usr/local/bin/
66

7-
ENTRYPOINT ["/usr/local/bin/aws-operator"]
7+
ENTRYPOINT ["/usr/local/bin/aws-service-operator"]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ dateStr := $(shell date +%s)
33

44
.PHONY: build
55
build:
6-
go build -ldflags "-X main.commit=$(commitSHA) -X main.date=$(dateStr)" ./cmd/aws-operator
6+
go build -ldflags "-X main.commit=$(commitSHA) -X main.date=$(dateStr)" ./cmd/aws-service-operator
77

88
.PHONY: release
99
release:

cmd/aws-service-operator/main.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
homedir "github.com/mitchellh/go-homedir"
6+
7+
"github.com/christopherhein/aws-operator/pkg/config"
8+
9+
"github.com/spf13/cobra"
10+
"github.com/spf13/viper"
11+
"os"
12+
"strings"
13+
)
14+
15+
var (
16+
// cfgFile, kubeConfig, awsRegion all help support passed in flags into the server
17+
cfgFile, kubeconfig, awsRegion, logLevel, logFile, resources, clusterName, bucket, accountID string
18+
19+
// rootCmd represents the base command when called without any subcommands
20+
rootCmd = &cobra.Command{
21+
Use: "aws-operator",
22+
Short: "AWS Operator manages your AWS Infrastructure using CRDs and Operators",
23+
Long: `TODO WRITE THIS`,
24+
Run: func(c *cobra.Command, _ []string) {
25+
c.Help()
26+
},
27+
}
28+
)
29+
30+
func main() {
31+
cobra.OnInitialize(initConfig)
32+
33+
if err := rootCmd.Execute(); err != nil {
34+
fmt.Println(err)
35+
os.Exit(1)
36+
}
37+
}
38+
39+
func init() {
40+
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "f", "Config file (default is $HOME/.aws-operator.yaml)")
41+
rootCmd.PersistentFlags().StringVarP(&kubeconfig, "kubeconfig", "k", "", "Path to local kubeconfig file (mainly used for development)")
42+
rootCmd.PersistentFlags().StringVarP(&awsRegion, "region", "r", "us-west-2", "AWS Region for resources to be created in")
43+
rootCmd.PersistentFlags().StringVarP(&logLevel, "loglevel", "l", "Info", "Log level for the CLI")
44+
rootCmd.PersistentFlags().StringVarP(&logFile, "logfile", "", "", "Log level for the CLI")
45+
rootCmd.PersistentFlags().StringVarP(&resources, "resources", "", "s3bucket,dynamodb", "Comma delimited list of CRDs to deploy")
46+
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")
47+
rootCmd.PersistentFlags().StringVarP(&bucket, "bucket", "b", "aws-operator", "To configure the operator you need a base bucket to contain the resources")
48+
rootCmd.PersistentFlags().StringVarP(&accountID, "account-id", "a", "", "AWS Account ID, this is used to configure outputs and operate on the proper account.")
49+
50+
viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
51+
viper.BindPFlag("kubeconfig", rootCmd.PersistentFlags().Lookup("kubeconfig"))
52+
viper.BindPFlag("region", rootCmd.PersistentFlags().Lookup("region"))
53+
viper.BindPFlag("loglevel", rootCmd.PersistentFlags().Lookup("loglevel"))
54+
viper.BindPFlag("logfile", rootCmd.PersistentFlags().Lookup("logfile"))
55+
viper.BindPFlag("resources", rootCmd.PersistentFlags().Lookup("resources"))
56+
viper.BindPFlag("clustername", rootCmd.PersistentFlags().Lookup("cluster-name"))
57+
viper.BindPFlag("bucket", rootCmd.PersistentFlags().Lookup("bucket"))
58+
viper.BindPFlag("accountid", rootCmd.PersistentFlags().Lookup("account-id"))
59+
}
60+
61+
// initConfig reads in config file and ENV variables if set.
62+
func initConfig() {
63+
if cfgFile != "" {
64+
viper.SetConfigFile(cfgFile)
65+
} else {
66+
home, err := homedir.Dir()
67+
if err != nil {
68+
fmt.Println(err)
69+
os.Exit(1)
70+
}
71+
72+
viper.AddConfigPath(home)
73+
viper.SetConfigName(".aws-operator")
74+
}
75+
76+
replacer := strings.NewReplacer(".", "_")
77+
viper.SetEnvKeyReplacer(replacer)
78+
viper.AutomaticEnv()
79+
80+
if err := viper.ReadInConfig(); err == nil {
81+
fmt.Println("Using config file:", viper.ConfigFileUsed())
82+
}
83+
}
84+
85+
func getConfig() (*config.Config, error) {
86+
resourcesList := strings.Split(resources, ",")
87+
config := &config.Config{
88+
Region: awsRegion,
89+
Kubeconfig: kubeconfig,
90+
LoggingConfig: &config.LoggingConfig{
91+
File: logFile,
92+
Level: logLevel,
93+
FullTimestamps: true,
94+
DisableTimestamps: false,
95+
},
96+
Resources: resourcesList,
97+
ClusterName: clusterName,
98+
Bucket: bucket,
99+
AccountID: accountID,
100+
}
101+
102+
return config, nil
103+
}

cmd/aws-service-operator/server.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"github.com/christopherhein/aws-operator/pkg/logger"
5+
"github.com/christopherhein/aws-operator/pkg/server"
6+
"github.com/sirupsen/logrus"
7+
"github.com/spf13/cobra"
8+
"os"
9+
"os/signal"
10+
"syscall"
11+
)
12+
13+
var serverCmd = &cobra.Command{
14+
Use: "server",
15+
Short: "Run the operator",
16+
Long: ``,
17+
Run: func(cmd *cobra.Command, args []string) {
18+
config, err := getConfig()
19+
if err != nil {
20+
logrus.Fatalf("%s", err)
21+
}
22+
23+
logger, err := logger.Configure(config.LoggingConfig)
24+
if err != nil {
25+
logrus.Fatalf("Failed to configure logging: '%s'" + err.Error())
26+
}
27+
config.Logger = logger
28+
29+
signalChan := make(chan os.Signal, 1)
30+
stopChan := make(chan struct{})
31+
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
32+
33+
server.New(config).Run(stopChan)
34+
35+
for {
36+
select {
37+
case <-signalChan:
38+
logger.Info("shutdown signal received, exiting...")
39+
close(stopChan)
40+
return
41+
}
42+
}
43+
44+
},
45+
}
46+
47+
func init() {
48+
rootCmd.AddCommand(serverCmd)
49+
}

cmd/aws-service-operator/version.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
goVersion "github.com/christopherhein/go-version"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var (
10+
shortened = false
11+
version = "dev"
12+
commit = "none"
13+
date = "unknown"
14+
versionCmd = &cobra.Command{
15+
Use: "version",
16+
Short: "Version will output the current aws-operator build information",
17+
Long: ``,
18+
Run: func(_ *cobra.Command, _ []string) {
19+
var response string
20+
versionOutput := goVersion.New(version, commit, date)
21+
22+
if shortened {
23+
response = versionOutput.ToShortened()
24+
} else {
25+
response = versionOutput.ToJSON()
26+
}
27+
fmt.Printf("%+v", response)
28+
return
29+
},
30+
}
31+
)
32+
33+
func init() {
34+
versionCmd.Flags().BoolVarP(&shortened, "short", "s", false, "Use shortened output for version information.")
35+
rootCmd.AddCommand(versionCmd)
36+
}

0 commit comments

Comments
 (0)