fix #1615 : cleanup based on heartbeat instead (#1617)

This commit is contained in:
Thibault "bui" Koechlin 2022-06-29 13:21:58 +02:00 committed by GitHub
parent 8e7e799304
commit 15902dcba6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -932,7 +932,7 @@ func (c *Client) FlushAgentsAndBouncers(agentsCfg *csconfig.AuthGCCfg, bouncersC
if bouncersCfg.ApiDuration != nil { if bouncersCfg.ApiDuration != nil {
log.Debug("trying to delete old bouncers from api") log.Debug("trying to delete old bouncers from api")
deletionCount, err := c.Ent.Bouncer.Delete().Where( deletionCount, err := c.Ent.Bouncer.Delete().Where(
bouncer.LastPullLTE(time.Now().UTC().Add(*bouncersCfg.ApiDuration)), bouncer.LastPullLTE(time.Now().UTC().Add(-*bouncersCfg.ApiDuration)),
).Where( ).Where(
bouncer.AuthTypeEQ(types.ApiKeyAuthType), bouncer.AuthTypeEQ(types.ApiKeyAuthType),
).Exec(c.CTX) ).Exec(c.CTX)
@ -946,7 +946,7 @@ func (c *Client) FlushAgentsAndBouncers(agentsCfg *csconfig.AuthGCCfg, bouncersC
log.Debug("trying to delete old bouncers from cert") log.Debug("trying to delete old bouncers from cert")
deletionCount, err := c.Ent.Bouncer.Delete().Where( deletionCount, err := c.Ent.Bouncer.Delete().Where(
bouncer.LastPullLTE(time.Now().UTC().Add(*bouncersCfg.CertDuration)), bouncer.LastPullLTE(time.Now().UTC().Add(-*bouncersCfg.CertDuration)),
).Where( ).Where(
bouncer.AuthTypeEQ(types.TlsAuthType), bouncer.AuthTypeEQ(types.TlsAuthType),
).Exec(c.CTX) ).Exec(c.CTX)
@ -963,7 +963,7 @@ func (c *Client) FlushAgentsAndBouncers(agentsCfg *csconfig.AuthGCCfg, bouncersC
log.Debug("trying to delete old agents from cert") log.Debug("trying to delete old agents from cert")
deletionCount, err := c.Ent.Machine.Delete().Where( deletionCount, err := c.Ent.Machine.Delete().Where(
machine.LastPushLTE(time.Now().UTC().Add(*agentsCfg.CertDuration)), machine.LastHeartbeatLTE(time.Now().UTC().Add(-*agentsCfg.CertDuration)),
).Where( ).Where(
machine.Not(machine.HasAlerts()), machine.Not(machine.HasAlerts()),
).Where( ).Where(
@ -980,7 +980,7 @@ func (c *Client) FlushAgentsAndBouncers(agentsCfg *csconfig.AuthGCCfg, bouncersC
log.Debug("trying to delete old agents from password") log.Debug("trying to delete old agents from password")
deletionCount, err := c.Ent.Machine.Delete().Where( deletionCount, err := c.Ent.Machine.Delete().Where(
machine.LastPushLTE(time.Now().UTC().Add(*agentsCfg.LoginPasswordDuration)), machine.LastHeartbeatLTE(time.Now().UTC().Add(-*agentsCfg.LoginPasswordDuration)),
).Where( ).Where(
machine.Not(machine.HasAlerts()), machine.Not(machine.HasAlerts()),
).Where( ).Where(