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

Commit

Permalink
Adding code generation for non-pointer config
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Hein <me@christopherhein.com>
  • Loading branch information
christopherhein committed Nov 28, 2018
1 parent 98c4c6b commit 6bb21f3
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 72 deletions.
28 changes: 14 additions & 14 deletions pkg/helpers/template_functions.go
Expand Up @@ -28,17 +28,17 @@ func New() Helpers {
// Helpers defines all the Helper functions that are exposed to the templates
type Helpers struct {
KubernetesResourceName func(string) string
GetCloudFormationTemplateByName func(*config.Config, string, string) (interface{}, error)
GetDynamoDBByName func(*config.Config, string, string) (interface{}, error)
GetECRRepositoryByName func(*config.Config, string, string) (interface{}, error)
GetS3BucketByName func(*config.Config, string, string) (interface{}, error)
GetSNSSubscriptionByName func(*config.Config, string, string) (interface{}, error)
GetSNSTopicByName func(*config.Config, string, string) (interface{}, error)
GetSQSQueueByName func(*config.Config, string, string) (interface{}, error)
GetCloudFormationTemplateByName func(config.Config, string, string) (interface{}, error)
GetDynamoDBByName func(config.Config, string, string) (interface{}, error)
GetECRRepositoryByName func(config.Config, string, string) (interface{}, error)
GetS3BucketByName func(config.Config, string, string) (interface{}, error)
GetSNSSubscriptionByName func(config.Config, string, string) (interface{}, error)
GetSNSTopicByName func(config.Config, string, string) (interface{}, error)
GetSQSQueueByName func(config.Config, string, string) (interface{}, error)
}

// GetCloudFormationTemplateByName will find the resource by name
func GetCloudFormationTemplateByName(config *config.Config, name string, namespace string) (interface{}, error) {
func GetCloudFormationTemplateByName(config config.Config, name string, namespace string) (interface{}, error) {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.CloudFormationTemplates(namespace).Get(name, metav1.GetOptions{})
Expand All @@ -51,7 +51,7 @@ func GetCloudFormationTemplateByName(config *config.Config, name string, namespa
}

// GetDynamoDBByName will find the resource by name
func GetDynamoDBByName(config *config.Config, name string, namespace string) (interface{}, error) {
func GetDynamoDBByName(config config.Config, name string, namespace string) (interface{}, error) {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.DynamoDBs(namespace).Get(name, metav1.GetOptions{})
Expand All @@ -64,7 +64,7 @@ func GetDynamoDBByName(config *config.Config, name string, namespace string) (in
}

// GetECRRepositoryByName will find the resource by name
func GetECRRepositoryByName(config *config.Config, name string, namespace string) (interface{}, error) {
func GetECRRepositoryByName(config config.Config, name string, namespace string) (interface{}, error) {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.ECRRepositories(namespace).Get(name, metav1.GetOptions{})
Expand All @@ -77,7 +77,7 @@ func GetECRRepositoryByName(config *config.Config, name string, namespace string
}

// GetS3BucketByName will find the resource by name
func GetS3BucketByName(config *config.Config, name string, namespace string) (interface{}, error) {
func GetS3BucketByName(config config.Config, name string, namespace string) (interface{}, error) {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.S3Buckets(namespace).Get(name, metav1.GetOptions{})
Expand All @@ -90,7 +90,7 @@ func GetS3BucketByName(config *config.Config, name string, namespace string) (in
}

// GetSNSSubscriptionByName will find the resource by name
func GetSNSSubscriptionByName(config *config.Config, name string, namespace string) (interface{}, error) {
func GetSNSSubscriptionByName(config config.Config, name string, namespace string) (interface{}, error) {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.SNSSubscriptions(namespace).Get(name, metav1.GetOptions{})
Expand All @@ -103,7 +103,7 @@ func GetSNSSubscriptionByName(config *config.Config, name string, namespace stri
}

// GetSNSTopicByName will find the resource by name
func GetSNSTopicByName(config *config.Config, name string, namespace string) (interface{}, error) {
func GetSNSTopicByName(config config.Config, name string, namespace string) (interface{}, error) {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.SNSTopics(namespace).Get(name, metav1.GetOptions{})
Expand All @@ -116,7 +116,7 @@ func GetSNSTopicByName(config *config.Config, name string, namespace string) (in
}

// GetSQSQueueByName will find the resource by name
func GetSQSQueueByName(config *config.Config, name string, namespace string) (interface{}, error) {
func GetSQSQueueByName(config config.Config, name string, namespace string) (interface{}, error) {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.SQSQueues(namespace).Get(name, metav1.GetOptions{})
Expand Down
4 changes: 2 additions & 2 deletions pkg/operators/base/base.go
Expand Up @@ -14,7 +14,7 @@ import (
)

type base struct {
config *config.Config
config config.Config
queueManager *queuemanager.QueueManager
cloudformationtemplate *cloudformationtemplate.Operator
dynamodb *dynamodb.Operator
Expand All @@ -26,7 +26,7 @@ type base struct {
}

func New(
config *config.Config,
config config.Config,
queueManager *queuemanager.QueueManager,
) *base {
return &base{
Expand Down
4 changes: 2 additions & 2 deletions pkg/operators/cloudformationtemplate/operator.go
Expand Up @@ -19,13 +19,13 @@ import (

// Operator represents a controller object for object store custom resources
type Operator struct {
config *config.Config
config config.Config
topicARN string
queueManager *queuemanager.QueueManager
}

// NewOperator create controller for watching object store custom resources created
func NewOperator(config *config.Config, queueManager *queuemanager.QueueManager) *Operator {
func NewOperator(config config.Config, queueManager *queuemanager.QueueManager) *Operator {

return &Operator{
config: config,
Expand Down
4 changes: 2 additions & 2 deletions pkg/operators/dynamodb/cft.go
Expand Up @@ -15,7 +15,7 @@ import (
)

// New generates a new object
func New(config *config.Config, dynamodb *awsV1alpha1.DynamoDB, topicARN string) *Cloudformation {
func New(config config.Config, dynamodb *awsV1alpha1.DynamoDB, topicARN string) *Cloudformation {
return &Cloudformation{
DynamoDB: dynamodb,
config: config,
Expand All @@ -25,7 +25,7 @@ func New(config *config.Config, dynamodb *awsV1alpha1.DynamoDB, topicARN string)

// Cloudformation defines the dynamodb cfts
type Cloudformation struct {
config *config.Config
config config.Config
DynamoDB *awsV1alpha1.DynamoDB
topicARN string
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/operators/dynamodb/operator.go
Expand Up @@ -26,13 +26,13 @@ import (

// Operator represents a controller object for object store custom resources
type Operator struct {
config *config.Config
config config.Config
topicARN string
queueManager *queuemanager.QueueManager
}

// NewOperator create controller for watching object store custom resources created
func NewOperator(config *config.Config, queueManager *queuemanager.QueueManager) *Operator {
func NewOperator(config config.Config, queueManager *queuemanager.QueueManager) *Operator {
queuectrl := queue.New(config, config.AWSClientset, 10)
topicARN, _ := queuectrl.Register("dynamodb")
queueManager.Add(topicARN, queuemanager.HandlerFunc(QueueUpdater))
Expand All @@ -57,7 +57,7 @@ func (c *Operator) StartWatch(ctx context.Context, namespace string) {
}

// QueueUpdater will take the messages from the queue and process them
func QueueUpdater(config *config.Config, msg *queuemanager.MessageBody) error {
func QueueUpdater(config config.Config, msg *queuemanager.MessageBody) error {
logger := config.Logger
var name, namespace string
if msg.Updatable {
Expand Down Expand Up @@ -167,7 +167,7 @@ func (c *Operator) onDelete(obj interface{}) {

c.config.Logger.Infof("deleted dynamodb '%s'", s.Name)
}
func incrementRollbackCount(config *config.Config, name string, namespace string) error {
func incrementRollbackCount(config config.Config, name string, namespace string) error {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.DynamoDBs(namespace).Get(name, metav1.GetOptions{})
Expand All @@ -187,7 +187,7 @@ func incrementRollbackCount(config *config.Config, name string, namespace string
return nil
}

func updateStatus(config *config.Config, name string, namespace string, stackID string, status string, reason string) (*awsV1alpha1.DynamoDB, error) {
func updateStatus(config config.Config, name string, namespace string, stackID string, status string, reason string) (*awsV1alpha1.DynamoDB, error) {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.DynamoDBs(namespace).Get(name, metav1.GetOptions{})
Expand Down Expand Up @@ -226,7 +226,7 @@ func updateStatus(config *config.Config, name string, namespace string, stackID
return resourceCopy, nil
}

func deleteStack(config *config.Config, name string, namespace string, stackID string) (*awsV1alpha1.DynamoDB, error) {
func deleteStack(config config.Config, name string, namespace string, stackID string) (*awsV1alpha1.DynamoDB, error) {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.DynamoDBs(namespace).Get(name, metav1.GetOptions{})
Expand All @@ -245,7 +245,7 @@ func deleteStack(config *config.Config, name string, namespace string, stackID s
return resource, err
}

func syncAdditionalResources(config *config.Config, s *awsV1alpha1.DynamoDB) (err error) {
func syncAdditionalResources(config config.Config, s *awsV1alpha1.DynamoDB) (err error) {
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.DynamoDBs(s.Namespace).Get(s.Name, metav1.GetOptions{})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/operators/ecrrepository/cft.go
Expand Up @@ -15,7 +15,7 @@ import (
)

// New generates a new object
func New(config *config.Config, ecrrepository *awsV1alpha1.ECRRepository, topicARN string) *Cloudformation {
func New(config config.Config, ecrrepository *awsV1alpha1.ECRRepository, topicARN string) *Cloudformation {
return &Cloudformation{
ECRRepository: ecrrepository,
config: config,
Expand All @@ -25,7 +25,7 @@ func New(config *config.Config, ecrrepository *awsV1alpha1.ECRRepository, topicA

// Cloudformation defines the ecrrepository cfts
type Cloudformation struct {
config *config.Config
config config.Config
ECRRepository *awsV1alpha1.ECRRepository
topicARN string
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/operators/ecrrepository/operator.go
Expand Up @@ -26,13 +26,13 @@ import (

// Operator represents a controller object for object store custom resources
type Operator struct {
config *config.Config
config config.Config
topicARN string
queueManager *queuemanager.QueueManager
}

// NewOperator create controller for watching object store custom resources created
func NewOperator(config *config.Config, queueManager *queuemanager.QueueManager) *Operator {
func NewOperator(config config.Config, queueManager *queuemanager.QueueManager) *Operator {
queuectrl := queue.New(config, config.AWSClientset, 10)
topicARN, _ := queuectrl.Register("ecrrepository")
queueManager.Add(topicARN, queuemanager.HandlerFunc(QueueUpdater))
Expand All @@ -57,7 +57,7 @@ func (c *Operator) StartWatch(ctx context.Context, namespace string) {
}

// QueueUpdater will take the messages from the queue and process them
func QueueUpdater(config *config.Config, msg *queuemanager.MessageBody) error {
func QueueUpdater(config config.Config, msg *queuemanager.MessageBody) error {
logger := config.Logger
var name, namespace string
if msg.Updatable {
Expand Down Expand Up @@ -167,7 +167,7 @@ func (c *Operator) onDelete(obj interface{}) {

c.config.Logger.Infof("deleted ecrrepository '%s'", s.Name)
}
func incrementRollbackCount(config *config.Config, name string, namespace string) error {
func incrementRollbackCount(config config.Config, name string, namespace string) error {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.ECRRepositories(namespace).Get(name, metav1.GetOptions{})
Expand All @@ -187,7 +187,7 @@ func incrementRollbackCount(config *config.Config, name string, namespace string
return nil
}

func updateStatus(config *config.Config, name string, namespace string, stackID string, status string, reason string) (*awsV1alpha1.ECRRepository, error) {
func updateStatus(config config.Config, name string, namespace string, stackID string, status string, reason string) (*awsV1alpha1.ECRRepository, error) {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.ECRRepositories(namespace).Get(name, metav1.GetOptions{})
Expand Down Expand Up @@ -228,7 +228,7 @@ func updateStatus(config *config.Config, name string, namespace string, stackID
return resourceCopy, nil
}

func deleteStack(config *config.Config, name string, namespace string, stackID string) (*awsV1alpha1.ECRRepository, error) {
func deleteStack(config config.Config, name string, namespace string, stackID string) (*awsV1alpha1.ECRRepository, error) {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.ECRRepositories(namespace).Get(name, metav1.GetOptions{})
Expand All @@ -247,7 +247,7 @@ func deleteStack(config *config.Config, name string, namespace string, stackID s
return resource, err
}

func syncAdditionalResources(config *config.Config, s *awsV1alpha1.ECRRepository) (err error) {
func syncAdditionalResources(config config.Config, s *awsV1alpha1.ECRRepository) (err error) {
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.ECRRepositories(s.Namespace).Get(s.Name, metav1.GetOptions{})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/operators/s3bucket/cft.go
Expand Up @@ -15,7 +15,7 @@ import (
)

// New generates a new object
func New(config *config.Config, s3bucket *awsV1alpha1.S3Bucket, topicARN string) *Cloudformation {
func New(config config.Config, s3bucket *awsV1alpha1.S3Bucket, topicARN string) *Cloudformation {
return &Cloudformation{
S3Bucket: s3bucket,
config: config,
Expand All @@ -25,7 +25,7 @@ func New(config *config.Config, s3bucket *awsV1alpha1.S3Bucket, topicARN string)

// Cloudformation defines the s3bucket cfts
type Cloudformation struct {
config *config.Config
config config.Config
S3Bucket *awsV1alpha1.S3Bucket
topicARN string
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/operators/s3bucket/operator.go
Expand Up @@ -26,13 +26,13 @@ import (

// Operator represents a controller object for object store custom resources
type Operator struct {
config *config.Config
config config.Config
topicARN string
queueManager *queuemanager.QueueManager
}

// NewOperator create controller for watching object store custom resources created
func NewOperator(config *config.Config, queueManager *queuemanager.QueueManager) *Operator {
func NewOperator(config config.Config, queueManager *queuemanager.QueueManager) *Operator {
queuectrl := queue.New(config, config.AWSClientset, 10)
topicARN, _ := queuectrl.Register("s3bucket")
queueManager.Add(topicARN, queuemanager.HandlerFunc(QueueUpdater))
Expand All @@ -57,7 +57,7 @@ func (c *Operator) StartWatch(ctx context.Context, namespace string) {
}

// QueueUpdater will take the messages from the queue and process them
func QueueUpdater(config *config.Config, msg *queuemanager.MessageBody) error {
func QueueUpdater(config config.Config, msg *queuemanager.MessageBody) error {
logger := config.Logger
var name, namespace string
if msg.Updatable {
Expand Down Expand Up @@ -167,7 +167,7 @@ func (c *Operator) onDelete(obj interface{}) {

c.config.Logger.Infof("deleted s3bucket '%s'", s.Name)
}
func incrementRollbackCount(config *config.Config, name string, namespace string) error {
func incrementRollbackCount(config config.Config, name string, namespace string) error {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.S3Buckets(namespace).Get(name, metav1.GetOptions{})
Expand All @@ -187,7 +187,7 @@ func incrementRollbackCount(config *config.Config, name string, namespace string
return nil
}

func updateStatus(config *config.Config, name string, namespace string, stackID string, status string, reason string) (*awsV1alpha1.S3Bucket, error) {
func updateStatus(config config.Config, name string, namespace string, stackID string, status string, reason string) (*awsV1alpha1.S3Bucket, error) {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.S3Buckets(namespace).Get(name, metav1.GetOptions{})
Expand Down Expand Up @@ -227,7 +227,7 @@ func updateStatus(config *config.Config, name string, namespace string, stackID
return resourceCopy, nil
}

func deleteStack(config *config.Config, name string, namespace string, stackID string) (*awsV1alpha1.S3Bucket, error) {
func deleteStack(config config.Config, name string, namespace string, stackID string) (*awsV1alpha1.S3Bucket, error) {
logger := config.Logger
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.S3Buckets(namespace).Get(name, metav1.GetOptions{})
Expand All @@ -246,7 +246,7 @@ func deleteStack(config *config.Config, name string, namespace string, stackID s
return resource, err
}

func syncAdditionalResources(config *config.Config, s *awsV1alpha1.S3Bucket) (err error) {
func syncAdditionalResources(config config.Config, s *awsV1alpha1.S3Bucket) (err error) {
clientSet, _ := awsclient.NewForConfig(config.RESTConfig)
resource, err := clientSet.S3Buckets(s.Namespace).Get(s.Name, metav1.GetOptions{})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/operators/snssubscription/cft.go
Expand Up @@ -15,7 +15,7 @@ import (
)

// New generates a new object
func New(config *config.Config, snssubscription *awsV1alpha1.SNSSubscription, topicARN string) *Cloudformation {
func New(config config.Config, snssubscription *awsV1alpha1.SNSSubscription, topicARN string) *Cloudformation {
return &Cloudformation{
SNSSubscription: snssubscription,
config: config,
Expand All @@ -25,7 +25,7 @@ func New(config *config.Config, snssubscription *awsV1alpha1.SNSSubscription, to

// Cloudformation defines the snssubscription cfts
type Cloudformation struct {
config *config.Config
config config.Config
SNSSubscription *awsV1alpha1.SNSSubscription
topicARN string
}
Expand Down

0 comments on commit 6bb21f3

Please sign in to comment.