Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1695 from 2opremio/sync-tag-warning
Browse files Browse the repository at this point in the history
Warn users about external changes in sync tag
  • Loading branch information
Alfonso Acosta authored Feb 1, 2019
2 parents 0940b06 + 52235cc commit cb43b07
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
18 changes: 16 additions & 2 deletions daemon/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ func (d *Daemon) Loop(stop chan struct{}, wg *sync.WaitGroup, logger log.Logger)
// Ask for a sync, and to poll images, straight away
d.AskForSync()
d.AskForImagePoll()

for {
var (
lastKnownSyncTagRev string
warnedAboutSyncTagChange bool
)
select {
case <-stop:
logger.Log("stopping", "true")
Expand All @@ -83,7 +88,7 @@ func (d *Daemon) Loop(stop chan struct{}, wg *sync.WaitGroup, logger log.Logger)
default:
}
}
if err := d.doSync(logger); err != nil {
if err := d.doSync(logger, &lastKnownSyncTagRev, &warnedAboutSyncTagChange); err != nil {
logger.Log("err", err)
}
syncTimer.Reset(d.SyncInterval)
Expand Down Expand Up @@ -149,7 +154,7 @@ func (d *LoopVars) AskForImagePoll() {

// -- extra bits the loop needs

func (d *Daemon) doSync(logger log.Logger) (retErr error) {
func (d *Daemon) doSync(logger log.Logger, lastKnownSyncTagRev *string, warnedAboutSyncTagChange *bool) (retErr error) {
started := time.Now().UTC()
defer func() {
syncDuration.With(
Expand Down Expand Up @@ -179,6 +184,14 @@ func (d *Daemon) doSync(logger log.Logger) (retErr error) {
if err != nil && !isUnknownRevision(err) {
return err
}
// Check if something other than the current instance of fluxd changed the sync tag.
// This is likely to be caused by another fluxd instance using the same tag.
// Having multiple instances fighting for the same tag can lead to fluxd missing manifest changes.
if *lastKnownSyncTagRev != "" && oldTagRev != *lastKnownSyncTagRev && !*warnedAboutSyncTagChange {
logger.Log("warning",
"detected external change in git sync tag; the sync tag should not be shared by fluxd instances")
*warnedAboutSyncTagChange = true
}

newTagRev, err := working.HeadRevision(ctx)
if err != nil {
Expand Down Expand Up @@ -419,6 +432,7 @@ func (d *Daemon) doSync(logger log.Logger) (retErr error) {
if err != nil {
return err
}
*lastKnownSyncTagRev = newTagRev
}
logger.Log("tag", d.GitConfig.SyncTag, "old", oldTagRev, "new", newTagRev)
{
Expand Down
24 changes: 18 additions & 6 deletions daemon/loop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ func TestPullAndSync_InitialSync(t *testing.T) {
syncDef = &def
return nil
}

d.doSync(log.NewLogfmtLogger(ioutil.Discard))
var (
logger = log.NewLogfmtLogger(ioutil.Discard)
lastKnownSyncTagRev string
warnedAboutSyncTagChange bool
)
d.doSync(logger, &lastKnownSyncTagRev, &warnedAboutSyncTagChange)

// It applies everything
if syncCalled != 1 {
Expand Down Expand Up @@ -174,8 +178,12 @@ func TestDoSync_NoNewCommits(t *testing.T) {
syncDef = &def
return nil
}

if err := d.doSync(log.NewLogfmtLogger(ioutil.Discard)); err != nil {
var (
logger = log.NewLogfmtLogger(ioutil.Discard)
lastKnownSyncTagRev string
warnedAboutSyncTagChange bool
)
if err := d.doSync(logger, &lastKnownSyncTagRev, &warnedAboutSyncTagChange); err != nil {
t.Error(err)
}

Expand Down Expand Up @@ -268,8 +276,12 @@ func TestDoSync_WithNewCommit(t *testing.T) {
syncDef = &def
return nil
}

d.doSync(log.NewLogfmtLogger(ioutil.Discard))
var (
logger = log.NewLogfmtLogger(ioutil.Discard)
lastKnownSyncTagRev string
warnedAboutSyncTagChange bool
)
d.doSync(logger, &lastKnownSyncTagRev, &warnedAboutSyncTagChange)

// It applies everything
if syncCalled != 1 {
Expand Down

0 comments on commit cb43b07

Please sign in to comment.