-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config validation for all components (#3952)
* Add config validation to all armada components * Make invalid config error and remove required tag from unrequired fields --------- Co-authored-by: Eleanor Pratt <[email protected]>
- Loading branch information
1 parent
f45aefa
commit 549c5b9
Showing
15 changed files
with
123 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package configuration | ||
|
||
import "github.com/go-playground/validator/v10" | ||
|
||
func (c BinocularsConfig) Validate() error { | ||
validate := validator.New() | ||
return validate.Struct(c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package configuration | ||
|
||
import ( | ||
"github.com/go-playground/validator/v10" | ||
) | ||
|
||
func (c EventIngesterConfiguration) Validate() error { | ||
validate := validator.New() | ||
return validate.Struct(c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package configuration | ||
|
||
import "github.com/go-playground/validator/v10" | ||
|
||
func (c ExecutorConfiguration) Validate() error { | ||
validate := validator.New() | ||
return validate.Struct(c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package configuration | ||
|
||
import "github.com/go-playground/validator/v10" | ||
|
||
func (c LookoutIngesterV2Configuration) Validate() error { | ||
validate := validator.New() | ||
return validate.Struct(c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package configuration | ||
|
||
import "github.com/go-playground/validator/v10" | ||
|
||
func (c LookoutV2Config) Validate() error { | ||
validate := validator.New() | ||
return validate.Struct(c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package configuration | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/go-playground/validator/v10" | ||
) | ||
|
||
func (c Configuration) Validate() error { | ||
validate := validator.New() | ||
validate.RegisterStructValidation(SchedulingConfigValidation, SchedulingConfig{}) | ||
return validate.Struct(c) | ||
} | ||
|
||
func SchedulingConfigValidation(sl validator.StructLevel) { | ||
c := sl.Current().Interface().(SchedulingConfig) | ||
|
||
wellKnownNodeTypes := make(map[string]bool) | ||
for i, wellKnownNodeType := range c.WellKnownNodeTypes { | ||
if wellKnownNodeTypes[wellKnownNodeType.Name] { | ||
fieldName := fmt.Sprintf("WellKnownNodeTypes[%d].Name", i) | ||
sl.ReportError(wellKnownNodeType.Name, fieldName, "", DuplicateWellKnownNodeTypeErrorMessage, "") | ||
} | ||
wellKnownNodeTypes[wellKnownNodeType.Name] = true | ||
} | ||
|
||
for priorityClassName, priorityClass := range c.PriorityClasses { | ||
if len(priorityClass.AwayNodeTypes) > 0 && !priorityClass.Preemptible { | ||
fieldName := fmt.Sprintf("Preemption.PriorityClasses[%s].Preemptible", priorityClassName) | ||
sl.ReportError(priorityClass.Preemptible, fieldName, "", AwayNodeTypesWithoutPreemptionErrorMessage, "") | ||
} | ||
|
||
for i, awayNodeType := range priorityClass.AwayNodeTypes { | ||
if !wellKnownNodeTypes[awayNodeType.WellKnownNodeTypeName] { | ||
fieldName := fmt.Sprintf("Preemption.PriorityClasses[%s].AwayNodeTypes[%d].WellKnownNodeTypeName", priorityClassName, i) | ||
sl.ReportError(awayNodeType.WellKnownNodeTypeName, fieldName, "", UnknownWellKnownNodeTypeErrorMessage, "") | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package configuration | ||
|
||
import "github.com/go-playground/validator/v10" | ||
|
||
func (c ArmadaConfig) Validate() error { | ||
validate := validator.New() | ||
return validate.Struct(c) | ||
} |