Skip to content

Commit

Permalink
BUG/MINOR: Fix configuration of backend model
Browse files Browse the repository at this point in the history
Setting the backend mode should be done before processing annotations
because some of them depend on the backend mode.
  • Loading branch information
Mo3m3n committed Nov 5, 2021
1 parent 0c5c611 commit 04bbbc0
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions controller/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (

var logger = utils.GetLogger()

const cookieKey = "ohph7OoGhong"

type Service struct {
path *store.IngressPath
resource *store.Service
Expand Down Expand Up @@ -139,25 +141,16 @@ func (s *Service) HandleBackend(client api.HAProxyClient, store store.K8s) (relo
}

// getBackendModel checks for a corresponding custom resource before falling back to annoations
func (s *Service) getBackendModel(store store.K8s) (*models.Backend, error) {
var backend *models.Backend
var err error
var cookieKey = "ohph7OoGhong"
crInuse := true
func (s *Service) getBackendModel(store store.K8s) (backend *models.Backend, err error) {
var crInUse = true
// get/create backend Model
backend, err = annotations.ModelBackend("cr-backend", s.resource.Namespace, store, s.annotations...)
logger.Warning(err)
if backend == nil {
backend = &models.Backend{DefaultServer: &models.DefaultServer{}}
crInuse = false
}
if !crInuse {
for _, a := range annotations.Backend(backend, store, s.certs) {
err = a.Process(store, s.annotations...)
if err != nil {
logger.Errorf("service '%s/%s': annotation '%s': %s", s.resource.Namespace, s.resource.Name, a.GetName(), err)
}
}
crInUse = false
}
// configure backend model
if s.modeTCP {
backend.Mode = "tcp"
} else {
Expand All @@ -169,6 +162,14 @@ func (s *Service) getBackendModel(store store.K8s) (*models.Backend, error) {
if s.resource.DNS != "" {
backend.DefaultServer = &models.DefaultServer{InitAddr: "last,libc,none"}
}
if !crInUse {
for _, a := range annotations.Backend(backend, store, s.certs) {
err = a.Process(store, s.annotations...)
if err != nil {
logger.Errorf("service '%s/%s': annotation '%s': %s", s.resource.Namespace, s.resource.Name, a.GetName(), err)
}
}
}
if backend.Cookie != nil && backend.Cookie.Dynamic && backend.DynamicCookieKey == "" {
backend.DynamicCookieKey = cookieKey
}
Expand Down

0 comments on commit 04bbbc0

Please sign in to comment.