fix(controller,app): include auth configuration in changes detection

This commit is contained in:
wpetit 2023-03-29 15:32:23 +02:00
parent a48c2ebe14
commit 854a6ae41b
1 changed files with 22 additions and 9 deletions

View File

@ -16,8 +16,8 @@ import (
) )
type serverEntry struct { type serverEntry struct {
SpecHash uint64 AppDefHash uint64
Server *Server Server *Server
} }
type Controller struct { type Controller struct {
@ -124,7 +124,20 @@ func (c *Controller) updateAppRepository(ctx context.Context, specs *spec.Spec)
func (c *Controller) updateApp(ctx context.Context, specs *spec.Spec, appKey string) (err error) { func (c *Controller) updateApp(ctx context.Context, specs *spec.Spec, appKey string) (err error) {
appEntry := specs.Apps[appKey] appEntry := specs.Apps[appKey]
newAppSpecHash, err := hashstructure.Hash(appEntry, hashstructure.FormatV2, nil) var auth *spec.Auth
if specs.Config != nil {
auth = specs.Config.Auth
}
appDef := struct {
App spec.AppEntry
Auth *spec.Auth
}{
App: appEntry,
Auth: auth,
}
newAppDefHash, err := hashstructure.Hash(appDef, hashstructure.FormatV2, nil)
if err != nil { if err != nil {
return errors.WithStack(err) return errors.WithStack(err)
} }
@ -163,20 +176,20 @@ func (c *Controller) updateApp(ctx context.Context, specs *spec.Spec, appKey str
} }
server = &serverEntry{ server = &serverEntry{
Server: NewServer(bundle, auth, options...), Server: NewServer(bundle, auth, options...),
SpecHash: 0, AppDefHash: 0,
} }
c.servers[appKey] = server c.servers[appKey] = server
} }
specChanged := newAppSpecHash != server.SpecHash defChanged := newAppDefHash != server.AppDefHash
if server.Server.Running() && !specChanged { if server.Server.Running() && !defChanged {
return nil return nil
} }
if specChanged && server.SpecHash != 0 { if defChanged && server.AppDefHash != 0 {
logger.Info( logger.Info(
ctx, "restarting app", ctx, "restarting app",
logger.F("address", appEntry.Address), logger.F("address", appEntry.Address),
@ -194,7 +207,7 @@ func (c *Controller) updateApp(ctx context.Context, specs *spec.Spec, appKey str
return errors.Wrap(err, "could not start app") return errors.Wrap(err, "could not start app")
} }
server.SpecHash = newAppSpecHash server.AppDefHash = newAppDefHash
return nil return nil
} }