-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from reactiveops/rs/better-resource-checks
Improving resource validation, lots of restructuring to add ContainerValidation type
- Loading branch information
Showing
9 changed files
with
122 additions
and
149 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
deploy | ||
.gitignore | ||
.git/* | ||
Dockerfile | ||
LICENSE | ||
Tiltfile |
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 |
---|---|---|
|
@@ -12,3 +12,4 @@ | |
*.out | ||
|
||
Tiltfile | ||
main |
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 was deleted.
Oops, something went wrong.
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,48 @@ | ||
package validator | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// Results contains the validation check results. | ||
type Results struct { | ||
Pass bool | ||
FailMsg string | ||
ContainerValidations []ContainerValidation | ||
InitContainerValidations []ContainerValidation | ||
} | ||
|
||
// Format structures the validation results to return back to k8s API. | ||
func (r *Results) Format() (bool, string) { | ||
var sb strings.Builder | ||
r.Pass = true | ||
|
||
for _, cv := range r.ContainerValidations { | ||
if !validContainer(&sb, &cv) { | ||
r.Pass = false | ||
} | ||
} | ||
|
||
for _, cv := range r.InitContainerValidations { | ||
if !validContainer(&sb, &cv) { | ||
r.Pass = false | ||
} | ||
} | ||
|
||
r.FailMsg = sb.String() | ||
return r.Pass, r.FailMsg | ||
} | ||
|
||
func validContainer(sb *strings.Builder, cv *ContainerValidation) bool { | ||
if len(cv.Failures) == 0 { | ||
return true | ||
} | ||
|
||
s := fmt.Sprintf("\nContainer: %s\n Failure/s:\n", cv.Container.Name) | ||
sb.WriteString(s) | ||
for _, failure := range cv.Failures { | ||
sb.WriteString(failure.Reason()) | ||
} | ||
return false | ||
} |