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

Commit 049f785

Browse files
Adding code generation library changes
Signed-off-by: Christopher Hein <[email protected]>
1 parent d1d2eef commit 049f785

File tree

3 files changed

+39
-23
lines changed

3 files changed

+39
-23
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,37 @@ package base
33
import (
44
"context"
55
"github.com/awslabs/aws-service-operator/pkg/config"
6+
"github.com/awslabs/aws-service-operator/pkg/queuemanager"
67
{{- range $index, $element := .Items}}
78
"github.com/awslabs/aws-service-operator/pkg/operators/{{$element.Spec.Resource.Name}}"
89
{{- end}}
910
)
1011

1112
type base struct {
1213
config *config.Config
14+
queueManager *queuemanager.QueueManager
15+
{{- range $index, $element := .Items}}
16+
{{$element.Spec.Resource.Name}} *{{$element.Spec.Resource.Name}}.Operator
17+
{{- end}}
1318
}
1419

1520
func New(
1621
config *config.Config,
22+
queueManager *queuemanager.QueueManager,
1723
) *base {
1824
return &base{
1925
config: config,
26+
queueManager: queueManager,
27+
{{- range $index, $element := .Items}}
28+
{{$element.Spec.Resource.Name}}: {{$element.Spec.Resource.Name}}.NewOperator(config, queueManager),
29+
{{- end}}
2030
}
2131
}
2232

2333
func (b *base) Watch(ctx context.Context, namespace string) {
2434
{{- range $index, $element := .Items}}
2535
if b.config.Resources["{{$element.Spec.Resource.Name}}"] {
26-
{{$element.Spec.Resource.Name}}operator := {{$element.Spec.Resource.Name}}.NewOperator(b.config)
27-
go {{$element.Spec.Resource.Name}}operator.StartWatch(ctx, namespace)
36+
go b.{{$element.Spec.Resource.Name}}.StartWatch(ctx, namespace)
2837
}
2938
{{- end}}
3039

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import (
1414
{{- end}}
1515

1616
"github.com/awslabs/aws-service-operator/pkg/config"
17-
{{- if .Spec.Queue}}
18-
"github.com/awslabs/aws-service-operator/pkg/queue"
19-
corev1 "k8s.io/api/core/v1"
20-
"github.com/iancoleman/strcase"
21-
"strings"
22-
awsclient "github.com/awslabs/aws-service-operator/pkg/client/clientset/versioned/typed/service-operator.aws/v1alpha1"
17+
"github.com/awslabs/aws-service-operator/pkg/queuemanager"
18+
{{- if .Spec.Queue}}
19+
corev1 "k8s.io/api/core/v1"
20+
"github.com/iancoleman/strcase"
21+
"strings"
22+
awsclient "github.com/awslabs/aws-service-operator/pkg/client/clientset/versioned/typed/service-operator.aws/v1alpha1"
23+
"github.com/awslabs/aws-service-operator/pkg/queue"
2324
{{- end}}
2425
"github.com/awslabs/aws-service-operator/pkg/operator"
2526
"k8s.io/client-go/tools/cache"
@@ -34,12 +35,23 @@ import (
3435
type Operator struct {
3536
config *config.Config
3637
topicARN string
38+
queueManager *queuemanager.QueueManager
3739
}
3840

3941
// NewOperator create controller for watching object store custom resources created
40-
func NewOperator(config *config.Config) *Operator {
42+
func NewOperator(config *config.Config, queueManager *queuemanager.QueueManager) *Operator {
43+
{{- if .Spec.Queue}}
44+
queuectrl := queue.New(config, config.AWSClientset, 10)
45+
topicARN, _ := queuectrl.Register("{{.Spec.Resource.Name}}")
46+
queueManager.Add(topicARN, queuemanager.HandlerFunc(QueueUpdater))
47+
{{- end}}
48+
4149
return &Operator{
4250
config: config,
51+
{{- if .Spec.Queue}}
52+
topicARN: topicARN,
53+
{{- end}}
54+
queueManager: queueManager,
4355
}
4456
}
4557

@@ -50,19 +62,14 @@ func (c *Operator) StartWatch(ctx context.Context, namespace string) {
5062
UpdateFunc: c.onUpdate,
5163
DeleteFunc: c.onDelete,
5264
}
53-
{{- if .Spec.Queue}}
54-
queuectrl := queue.New(c.config, c.config.AWSClientset, 1)
55-
c.topicARN, _, _, _ = queuectrl.Register("{{.Spec.Resource.Name}}", &awsV1alpha1.{{.Spec.Kind}}{})
56-
go queuectrl.StartWatch(queue.HandlerFunc(QueueUpdater), ctx.Done())
57-
{{- end}}
5865

5966
oper := operator.New("{{.Spec.Resource.Plural}}", namespace, resourceHandlers, c.config.AWSClientset.RESTClient())
6067
oper.Watch(&awsV1alpha1.{{.Spec.Kind}}{}, ctx.Done())
6168
}
6269

6370
{{- if .Spec.Queue}}
6471
// QueueUpdater will take the messages from the queue and process them
65-
func QueueUpdater(config *config.Config, msg *queue.MessageBody) error {
72+
func QueueUpdater(config *config.Config, msg *queuemanager.MessageBody) error {
6673
logger := config.Logger
6774
var name, namespace string
6875
if msg.Updatable {

0 commit comments

Comments
 (0)