Skip to content

Commit

Permalink
Drop global Cloudsvc in reconcilers
Browse files Browse the repository at this point in the history
  • Loading branch information
bigkraig committed Oct 25, 2018
1 parent 94ade46 commit a269146
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func main() {
}
mc.Start()

aws.Initialize(options.AWSAPIMaxRetries, options.AWSAPIDebug, options.config.ClusterName, mc, cc)
controller.Initialize(&options.config, mgr, mc)
cloud := aws.New(options.AWSAPIMaxRetries, options.AWSAPIDebug, options.config.ClusterName, mc, cc)
controller.Initialize(&options.config, mgr, mc, cloud)

mux := http.NewServeMux()
if options.ProfilingEnabled {
Expand Down
15 changes: 12 additions & 3 deletions internal/aws/cloud.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package aws

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/acm"
"github.com/aws/aws-sdk-go/service/acm/acmiface"
"github.com/aws/aws-sdk-go/service/ec2"
Expand All @@ -15,6 +15,8 @@ import (
"github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi/resourcegroupstaggingapiiface"
"github.com/aws/aws-sdk-go/service/wafregional"
"github.com/aws/aws-sdk-go/service/wafregional/wafregionaliface"
"github.com/kubernetes-sigs/aws-alb-ingress-controller/internal/ingress/metric"
"github.com/ticketmaster/aws-sdk-go-cache/cache"
)

type CloudAPI interface {
Expand Down Expand Up @@ -42,7 +44,12 @@ type Cloud struct {
// TODO: Deprecate global variable
var Cloudsvc CloudAPI

func NewCloudsvc(awsSession *session.Session) {
// Initialize the global AWS clients.
// TODO, pass these aws clients instances to controller instead of global clients.
// But due to huge number of aws clients, it's best to have one container AWS client that embed these aws clients.
func New(AWSAPIMaxRetries int, AWSAPIDebug bool, clusterName string, mc metric.Collector, cc *cache.Config) CloudAPI {
awsSession := NewSession(&aws.Config{MaxRetries: aws.Int(AWSAPIMaxRetries)}, AWSAPIDebug, mc, cc)

Cloudsvc = &Cloud{
acm.New(awsSession),
ec2.New(awsSession),
Expand All @@ -51,6 +58,8 @@ func NewCloudsvc(awsSession *session.Session) {
iam.New(awsSession),
resourcegroupstaggingapi.New(awsSession),
wafregional.New(awsSession),
"TODO GET RID OF THIS",
clusterName,
}

return Cloudsvc
}
4 changes: 2 additions & 2 deletions internal/aws/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (c *Cloud) RevokeSecurityGroupIngress(i *ec2.RevokeSecurityGroupIngressInpu
}

func (c *Cloud) GetSubnets(names []*string) (subnets []*string, err error) {
vpcID, err := Cloudsvc.GetVPCID()
vpcID, err := c.GetVPCID()
if err != nil {
return
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func (c *Cloud) GetSubnets(names []*string) (subnets []*string, err error) {
}

func (c *Cloud) GetSecurityGroups(names []*string) (sgs []*string, err error) {
vpcID, err := Cloudsvc.GetVPCID()
vpcID, err := c.GetVPCID()
if err != nil {
return
}
Expand Down
11 changes: 0 additions & 11 deletions internal/aws/client.go → internal/aws/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,10 @@ package aws
import (
"net/http"

"github.com/aws/aws-sdk-go/aws"
"github.com/golang/glog"
"github.com/kubernetes-sigs/aws-alb-ingress-controller/internal/ingress/metric"
"github.com/ticketmaster/aws-sdk-go-cache/cache"
"k8s.io/apiserver/pkg/server/healthz"
)

// Initialize the global AWS clients.
// TODO, pass these aws clients instances to controller instead of global clients.
// But due to huge number of aws clients, it's best to have one container AWS client that embed these aws clients.
func Initialize(AWSAPIMaxRetries int, AWSAPIDebug bool, clusterName string, mc metric.Collector, cc *cache.Config) {
sess := NewSession(&aws.Config{MaxRetries: aws.Int(AWSAPIMaxRetries)}, AWSAPIDebug, mc, cc)
NewCloudsvc(sess)
}

type AWSHealthChecker struct{}

var _ healthz.HealthzChecker = (*AWSHealthChecker)(nil)
Expand Down
22 changes: 11 additions & 11 deletions internal/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"
)

func Initialize(config *config.Configuration, mgr manager.Manager, mc metric.Collector) error {
reconciler, err := newReconciler(config, mgr, mc)
func Initialize(config *config.Configuration, mgr manager.Manager, mc metric.Collector, cloud aws.CloudAPI) error {
reconciler, err := newReconciler(config, mgr, mc, cloud)
if err != nil {
return err
}
c, err := controller.New("alb-ingress-controller", mgr, controller.Options{Reconciler: reconciler})
if err != nil {
return err
}
if err := config.BindDynamicSettings(mgr, c, aws.Cloudsvc); err != nil {
if err := config.BindDynamicSettings(mgr, c, cloud); err != nil {
return err
}

Expand All @@ -45,19 +45,19 @@ func Initialize(config *config.Configuration, mgr manager.Manager, mc metric.Col
return nil
}

func newReconciler(config *config.Configuration, mgr manager.Manager, mc metric.Collector) (reconcile.Reconciler, error) {
func newReconciler(config *config.Configuration, mgr manager.Manager, mc metric.Collector, cloud aws.CloudAPI) (reconcile.Reconciler, error) {
store, err := store.New(mgr, config)
if err != nil {
return nil, err
}
nameTagGenerator := generator.NewNameTagGenerator(*config)
tagsController := tags.NewController(aws.Cloudsvc)
endpointResolver := backend.NewEndpointResolver(store, aws.Cloudsvc)
tgGroupController := tg.NewGroupController(aws.Cloudsvc, store, nameTagGenerator, tagsController, endpointResolver)
rsController := rs.NewController(aws.Cloudsvc)
lsGroupController := ls.NewGroupController(store, aws.Cloudsvc, rsController)
sgAssociationController := sg.NewAssociationController(store, aws.Cloudsvc)
lbController := lb.NewController(aws.Cloudsvc, store,
tagsController := tags.NewController(cloud)
endpointResolver := backend.NewEndpointResolver(store, cloud)
tgGroupController := tg.NewGroupController(cloud, store, nameTagGenerator, tagsController, endpointResolver)
rsController := rs.NewController(cloud)
lsGroupController := ls.NewGroupController(store, cloud, rsController)
sgAssociationController := sg.NewAssociationController(store, cloud)
lbController := lb.NewController(cloud, store,
nameTagGenerator, tgGroupController, lsGroupController, sgAssociationController)

return &Reconciler{
Expand Down

0 comments on commit a269146

Please sign in to comment.