Skip to content

Commit e88aa66

Browse files
authored
Merge pull request #781 from Praqma/multiple-spec-fix-priority
Remove 'priority' field from -spec docs
2 parents ba7e54c + 6365f10 commit e88aa66

File tree

3 files changed

+3
-68
lines changed

3 files changed

+3
-68
lines changed

docs/how_to/misc/multiple_desired_state_files_specification.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version: v3.8.1
55
# Specification file
66

77
Starting from v3.8.0, Helmsman allows you to use Specification file passed with `--spec <file>` flag
8-
in order to define multiple Desired State Files to be merged in particular order and with specific priorities.
8+
in order to define multiple Desired State Files to be merged together.
99

1010
An example Specification file `spec.yaml`:
1111

@@ -14,9 +14,7 @@ An example Specification file `spec.yaml`:
1414
stateFiles:
1515
- path: examples/example.yaml
1616
- path: examples/minimal-example.yaml
17-
priority: -10
1817
- path: examples/minimal-example.toml
19-
priority: -20
2018

2119
```
2220

@@ -26,18 +24,8 @@ This file can be then run with:
2624
helmsman --spec spec.yaml ...
2725
```
2826

29-
What it does is it takes the files from `stateFiles` list and orders them based on their priorities same way it does with the apps in DSF file.
30-
In an example above the result order would be:
31-
32-
```yaml
33-
- path: examples/minimal-example.toml
34-
- path: examples/minimal-example.yaml
35-
- path: examples/example.yaml
36-
```
37-
38-
with priorities being `-20, -10, 0` after ordering.
39-
40-
Once ordering is done, Helmsman will read each file one by one and merge the previous states with the current file it goes through.
27+
It takes the files from `stateFiles` list in the same order they are defined.
28+
Then Helmsman will read each file one by one and merge the previous states with the current file it goes through.
4129

4230
One can take advantage of that and define the state of the environment starting with more general definitions and then reaching more specific cases in the end,
4331
which would overwrite or extend things from previous files.

internal/app/cli.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"flag"
55
"fmt"
66
"os"
7-
"sort"
87
"strings"
98
)
109

@@ -45,14 +44,6 @@ func (f *fileOptionArray) Set(value string) error {
4544
return nil
4645
}
4746

48-
func (f fileOptionArray) sort() {
49-
log.Verbose("Sorting files listed in the -spec file based on their priorities... ")
50-
51-
sort.SliceStable(f, func(i, j int) bool {
52-
return (f)[i].priority < (f)[j].priority
53-
})
54-
}
55-
5647
func (i *stringArray) String() string {
5748
return strings.Join(*i, " ")
5849
}
@@ -279,7 +270,6 @@ func (c *cli) readState(s *State) error {
279270
}
280271
c.files = append(c.files, fo)
281272
}
282-
c.files.sort()
283273
}
284274

285275
// read the TOML/YAML desired state file

internal/app/spec_state_test.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -58,46 +58,3 @@ func Test_specFromYAML(t *testing.T) {
5858
})
5959
}
6060
}
61-
62-
func Test_specFileSort(t *testing.T) {
63-
type args struct {
64-
files fileOptionArray
65-
}
66-
tests := []struct {
67-
name string
68-
args args
69-
want [3]int
70-
}{
71-
{
72-
name: "test case 1 -- Files sorted by priority",
73-
args: args{
74-
files: fileOptionArray(
75-
[]fileOption{
76-
{"third.yaml", 0},
77-
{"first.yaml", -20},
78-
{"second.yaml", -10},
79-
}),
80-
},
81-
want: [3]int{-20, -10, 0},
82-
},
83-
}
84-
85-
teardownTestCase, err := setupStateFileTestCase(t)
86-
if err != nil {
87-
t.Fatal(err)
88-
}
89-
defer teardownTestCase(t)
90-
for _, tt := range tests {
91-
t.Run(tt.name, func(t *testing.T) {
92-
tt.args.files.sort()
93-
94-
got := [3]int{}
95-
for i, f := range tt.args.files {
96-
got[i] = f.priority
97-
}
98-
if got != tt.want {
99-
t.Errorf("files from spec file are not sorted by priority = %v, want %v", got, tt.want)
100-
}
101-
})
102-
}
103-
}

0 commit comments

Comments
 (0)