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

Commit

Permalink
Merge pull request #107 from christopherhein/chore/23-codegen-crds
Browse files Browse the repository at this point in the history
Remove Operator-Kit in favor of manually managing the operator server
  • Loading branch information
Christopher Hein committed Oct 16, 2018
2 parents d504206 + ffdc6d1 commit c8fccb2
Show file tree
Hide file tree
Showing 11,316 changed files with 772 additions and 2,460,980 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
5 changes: 5 additions & 0 deletions .generated_files
@@ -0,0 +1,5 @@
file-prefix zz_generated.
path-prefix pkg/client/
path-prefix pkg/operator
file-name template_functions.go
file-name aws-service-operator.yaml
34 changes: 1 addition & 33 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions Gopkg.toml
Expand Up @@ -30,18 +30,10 @@ required = ["k8s.io/code-generator/cmd/client-gen"]
branch = "master"
name = "github.com/golang/glog"

[[constraint]]
branch = "master"
name = "github.com/christopherhein/operator-kit"

[[constraint]]
name = "k8s.io/api"
version = "kubernetes-1.11.3"

[[constraint]]
name = "k8s.io/apiextensions-apiserver"
version = "kubernetes-1.11.3"

[[constraint]]
name = "k8s.io/apimachinery"
version = "kubernetes-1.11.3"
Expand Down
5 changes: 5 additions & 0 deletions Makefile
@@ -1,5 +1,6 @@
commitSHA := $(shell git describe --dirty --always)
dateStr := $(shell date +%s)
repo ?= github.com/awslab/aws-service-operator

.PHONY: build
build:
Expand All @@ -13,6 +14,10 @@ release:
dev-release:
goreleaser --rm-dist --snapshot --skip-publish

.PHONY: test
test:
go test -v -cover -race $(repo)/...

.PHONY: tag
tag:
git tag -a ${VERSION} -s
Expand Down
4 changes: 2 additions & 2 deletions cloudformation/dynamodb.yaml
@@ -1,5 +1,5 @@
AWSTemplateFormatVersion: 2010-09-09
Description: 'AWS Operator - Amazon DynamoDB'
Description: 'AWS Service Operator - Amazon DynamoDB'
Parameters:
Namespace:
Description: >-
Expand Down Expand Up @@ -63,7 +63,7 @@ Resources:
-
AttributeName: !Ref RangeAttributeName
KeyType: "RANGE"
AttributeDefinitions:
AttributeDefinitions:
-
AttributeName: !Ref HashAttributeName
AttributeType: "S"
Expand Down
2 changes: 1 addition & 1 deletion cloudformation/ecrrepository.yaml
@@ -1,5 +1,5 @@
AWSTemplateFormatVersion: 2010-09-09
Description: 'AWS Operator - Amazon ECR Repository'
Description: 'AWS Service Operator - Amazon ECR Repository'
Parameters:
Namespace:
Description: >-
Expand Down
16 changes: 8 additions & 8 deletions cloudformation/s3bucket.yaml
@@ -1,5 +1,5 @@
AWSTemplateFormatVersion: 2010-09-09
Description: 'AWS Operator - Amazon S3 Bucket'
Description: 'AWS Service Operator - Amazon S3 Bucket'
Parameters:
Namespace:
Description: >-
Expand Down Expand Up @@ -90,13 +90,13 @@ Parameters:
Default: "500.html"
Mappings: {}
Conditions:
UseLogging: !Equals
UseLogging: !Equals
- !Ref EnableLogging
- 'true'
UseGlacierLifeCycle: !Equals
UseGlacierLifeCycle: !Equals
- !Ref EnableGlacierLifeCycle
- 'true'
UseVersioning: !Equals
UseVersioning: !Equals
- !Ref EnableVersioning
- 'true'
UseAsStaticSite: !Equals
Expand All @@ -122,7 +122,7 @@ Resources:
Transitions:
- TransitionInDays: !Ref GlacierLifeCycleTransitionInDays
StorageClass: Glacier
LoggingConfiguration: !If
LoggingConfiguration: !If
- UseLogging
- DestinationBucketName: !Ref LoggingBucket
LogFilePrefix: !Ref LoggingPrefix
Expand All @@ -138,7 +138,7 @@ Resources:
Value: !Ref ClusterName
- Key: Heritage
Value: operator.aws
VersioningConfiguration: !If
VersioningConfiguration: !If
- UseVersioning
- Status: Enabled
- !Ref 'AWS::NoValue'
Expand Down Expand Up @@ -171,7 +171,7 @@ Resources:
DeletionPolicy: Retain
Properties:
AccessControl: LogDeliveryWrite
BucketName: !Join
BucketName: !Join
- ''
- - !Ref BucketName
- logging
Expand All @@ -180,7 +180,7 @@ Outputs:
Value: !Ref S3bucket
Description: Name of the sample Amazon S3 bucket.
BucketArn:
Value: !GetAtt
Value: !GetAtt
- S3bucket
- Arn
Description: Name of the Amazon S3 bucket
Expand Down
2 changes: 1 addition & 1 deletion cloudformation/snssubscription.yaml
@@ -1,5 +1,5 @@
AWSTemplateFormatVersion: 2010-09-09
Description: 'AWS Operator - Amazon SNS Subscription'
Description: 'AWS Service Operator - Amazon SNS Subscription'
Parameters:
Namespace:
Description: >-
Expand Down
2 changes: 1 addition & 1 deletion cloudformation/snstopic.yaml
@@ -1,5 +1,5 @@
AWSTemplateFormatVersion: 2010-09-09
Description: 'AWS Operator - Amazon SNS Topic'
Description: 'AWS Service Operator - Amazon SNS Topic'
Parameters:
Namespace:
Description: >-
Expand Down
2 changes: 1 addition & 1 deletion cloudformation/sqsqueue.yaml
@@ -1,5 +1,5 @@
AWSTemplateFormatVersion: 2010-09-09
Description: "AWS Operator - Amazon SQS Queue"
Description: "AWS Service Operator - Amazon SQS Queue"
Parameters:
Namespace:
Type: String
Expand Down
52 changes: 40 additions & 12 deletions cmd/aws-service-operator/main.go
Expand Up @@ -2,25 +2,26 @@ package main

import (
"fmt"
homedir "github.com/mitchellh/go-homedir"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/awslabs/aws-service-operator/pkg/config"

homedir "github.com/mitchellh/go-homedir"
"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
// cfgFile, masterURL, kubeConfig, awsRegion all help support passed in flags into the server
cfgFile, masterURL, 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: `AWS Operator manages your AWS Infrastructure using CRDs and Operators.
Long: `AWS Operator manages your AWS Infrastructure using CRDs and Operators.
With a single manifest file you can now model both the application and the resource necessary to run it.`,
Run: func(c *cobra.Command, _ []string) {
c.Help()
Expand All @@ -39,16 +40,18 @@ func main() {

func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "f", "Config file (default is $HOME/.aws-operator.yaml)")
rootCmd.PersistentFlags().StringVarP(&masterURL, "master-url", "u", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig.")
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(&resources, "resources", "", "cloudformationtemplates,dynamodb,ecrrepository,s3bucket,snssubscription,snstopic,sqsqueue", "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("masterurl", rootCmd.PersistentFlags().Lookup("master-url"))
viper.BindPFlag("kubeconfig", rootCmd.PersistentFlags().Lookup("kubeconfig"))
viper.BindPFlag("region", rootCmd.PersistentFlags().Lookup("region"))
viper.BindPFlag("loglevel", rootCmd.PersistentFlags().Lookup("loglevel"))
Expand Down Expand Up @@ -83,22 +86,47 @@ func initConfig() {
}
}

func getConfig() (*config.Config, error) {
resourcesList := strings.Split(resources, ",")
config := &config.Config{
func getConfig() (c *config.Config, err error) {
resourcesMap := map[string]bool{}
for _, r := range strings.Split(resources, ",") {
resourcesMap[r] = true
}

ec2Session, err := session.NewSession()
metadata := ec2metadata.New(ec2Session)
if awsRegion == "" {
awsRegion, err = metadata.Region()
if err != nil {
return nil, err
}
}

sess, err := session.NewSession(&aws.Config{Region: aws.String(awsRegion)})
if err != nil {
return nil, err
}

c = &config.Config{
Region: awsRegion,
Kubeconfig: kubeconfig,
MasterURL: masterURL,
AWSSession: sess,
LoggingConfig: &config.LoggingConfig{
File: logFile,
Level: logLevel,
FullTimestamps: true,
DisableTimestamps: false,
},
Resources: resourcesList,
Resources: resourcesMap,
ClusterName: clusterName,
Bucket: bucket,
AccountID: accountID,
}

return config, nil
err = c.CreateContext(masterURL, kubeconfig)
if err != nil {
return nil, err
}

return c, nil
}

0 comments on commit c8fccb2

Please sign in to comment.