Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove 'priority' field from -spec docs #781

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions docs/how_to/misc/multiple_desired_state_files_specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <file>` 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`:

Expand All @@ -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

```

Expand All @@ -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.
10 changes: 0 additions & 10 deletions internal/app/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"os"
"sort"
"strings"
)

Expand Down Expand Up @@ -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, " ")
}
Expand Down Expand Up @@ -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
Expand Down
43 changes: 0 additions & 43 deletions internal/app/spec_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}