Skip to content

Commit

Permalink
PRODENG-2654 MSR without MKE fails config validate (#490)
Browse files Browse the repository at this point in the history
- As both MSR2 and MSR3 require MKE, config validation will fail if
  msr2/msr3 blocks are in the config, but mke is not
- ClusterSpec validation handler combine
- Had to do a fair amount of unit test cleanup to get tests to pass:

- As both MSR2 and MSR3 require MKE, config validation will fail if msr2/msr3 blocks are in the config, but mke is not ClusterSpec validation handler combine

ALSO:

- Had to do a fair amount of unit test cleanup to get tests to pass:
  - fix MSR2 host & MSR testing
  - updated several test schema versions and product versions in test yaml
  - dropped really outdated migration tests for beta spec version
  - whitespace cleanup in test yaml (tabs & spaces)
  - standardized whitespace in test calls, so that they all look the same
  - updated product versions in test yaml

Signed-off-by: James Nesbitt <[email protected]>
Co-authored-by: Pathma Sri Ambegode Gedara <[email protected]>
  • Loading branch information
james-nesbitt and pgedara authored Aug 2, 2024
1 parent f6be297 commit c0df8e3
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 176 deletions.
23 changes: 17 additions & 6 deletions pkg/product/mke/api/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,32 @@ func (c *ClusterConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
// Currently we do only very "static" validation using https://github.com/go-playground/validator
func (c *ClusterConfig) Validate() error {
validator := validator.New(validator.WithRequiredStructEnabled())
validator.RegisterStructValidation(roleChecks, ClusterSpec{})
validator.RegisterStructValidation(validateClusterSpec, ClusterSpec{})
if err := validator.Struct(c); err != nil {
return fmt.Errorf("cluster config validation failed: %w", err)
}

return nil
}

func roleChecks(sl validator.StructLevel) {
spec, ok := sl.Current().Interface().(ClusterSpec)
func validateClusterSpec(vsl validator.StructLevel) {
spec, ok := vsl.Current().Interface().(ClusterSpec)

if !ok {
vsl.ReportError(nil, "spec", "", "no spec in cluster", "")
return
}
hosts := spec.Hosts
if hosts.Count(func(h *Host) bool { return h.Role == "manager" }) == 0 {
sl.ReportError(hosts, "hosts", "", "manager required", "")

if len(spec.Managers()) == 0 {
vsl.ReportError(spec.Hosts, "hosts", "", "at least one manager host required", "")
}

if spec.MSR2 != nil && len(spec.MSR2s()) == 0 {
vsl.ReportError(spec.Hosts, "hosts", "", "with msr2 configuration, at least one msr2 host is required", "")
}

if spec.MKE == nil && (spec.MSR2 != nil || spec.MSR3 != nil) {
vsl.ReportError(spec, "spec", "", "if msr2 or msr3 installation is requested, mke must also be included in the installation instructions", "")
}
}

Expand Down
Loading

0 comments on commit c0df8e3

Please sign in to comment.