-
Notifications
You must be signed in to change notification settings - Fork 215
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
Add --audit and --audit-destination flags #40
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package validator | ||
|
||
import ( | ||
conf "github.com/reactiveops/fairwinds/pkg/config" | ||
"github.com/reactiveops/fairwinds/pkg/kube" | ||
) | ||
|
||
// AuditData contains all the data from a full Fairwinds audit | ||
type AuditData struct { | ||
ClusterSummary ResultSummary | ||
NamespacedResults NamespacedResults | ||
} | ||
|
||
// RunAudit runs a full Fairwinds audit and returns an AuditData object | ||
func RunAudit(config conf.Configuration, kubeAPI *kube.API) (AuditData, error) { | ||
// TODO: Validate StatefulSets, DaemonSets, Cron jobs | ||
// in addition to deployments | ||
|
||
// TODO: Once we are validating more than deployments, | ||
// we will need to merge the namespaceResults that get returned | ||
// from each validation. | ||
nsResults, err := ValidateDeploys(config, kubeAPI) | ||
if err != nil { | ||
return AuditData{}, err | ||
} | ||
|
||
var clusterSuccesses, clusterErrors, clusterWarnings uint | ||
|
||
// Aggregate all summary counts to get a clusterwide count. | ||
for _, nsRes := range nsResults { | ||
for _, rr := range nsRes.Results { | ||
clusterErrors += rr.Summary.Errors | ||
clusterWarnings += rr.Summary.Warnings | ||
clusterSuccesses += rr.Summary.Successes | ||
} | ||
} | ||
|
||
auditData := AuditData{ | ||
ClusterSummary: ResultSummary{ | ||
Errors: clusterErrors, | ||
Warnings: clusterWarnings, | ||
Successes: clusterSuccesses, | ||
}, | ||
NamespacedResults: nsResults, | ||
} | ||
return auditData, nil | ||
} |
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,36 @@ | ||
package validator | ||
|
||
import ( | ||
"testing" | ||
|
||
conf "github.com/reactiveops/fairwinds/pkg/config" | ||
"github.com/reactiveops/fairwinds/test" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetTemplateData(t *testing.T) { | ||
k8s := test.SetupTestAPI() | ||
k8s = test.SetupAddDeploys(k8s, "test") | ||
|
||
c := conf.Configuration{ | ||
HealthChecks: conf.HealthChecks{ | ||
ReadinessProbeMissing: conf.SeverityError, | ||
LivenessProbeMissing: conf.SeverityWarning, | ||
}, | ||
} | ||
|
||
sum := ResultSummary{ | ||
Successes: uint(4), | ||
Warnings: uint(1), | ||
Errors: uint(1), | ||
} | ||
|
||
actualAudit, err := RunAudit(c, k8s) | ||
assert.Equal(t, err, nil, "error should be nil") | ||
|
||
assert.EqualValues(t, actualAudit.ClusterSummary, sum) | ||
assert.Equal(t, len(actualAudit.NamespacedResults["test"].Results), 1, "should be equal") | ||
assert.Equal(t, len(actualAudit.NamespacedResults["test"].Results[0].PodResults), 1, "should be equal") | ||
assert.Equal(t, len(actualAudit.NamespacedResults["test"].Results[0].PodResults[0].ContainerResults), 1, "should be equal") | ||
assert.Equal(t, len(actualAudit.NamespacedResults["test"].Results[0].PodResults[0].ContainerResults[0].Messages), 6, "should be equal") | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand this correctly, audit, webhook, and dashboard are all separate modes Fairwinds can run in, but it can never run in more than one of them. Is that accurate? If so, it might make more sense to have a single mode/service/whatever argument with a default value, maybe dashboard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the impression that you could run
webhook
anddashboard
simultaneously. Is that wrong?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe that's currently possible due to them both requiring a server to run, and those servers being different implementations (one of which is specific to controller-runtime's webhook implementation). I think it could be possible to run them together at some point in the future, but it may be simplest to keep them separate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the case, it might make sense to split these operations into different binaries. I can take a crack at that in another PR if you agree.
For now, I set
audit
as the default, since that's the simplest operation. It'll also exit immediately, so if you intended a different operation you won't be sitting there waiting for it to finish.