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 source for new base operator list
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Hein <me@christopherhein.com>
  • Loading branch information
christopherhein committed Oct 16, 2018
1 parent 4c6e4c5 commit 23dfa95
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# >>>>>>> DO NOT EDIT THIS FILE <<<<<<<<<<
# This file is autogenerated via `aws-operator generate`
# If you'd like the change anything about this file make edits to the .templ
# file in the pkg/codegen/assets directory.
apiVersion: v1
kind: List
items:
Expand Down
40 changes: 40 additions & 0 deletions code-generation/pkg/codegen/assets/base.go.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package base

import (
"github.com/awslabs/aws-service-operator/pkg/config"
opkit "github.com/christopherhein/operator-kit"
awsclient "github.com/awslabs/aws-service-operator/pkg/client/clientset/versioned/typed/service-operator.aws/v1alpha1"
{{- range $index, $element := .Items}}
"github.com/awslabs/aws-service-operator/pkg/operators/{{$element.Spec.Resource.Name}}"
{{- end}}
)

type base struct {
config *config.Config
context *opkit.Context
awsClientset awsclient.ServiceoperatorV1alpha1Interface
}

func New(
config *config.Config,
context *opkit.Context,
awsClientset awsclient.ServiceoperatorV1alpha1Interface,
) *base {
return &base{
config: config,
context: context,
awsClientset: awsClientset,
}
}

func (b *base) Watch(namespace string, stopCh chan struct{}) (err error) {
{{- range $index, $element := .Items}}
{{$element.Spec.Resource.Name}}operator := {{$element.Spec.Resource.Name}}.NewOperator(b.config, b.context, b.awsClientset)
err = {{$element.Spec.Resource.Name}}operator.StartWatch(namespace, stopCh)
if err != nil {
return err
}
{{- end}}

return nil
}
20 changes: 10 additions & 10 deletions code-generation/pkg/codegen/assets/operator.go.templ
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,25 @@ var Resource = opkit.CustomResource{
},
}

// Controller represents a controller object for object store custom resources
type Controller struct {
// Operator represents a controller object for object store custom resources
type Operator struct {
config *config.Config
context *opkit.Context
awsclientset awsclient.ServiceoperatorV1alpha1Interface
topicARN string
}

// NewController create controller for watching object store custom resources created
func NewController(config *config.Config, context *opkit.Context, awsclientset awsclient.ServiceoperatorV1alpha1Interface) *Controller {
return &Controller{
// NewOperator create controller for watching object store custom resources created
func NewOperator(config *config.Config, context *opkit.Context, awsclientset awsclient.ServiceoperatorV1alpha1Interface) *Operator {
return &Operator{
config: config,
context: context,
awsclientset: awsclientset,
}
}

// StartWatch watches for instances of Object Store custom resources and acts on them
func (c *Controller) StartWatch(namespace string, stopCh chan struct{}) error {
func (c *Operator) StartWatch(namespace string, stopCh chan struct{}) error {
resourceHandlers := cache.ResourceEventHandlerFuncs{
AddFunc: c.onAdd,
UpdateFunc: c.onUpdate,
Expand Down Expand Up @@ -137,14 +137,14 @@ func QueueUpdater(config *config.Config, msg *queue.MessageBody) error {
}
config.Recorder.AnnotatedEventf(obj, annotations, corev1.EventTypeNormal, strcase.ToCamel(strings.ToLower(msg.ParsedMessage["ResourceStatus"])), msg.ParsedMessage["ResourceStatusReason"])
}

}

return nil
}
{{- end}}

func (c *Controller) onAdd(obj interface{}) {
func (c *Operator) onAdd(obj interface{}) {
s := obj.(*awsV1alpha1.{{.Spec.Kind}}).DeepCopy()

{{- if not .Spec.Customizations.Add}}
Expand All @@ -168,7 +168,7 @@ func (c *Controller) onAdd(obj interface{}) {
{{- end}}
}

func (c *Controller) onUpdate(oldObj, newObj interface{}) {
func (c *Operator) onUpdate(oldObj, newObj interface{}) {
oo := oldObj.(*awsV1alpha1.{{.Spec.Kind}}).DeepCopy()
no := newObj.(*awsV1alpha1.{{.Spec.Kind}}).DeepCopy()

Expand Down Expand Up @@ -197,7 +197,7 @@ func (c *Controller) onUpdate(oldObj, newObj interface{}) {
{{- end}}
}

func (c *Controller) onDelete(obj interface{}) {
func (c *Operator) onDelete(obj interface{}) {
s := obj.(*awsV1alpha1.{{.Spec.Kind}}).DeepCopy()

{{- if not .Spec.Customizations.Delete}}
Expand Down
4 changes: 3 additions & 1 deletion code-generation/pkg/codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (c *Codegen) Run() error {
}
models.Items = append(models.Items, parsedModel)

operatorPath := rootPath + "pkg/operator/" + parsedModel.Spec.Resource.Name
operatorPath := rootPath + "pkg/operators/" + parsedModel.Spec.Resource.Name
apiPath := rootPath + "pkg/apis/service-operator.aws/v1alpha1"

createDirIfNotExist(operatorPath)
Expand All @@ -131,9 +131,11 @@ func (c *Codegen) Run() error {

helpersPath := rootPath + "pkg/helpers"
configPath := rootPath + "configs"
operatorsPath := rootPath + "pkg/operators/base"

createFile(rootPath, "template_functions.go", "template_functions.go", helpersPath+"/", models)
createFile(rootPath, "aws-service-operator.yaml", "aws-service-operator.yaml", configPath+"/", models)
createFile(rootPath, "base.go", "base.go", operatorsPath+"/", models)

return nil
}
Expand Down
Loading

0 comments on commit 23dfa95

Please sign in to comment.