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

Commit 23dfa95

Browse files
Adding Code Generation source for new base operator list
Signed-off-by: Christopher Hein <[email protected]>
1 parent 4c6e4c5 commit 23dfa95

File tree

5 files changed

+85
-15
lines changed

5 files changed

+85
-15
lines changed

code-generation/pkg/codegen/assets/aws-service-operator.yaml.templ

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# >>>>>>> DO NOT EDIT THIS FILE <<<<<<<<<<
2+
# This file is autogenerated via `aws-operator generate`
3+
# If you'd like the change anything about this file make edits to the .templ
4+
# file in the pkg/codegen/assets directory.
5+
16
apiVersion: v1
27
kind: List
38
items:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package base
2+
3+
import (
4+
"github.com/awslabs/aws-service-operator/pkg/config"
5+
opkit "github.com/christopherhein/operator-kit"
6+
awsclient "github.com/awslabs/aws-service-operator/pkg/client/clientset/versioned/typed/service-operator.aws/v1alpha1"
7+
{{- range $index, $element := .Items}}
8+
"github.com/awslabs/aws-service-operator/pkg/operators/{{$element.Spec.Resource.Name}}"
9+
{{- end}}
10+
)
11+
12+
type base struct {
13+
config *config.Config
14+
context *opkit.Context
15+
awsClientset awsclient.ServiceoperatorV1alpha1Interface
16+
}
17+
18+
func New(
19+
config *config.Config,
20+
context *opkit.Context,
21+
awsClientset awsclient.ServiceoperatorV1alpha1Interface,
22+
) *base {
23+
return &base{
24+
config: config,
25+
context: context,
26+
awsClientset: awsClientset,
27+
}
28+
}
29+
30+
func (b *base) Watch(namespace string, stopCh chan struct{}) (err error) {
31+
{{- range $index, $element := .Items}}
32+
{{$element.Spec.Resource.Name}}operator := {{$element.Spec.Resource.Name}}.NewOperator(b.config, b.context, b.awsClientset)
33+
err = {{$element.Spec.Resource.Name}}operator.StartWatch(namespace, stopCh)
34+
if err != nil {
35+
return err
36+
}
37+
{{- end}}
38+
39+
return nil
40+
}

code-generation/pkg/codegen/assets/operator.go.templ

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,25 @@ var Resource = opkit.CustomResource{
4848
},
4949
}
5050

51-
// Controller represents a controller object for object store custom resources
52-
type Controller struct {
51+
// Operator represents a controller object for object store custom resources
52+
type Operator struct {
5353
config *config.Config
5454
context *opkit.Context
5555
awsclientset awsclient.ServiceoperatorV1alpha1Interface
5656
topicARN string
5757
}
5858

59-
// NewController create controller for watching object store custom resources created
60-
func NewController(config *config.Config, context *opkit.Context, awsclientset awsclient.ServiceoperatorV1alpha1Interface) *Controller {
61-
return &Controller{
59+
// NewOperator create controller for watching object store custom resources created
60+
func NewOperator(config *config.Config, context *opkit.Context, awsclientset awsclient.ServiceoperatorV1alpha1Interface) *Operator {
61+
return &Operator{
6262
config: config,
6363
context: context,
6464
awsclientset: awsclientset,
6565
}
6666
}
6767

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

143143
return nil
144144
}
145145
{{- end}}
146146

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

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

171-
func (c *Controller) onUpdate(oldObj, newObj interface{}) {
171+
func (c *Operator) onUpdate(oldObj, newObj interface{}) {
172172
oo := oldObj.(*awsV1alpha1.{{.Spec.Kind}}).DeepCopy()
173173
no := newObj.(*awsV1alpha1.{{.Spec.Kind}}).DeepCopy()
174174

@@ -197,7 +197,7 @@ func (c *Controller) onUpdate(oldObj, newObj interface{}) {
197197
{{- end}}
198198
}
199199

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

203203
{{- if not .Spec.Customizations.Delete}}

code-generation/pkg/codegen/codegen.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (c *Codegen) Run() error {
110110
}
111111
models.Items = append(models.Items, parsedModel)
112112

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

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

132132
helpersPath := rootPath + "pkg/helpers"
133133
configPath := rootPath + "configs"
134+
operatorsPath := rootPath + "pkg/operators/base"
134135

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

138140
return nil
139141
}

0 commit comments

Comments
 (0)