-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added auto-renewal of nebula certificates and GC on badgerDB (#22)
* Added auto-renewal of nebula certificates and GC on badgerDB
- Loading branch information
Showing
6 changed files
with
160 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,9 @@ | |
# authUrl: "" | ||
# tokenUrl: "" | ||
# userInfoUrl: "" | ||
|
||
#tasks: | ||
# certRenew: | ||
# interval: 1h | ||
# dbGC: | ||
# interval: 5m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package server | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/slackhq/nebula" | ||
"github.com/slyngdk/nebula-provisioner/server/store" | ||
) | ||
|
||
type tasks struct { | ||
config *nebula.Config | ||
store *store.Store | ||
|
||
l *logrus.Logger | ||
quit chan interface{} | ||
} | ||
|
||
func NewTasks(l *logrus.Logger, config *nebula.Config, store *store.Store) *tasks { | ||
return &tasks{l: l, config: config, store: store, quit: make(chan interface{})} | ||
} | ||
|
||
func (t *tasks) Start() { | ||
t.l.Infoln("Starting task scheduler") | ||
|
||
renewCertTicker := time.NewTicker(t.config.GetDuration("tasks.certRenew.interval", 1*time.Hour)) | ||
dbGCTicker := time.NewTicker(t.config.GetDuration("tasks.dbGC.interval", 5*time.Minute)) | ||
|
||
go func() { | ||
for { | ||
select { | ||
case <-renewCertTicker.C: | ||
t.renewCerts() | ||
case <-dbGCTicker.C: | ||
t.dbGC() | ||
case <-t.quit: | ||
renewCertTicker.Stop() | ||
return | ||
} | ||
} | ||
}() | ||
} | ||
|
||
func (t *tasks) Stop() { | ||
t.l.Infoln("Stopping task scheduler") | ||
t.quit <- struct{}{} | ||
} | ||
|
||
func (t *tasks) renewCerts() { | ||
t.l.Infoln("Task: renew agent certificates") | ||
err := t.store.RenewCertForAgents() | ||
if err != nil { | ||
t.l.WithError(err).Errorln("error when renewing certificates for agents") | ||
} | ||
} | ||
|
||
func (t *tasks) dbGC() { | ||
t.l.Debugln("Task: db garbage collection") | ||
t.store.GC() | ||
} |