Skip to content
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
51 changes: 51 additions & 0 deletions internal/site/presets_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package site

import (
"reflect"
"testing"

"gopkg.in/yaml.v3"

"github.com/modelsphere/swiss/internal/values"
)

func TestPresetsRoundTrip(t *testing.T) {
p, err := Parse([]byte(inputsHead+`presets:
storage-net:
description: on storage-network nodes
values:
nodeSelector:
ebof.modelsphere.io/storage-net: "true"
tolerations:
- key: ebof-test
operator: Exists
effect: NoSchedule
`), "test")
if err != nil {
t.Fatal(err)
}
got := p.Presets["storage-net"]
if got.Description != "on storage-network nodes" {
t.Errorf("description = %q", got.Description)
}
if sel, _ := values.Get(got.Values, "nodeSelector"); !reflect.DeepEqual(sel, values.Tree{"ebof.modelsphere.io/storage-net": "true"}) {
t.Errorf("nodeSelector = %#v", sel)
}
out, err := yaml.Marshal(p)
if err != nil {
t.Fatal(err)
}
again, err := Parse(out, "again")
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(again.Presets, p.Presets) {
t.Errorf("presets changed on the way back:\n%v\n%v", p.Presets, again.Presets)
}
}

func TestPresetValuesMustBeAMap(t *testing.T) {
if _, err := Parse([]byte(inputsHead+"presets:\n x:\n values: [a]\n"), "test"); err == nil {
t.Error("a preset whose values are a list parsed")
}
}
9 changes: 9 additions & 0 deletions internal/site/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ type Profile struct {
// the key -- unlike extra. Strings take pathTemplate's placeholders.
Inputs map[string]any `yaml:"inputs,omitempty" json:"inputs,omitempty"`

// Presets are named values a deploy may pick one of. The console merges the
// picked one into the form layer; swissd composes nothing from them.
Presets map[string]Preset `yaml:"presets,omitempty" json:"presets,omitempty"`

// Sites are the other clusters' swissd instances, for the nav switcher.
//
// In the profile rather than swissd's config because it is a fact about the
Expand All @@ -94,6 +98,11 @@ type Profile struct {
Extra values.Tree `yaml:"extra,omitempty" json:"extra,omitempty"`
}

type Preset struct {
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Values values.Tree `yaml:"values,omitempty" json:"values,omitempty"`
}

// Site is one other swissd, by name and address. The URL is where a browser
// goes, so it is an origin this one links to and never calls.
type Site struct {
Expand Down
Loading