Skip to content

Commit

Permalink
Merge pull request #634 from mkubaczyk/skip-ignored-apps
Browse files Browse the repository at this point in the history
Add skipIgnoredApps option to DSF Settings block
  • Loading branch information
luisdavim authored Dec 3, 2021
2 parents 510b3b9 + c707583 commit 9142d9f
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/desired_state_specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ The following options can be skipped if your kubectl context is already created
- **eyamlPublicKeyPath** : if set with path to the eyaml public key file, it will use it instead of looking for default one in ./keys directory relative to where Helmsman were run. It needs to be defined in conjunction with eyamlPrivateKeyPath.
- **globalHooks** : defines global lifecycle hooks to apply yaml manifest before and/or after different helmsman operations. Check [here](how_to/apps/lifecycle_hooks.md) for more details.
- **globalMaxHistory** : defines the **global** maximum number of helm revisions state (secrets/configmap) to keep. Releases can override this global value by setting `maxHistory`. If both are not set or are set to `0`, it is defaulted to 10.
- **skipIgnoredApps** : if set to true apps, that would normally be listed in the plan as `ignored`, will be skipped. They won't show up on the plan output and won't be considered in decisions. This is especially useful when using `-target` or `-group` flags with significant amount of apps where most of them show up as `ignored` in the plan output making it hard to read.

Example:

Expand Down
8 changes: 5 additions & 3 deletions internal/app/decision_maker.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (cs *currentState) makePlan(s *state) *plan {
<-sem
}()
r.checkChartDepUpdate()
cs.decide(r, s.Namespaces[r.Namespace], p, c)
cs.decide(r, s.Namespaces[r.Namespace], p, c, s.Settings)
}(r, s.ChartInfo[r.Chart][r.Version])
}
wg.Wait()
Expand All @@ -87,10 +87,12 @@ func (cs *currentState) makePlan(s *state) *plan {

// decide makes a decision about what commands (actions) need to be executed
// to make a release section of the desired state come true.
func (cs *currentState) decide(r *release, n *namespace, p *plan, c *chartInfo) {
func (cs *currentState) decide(r *release, n *namespace, p *plan, c *chartInfo, settings config) {
// check for presence in defined targets or groups
if !r.isConsideredToRun() {
p.addDecision("Release [ "+r.Name+" ] ignored", r.Priority, ignored)
if !settings.SkipIgnoredApps {
p.addDecision("Release [ "+r.Name+" ] ignored", r.Priority, ignored)
}
return
}

Expand Down
83 changes: 82 additions & 1 deletion internal/app/decision_maker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ func Test_decide(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
cs := newCurrentState()
tt.args.s.disableUntargetedApps([]string{}, tt.targetFlag)
settings := config{}
outcome := plan{}
// Act
cs.decide(tt.args.s.Apps[tt.args.r], tt.args.s.Namespaces[tt.args.s.Apps[tt.args.r].Namespace], &outcome, &chartInfo{})
cs.decide(tt.args.s.Apps[tt.args.r], tt.args.s.Namespaces[tt.args.s.Apps[tt.args.r].Namespace], &outcome, &chartInfo{}, settings)
got := outcome.Decisions[0].Type
t.Log(outcome.Decisions[0].Description)

Expand All @@ -240,6 +241,86 @@ func Test_decide(t *testing.T) {
}
}

func Test_decide_skip_ignored_apps(t *testing.T) {
type args struct {
rs []string
s *state
}
tests := []struct {
name string
targetFlag []string
args args
want int
}{
{
name: "decide() - skipIgnoredApps is defined and target flag contains 2 app names - plan should have 2 decisions",
targetFlag: []string{"service1", "service2"},
args: args{
rs: []string{"service1", "service2"},
s: &state{
Apps: map[string]*release{
"service1": {
Name: "service1",
Namespace: "namespace",
Enabled: true,
},
"service2": {
Name: "service2",
Namespace: "namespace",
Enabled: true,
},
},
},
},
want: 2,
},
{
name: "decide() - skipIgnoredApps is defined and target flag contains just 1 app name - plan should have 1 decision - one app should be ignored",
targetFlag: []string{"service1"},
args: args{
rs: []string{"service1", "service2"},
s: &state{
Apps: map[string]*release{
"service1": {
Name: "service1",
Namespace: "namespace",
Enabled: true,
},
"service2": {
Name: "service2",
Namespace: "namespace",
Enabled: true,
},
},
},
},
want: 1,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cs := newCurrentState()
tt.args.s.disableUntargetedApps([]string{}, tt.targetFlag)
settings := config{
SkipIgnoredApps: true,
}
outcome := plan{}
// Act
for _, r := range tt.args.rs {
cs.decide(tt.args.s.Apps[r], tt.args.s.Namespaces[tt.args.s.Apps[r].Namespace], &outcome, &chartInfo{}, settings)
}
got := outcome.Decisions
t.Log(outcome.Decisions)

// Assert
if len(got) != tt.want {
t.Errorf("decide() = %d, want %d", len(got), tt.want)
}
})
}
}

func Test_decide_group(t *testing.T) {
type args struct {
s *state
Expand Down
1 change: 1 addition & 0 deletions internal/app/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type config struct {
EyamlPublicKeyPath string `yaml:"eyamlPublicKeyPath"`
GlobalHooks map[string]interface{} `yaml:"globalHooks"`
GlobalMaxHistory int `yaml:"globalMaxHistory"`
SkipIgnoredApps bool `yaml:"skipIgnoredApps"`
}

// state type represents the desired state of applications on a k8s cluster.
Expand Down

0 comments on commit 9142d9f

Please sign in to comment.