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

Commit b147505

Browse files
Adding source for loading operators
Signed-off-by: Christopher Hein <[email protected]>
1 parent 23dfa95 commit b147505

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

pkg/server/server.go

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ import (
1010
awsscheme "github.com/awslabs/aws-service-operator/pkg/client/clientset/versioned/scheme"
1111
awsclient "github.com/awslabs/aws-service-operator/pkg/client/clientset/versioned/typed/service-operator.aws/v1alpha1"
1212
"github.com/awslabs/aws-service-operator/pkg/config"
13-
"github.com/awslabs/aws-service-operator/pkg/operator/cloudformationtemplate"
14-
"github.com/awslabs/aws-service-operator/pkg/operator/dynamodb"
15-
"github.com/awslabs/aws-service-operator/pkg/operator/ecrrepository"
16-
"github.com/awslabs/aws-service-operator/pkg/operator/s3bucket"
17-
"github.com/awslabs/aws-service-operator/pkg/operator/snssubscription"
18-
"github.com/awslabs/aws-service-operator/pkg/operator/snstopic"
19-
"github.com/awslabs/aws-service-operator/pkg/operator/sqsqueue"
13+
opBase "github.com/awslabs/aws-service-operator/pkg/operators/base"
2014
opkit "github.com/christopherhein/operator-kit"
2115
corev1 "k8s.io/api/core/v1"
2216
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
@@ -41,7 +35,7 @@ func New(config *config.Config) *Server {
4135
func (c *Server) Run(stopChan chan struct{}) {
4236
config := c.Config
4337
logger := config.Logger
44-
logger.Info("Getting kubernetes context")
38+
logger.Info("getting kubernetes context")
4539
context, restConfig, kubeclientset, awsClientset, err := createContext(config.Kubeconfig)
4640
if err != nil {
4741
logger.Fatalf("failed to create context. %+v\n", err)
@@ -64,13 +58,13 @@ func (c *Server) Run(stopChan chan struct{}) {
6458
region = config.Region
6559
}
6660

67-
logger.Infof("Region: %+v", region)
61+
logger.Infof("region: %+v", region)
6862

6963
sess, err := session.NewSession(&aws.Config{
7064
Region: aws.String(region),
7165
})
7266
if err != nil {
73-
logger.Infof("Error creating AWS session '%s'\n", err)
67+
logger.Infof("error creating AWS session '%s'\n", err)
7468
}
7569
config.AWSSession = sess
7670

@@ -83,37 +77,22 @@ func (c *Server) Run(stopChan chan struct{}) {
8377

8478
// start watching the aws operator resources
8579
logger.Info("Watching the resources")
86-
cftcontroller := cloudformationtemplate.NewController(config, context, awsClientset)
87-
cftcontroller.StartWatch(corev1.NamespaceAll, stopChan)
88-
89-
s3controller := s3bucket.NewController(config, context, awsClientset)
90-
s3controller.StartWatch(corev1.NamespaceAll, stopChan)
91-
92-
ddbcontroller := dynamodb.NewController(config, context, awsClientset)
93-
ddbcontroller.StartWatch(corev1.NamespaceAll, stopChan)
94-
95-
sqscontroller := sqsqueue.NewController(config, context, awsClientset)
96-
sqscontroller.StartWatch(corev1.NamespaceAll, stopChan)
97-
98-
ecrcontroller := ecrrepository.NewController(config, context, awsClientset)
99-
ecrcontroller.StartWatch(corev1.NamespaceAll, stopChan)
100-
101-
snscontroller := snstopic.NewController(config, context, awsClientset)
102-
snscontroller.StartWatch(corev1.NamespaceAll, stopChan)
103-
104-
snssubcontroller := snssubscription.NewController(config, context, awsClientset)
105-
snssubcontroller.StartWatch(corev1.NamespaceAll, stopChan)
80+
operators := opBase.New(config, context, awsClientset)
81+
err = operators.Watch(corev1.NamespaceAll, stopChan)
82+
if err != nil {
83+
logger.Infof("error watching operators '%s'\n", err)
84+
}
10685
}
10786

108-
func getClientConfig(kubeconfig string) (*rest.Config, error) {
87+
func getConfig(kubeconfig string) (*rest.Config, error) {
10988
if kubeconfig != "" {
11089
return clientcmd.BuildConfigFromFlags("", kubeconfig)
11190
}
11291
return rest.InClusterConfig()
11392
}
11493

11594
func createContext(kubeconfig string) (*opkit.Context, *rest.Config, kubernetes.Interface, awsclient.ServiceoperatorV1alpha1Interface, error) {
116-
config, err := getClientConfig(kubeconfig)
95+
config, err := getConfig(kubeconfig)
11796
if err != nil {
11897
return nil, nil, nil, nil, fmt.Errorf("failed to get k8s config. %+v", err)
11998
}

0 commit comments

Comments
 (0)