Skip to content

Commit 5e53503

Browse files
author
Joseph Sawaya
committed
Add back bad commit list
The bad commit list is scoped down to the target itself. This commit also adds a config option to the config in order give users the choice to enable to badCommitList. Signed-off-by: Joseph Sawaya <[email protected]>
1 parent c8259a0 commit 5e53503

File tree

3 files changed

+41
-30
lines changed

3 files changed

+41
-30
lines changed

pkg/engine/common.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func zeroToCurrent(ctx, conn context.Context, m Method, target *Target, tag *[]s
6767
type empty struct {
6868
}
6969

70-
var BadCommitMethods map[string]map[plumbing.Hash]empty = make(map[string]map[plumbing.Hash]empty)
70+
var BadCommitList map[string]map[string]map[plumbing.Hash]empty = make(map[string]map[string]map[plumbing.Hash]empty)
7171

7272
func currentToLatest(ctx, conn context.Context, m Method, target *Target, tag *[]string) error {
7373
if target.disconnected && len(target.url) > 0 {
@@ -85,13 +85,19 @@ func currentToLatest(ctx, conn context.Context, m Method, target *Target, tag *[
8585
return fmt.Errorf("Failed to get current commit: %v", err)
8686
}
8787

88-
if _, ok := BadCommitMethods[m.GetKind()]; !ok {
89-
BadCommitMethods[m.GetKind()] = make(map[plumbing.Hash]empty)
90-
}
88+
if target.trackBadCommits {
89+
if _, ok := BadCommitList[target.name]; !ok {
90+
BadCommitList[target.name] = make(map[string]map[plumbing.Hash]empty)
91+
}
9192

92-
if _, ok := BadCommitMethods[m.GetKind()][latest]; ok {
93-
klog.Infof("No changes applied to target %s this run, %s currently at %s", target.name, m.GetKind(), current)
94-
return nil
93+
if _, ok := BadCommitList[target.name][m.GetKind()]; !ok {
94+
BadCommitList[target.name][m.GetKind()] = make(map[plumbing.Hash]empty)
95+
}
96+
97+
if _, ok := BadCommitList[target.name][m.GetKind()][latest]; ok {
98+
klog.Infof("No changes applied to target %s this run, %s currently at %s", target.name, m.GetKind(), current)
99+
return nil
100+
}
95101
}
96102

97103
if latest != current {
@@ -108,7 +114,9 @@ func currentToLatest(ctx, conn context.Context, m Method, target *Target, tag *[
108114
// Roll back failed
109115
return fmt.Errorf("Roll back failed, state between %s and %s: %v", current, latest, err)
110116
}
111-
BadCommitMethods[m.GetKind()][latest] = empty{}
117+
if target.trackBadCommits {
118+
BadCommitList[target.name][m.GetKind()][latest] = empty{}
119+
}
112120
return fmt.Errorf("Rolled back to %v: %v", current, err)
113121
}
114122

pkg/engine/fetchit.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,12 @@ func getMethodTargetScheds(targetConfigs []*TargetConfig, fetchit *Fetchit) *Fet
245245
tc.mu.Lock()
246246
defer tc.mu.Unlock()
247247
internalTarget := &Target{
248-
name: tc.Name,
249-
url: tc.Url,
250-
device: tc.Device,
251-
branch: tc.Branch,
252-
disconnected: tc.Disconnected,
248+
name: tc.Name,
249+
url: tc.Url,
250+
device: tc.Device,
251+
branch: tc.Branch,
252+
disconnected: tc.Disconnected,
253+
trackBadCommits: tc.trackBadCommits,
253254
}
254255

255256
if tc.configReload != nil {

pkg/engine/types.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@ type FetchitConfig struct {
3131
}
3232

3333
type TargetConfig struct {
34-
Name string `mapstructure:"name"`
35-
Url string `mapstructure:"url"`
36-
Device string `mapstructure:"device"`
37-
Disconnected bool `mapstructure:"disconnected"`
38-
Branch string `mapstructure:"branch"`
39-
Ansible []*Ansible `mapstructure:"ansible"`
40-
FileTransfer []*FileTransfer `mapstructure:"filetransfer"`
41-
Kube []*Kube `mapstructure:"kube"`
42-
Raw []*Raw `mapstructure:"raw"`
43-
Systemd []*Systemd `mapstructure:"systemd"`
34+
Name string `mapstructure:"name"`
35+
Url string `mapstructure:"url"`
36+
Device string `mapstructure:"device"`
37+
Disconnected bool `mapstructure:"disconnected"`
38+
trackBadCommits bool `mapstructure:"trackBadCommits"`
39+
Branch string `mapstructure:"branch"`
40+
Ansible []*Ansible `mapstructure:"ansible"`
41+
FileTransfer []*FileTransfer `mapstructure:"filetransfer"`
42+
Kube []*Kube `mapstructure:"kube"`
43+
Raw []*Raw `mapstructure:"raw"`
44+
Systemd []*Systemd `mapstructure:"systemd"`
4445

4546
image *Image
4647
prune *Prune
@@ -49,13 +50,14 @@ type TargetConfig struct {
4950
}
5051

5152
type Target struct {
52-
name string
53-
url string
54-
device string
55-
localPath string
56-
branch string
57-
mu sync.Mutex
58-
disconnected bool
53+
name string
54+
url string
55+
device string
56+
localPath string
57+
branch string
58+
mu sync.Mutex
59+
disconnected bool
60+
trackBadCommits bool
5961
}
6062

6163
type SchedInfo struct {

0 commit comments

Comments
 (0)