diff --git a/docs/how_to/misc/multiple_desired_state_files_specification.md b/docs/how_to/misc/multiple_desired_state_files_specification.md index 8167ec79..2da97e6f 100644 --- a/docs/how_to/misc/multiple_desired_state_files_specification.md +++ b/docs/how_to/misc/multiple_desired_state_files_specification.md @@ -5,7 +5,7 @@ version: v3.8.1 # Specification file Starting from v3.8.0, Helmsman allows you to use Specification file passed with `--spec ` flag -in order to define multiple Desired State Files to be merged in particular order and with specific priorities. +in order to define multiple Desired State Files to be merged together. An example Specification file `spec.yaml`: @@ -14,9 +14,7 @@ An example Specification file `spec.yaml`: stateFiles: - path: examples/example.yaml - path: examples/minimal-example.yaml - priority: -10 - path: examples/minimal-example.toml - priority: -20 ``` @@ -26,18 +24,8 @@ This file can be then run with: helmsman --spec spec.yaml ... ``` -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. -In an example above the result order would be: - -```yaml - - path: examples/minimal-example.toml - - path: examples/minimal-example.yaml - - path: examples/example.yaml -``` - -with priorities being `-20, -10, 0` after ordering. - -Once ordering is done, Helmsman will read each file one by one and merge the previous states with the current file it goes through. +It takes the files from `stateFiles` list in the same order they are defined. +Then Helmsman will read each file one by one and merge the previous states with the current file it goes through. 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, which would overwrite or extend things from previous files. diff --git a/internal/app/cli.go b/internal/app/cli.go index 24a2f009..d959304f 100644 --- a/internal/app/cli.go +++ b/internal/app/cli.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "os" - "sort" "strings" ) @@ -45,14 +44,6 @@ func (f *fileOptionArray) Set(value string) error { return nil } -func (f fileOptionArray) sort() { - log.Verbose("Sorting files listed in the -spec file based on their priorities... ") - - sort.SliceStable(f, func(i, j int) bool { - return (f)[i].priority < (f)[j].priority - }) -} - func (i *stringArray) String() string { return strings.Join(*i, " ") } @@ -279,7 +270,6 @@ func (c *cli) readState(s *State) error { } c.files = append(c.files, fo) } - c.files.sort() } // read the TOML/YAML desired state file diff --git a/internal/app/spec_state_test.go b/internal/app/spec_state_test.go index ac514fa3..728a834d 100644 --- a/internal/app/spec_state_test.go +++ b/internal/app/spec_state_test.go @@ -58,46 +58,3 @@ func Test_specFromYAML(t *testing.T) { }) } } - -func Test_specFileSort(t *testing.T) { - type args struct { - files fileOptionArray - } - tests := []struct { - name string - args args - want [3]int - }{ - { - name: "test case 1 -- Files sorted by priority", - args: args{ - files: fileOptionArray( - []fileOption{ - {"third.yaml", 0}, - {"first.yaml", -20}, - {"second.yaml", -10}, - }), - }, - want: [3]int{-20, -10, 0}, - }, - } - - teardownTestCase, err := setupStateFileTestCase(t) - if err != nil { - t.Fatal(err) - } - defer teardownTestCase(t) - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - tt.args.files.sort() - - got := [3]int{} - for i, f := range tt.args.files { - got[i] = f.priority - } - if got != tt.want { - t.Errorf("files from spec file are not sorted by priority = %v, want %v", got, tt.want) - } - }) - } -}