Skip to content

Commit

Permalink
Fix loadbalancer deletes (#118)
Browse files Browse the repository at this point in the history
* Fix loadbalancer deletes

Signed-off-by: Tyler Auerbeck <[email protected]>

* Point everything to a supergraph endpoint

Signed-off-by: Tyler Auerbeck <[email protected]>

---------

Signed-off-by: Tyler Auerbeck <[email protected]>
Co-authored-by: Tyler Auerbeck <[email protected]>
  • Loading branch information
tylerauerbeck and tylerauerbeck authored Jul 5, 2023
1 parent 8f2554e commit f45b5ee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
13 changes: 4 additions & 9 deletions cmd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func process(ctx context.Context, logger *zap.SugaredLogger) error {
}

server := &srv.Server{
// APIClient: lbapi.NewClient(viper.GetString("api-endpoint")),
Echo: eSrv,
Chart: chart,
Context: cx,
Expand All @@ -128,15 +127,11 @@ func process(ctx context.Context, logger *zap.SugaredLogger) error {
// init lbapi client
if config.AppConfig.OIDC.ClientID != "" {
oauthHTTPClient := oauth2x.NewClient(ctx, oauth2x.NewClientCredentialsTokenSrc(ctx, config.AppConfig.OIDC))
server.APIClient = lbapi.NewClient(determineEndpoint(viper.GetString("api-endpoint"), viper.GetString("supergraph-endpoint")),
lbapi.WithHTTPClient(oauthHTTPClient),
)
server.IPAMClient = ipamclient.NewClient(determineEndpoint(viper.GetString("ipam-endpoint"), viper.GetString("supergraph-endpoint")),
ipamclient.WithHTTPClient(oauthHTTPClient),
)
server.APIClient = lbapi.NewClient(viper.GetString("supergraph-endpoint"), lbapi.WithHTTPClient(oauthHTTPClient))
server.IPAMClient = ipamclient.NewClient(viper.GetString("supergraph-endpoint"), ipamclient.WithHTTPClient(oauthHTTPClient))
} else {
server.APIClient = lbapi.NewClient(determineEndpoint(viper.GetString("api-endpoint"), viper.GetString("supergraph-endpoint")))
server.IPAMClient = ipamclient.NewClient(determineEndpoint(viper.GetString("ipam-endpoint"), viper.GetString("supergraph-endpoint")))
server.APIClient = lbapi.NewClient(viper.GetString("supergraph-endpoint"))
server.IPAMClient = ipamclient.NewClient(viper.GetString("supergraph-endpoint"))
}

if err := server.Run(cx); err != nil {
Expand Down
32 changes: 23 additions & 9 deletions internal/srv/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func (s *Server) locationCheck(i gidx.PrefixedID) bool {
}

func (s *Server) processEvent(messages <-chan *message.Message) {
var lb *loadBalancer

for msg := range messages {
s.Logger.Infof("received event message: %s, payload: %s\n", msg.UUID, string(msg.Payload))

Expand All @@ -30,21 +32,27 @@ func (s *Server) processEvent(messages <-chan *message.Message) {
}

if slices.ContainsFunc(m.AdditionalSubjectIDs, s.locationCheck) || len(s.Locations) == 0 {
lb, err := s.newLoadBalancer(m.SubjectID, m.AdditionalSubjectIDs)
if err != nil {
s.Logger.Errorw("unable to initialize loadbalancer", "error", err, "messageID", msg.UUID)
msg.Nack()
if m.EventType == string("ip-address.unassigned") {
lb = &loadBalancer{loadBalancerID: m.SubjectID, lbData: nil, lbType: typeLB}
} else {
lb, err = s.newLoadBalancer(m.SubjectID, m.AdditionalSubjectIDs)
if err != nil {
s.Logger.Errorw("unable to initialize loadbalancer", "error", err, "messageID", msg.UUID)
msg.Nack()
}
}

if lb.lbType != typeNoLB {
switch {
case m.EventType == "ip-address.assigned" || m.EventType == "ip-address.unassigned":
case m.EventType == "ip-address.assigned":
s.Logger.Debugw("ip address processed. updating loadbalancer", "loadbalancer", lb.loadBalancerID.String())

if err := s.updateDeployment(lb); err != nil {
s.Logger.Errorw("unable to update loadbalancer", "error", err, "messageID", msg.UUID, "loadbalancer", lb.loadBalancerID.String())
msg.Nack()
}
case m.EventType == "ip-address.unassigned":
s.Logger.Debugw("ip address unassigned. updating loadbalancer", "loadbalancer", lb.loadBalancerID.String())
default:
s.Logger.Debugw("unknown event", "loadbalancer", lb.loadBalancerID.String(), "event", m.EventType)
}
Expand All @@ -57,6 +65,8 @@ func (s *Server) processEvent(messages <-chan *message.Message) {
}

func (s *Server) processChange(messages <-chan *message.Message) {
var lb *loadBalancer

for msg := range messages {
m, err := events.UnmarshalChangeMessage(msg.Payload)
if err != nil {
Expand All @@ -65,10 +75,14 @@ func (s *Server) processChange(messages <-chan *message.Message) {
}

if slices.ContainsFunc(m.AdditionalSubjectIDs, s.locationCheck) || len(s.Locations) == 0 {
lb, err := s.newLoadBalancer(m.SubjectID, m.AdditionalSubjectIDs)
if err != nil {
s.Logger.Errorw("unable to initialize loadbalancer", "error", err, "messageID", msg.UUID)
msg.Nack()
if m.EventType == string(events.DeleteChangeType) {
lb = &loadBalancer{loadBalancerID: m.SubjectID, lbData: nil, lbType: typeLB}
} else {
lb, err = s.newLoadBalancer(m.SubjectID, m.AdditionalSubjectIDs)
if err != nil {
s.Logger.Errorw("unable to initialize loadbalancer", "error", err, "messageID", msg.UUID)
msg.Nack()
}
}

if lb.lbType != typeNoLB {
Expand Down

0 comments on commit f45b5ee

Please sign in to comment.