chore: fixing up tests

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
Alex Jones
2023-04-13 21:44:33 +01:00
parent 23071fd2e6
commit 498d454c17
6 changed files with 71 additions and 63 deletions

View File

@@ -16,31 +16,40 @@ type DeploymentAnalyzer struct {
// Analyze scans all namespaces for Deployments with misconfigurations
func (d DeploymentAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) {
var results []common.Result
deployments, err := a.Client.GetClient().AppsV1().Deployments("").List(context.Background(), v1.ListOptions{})
if err != nil {
return nil, err
}
var preAnalysis = map[string]common.PreAnalysis{}
for _, deployment := range deployments.Items {
var failures []common.Failure
if *deployment.Spec.Replicas != deployment.Status.Replicas {
failureDetails := []common.Failure{
{
Text: fmt.Sprintf("Deployment %s has a mismatch between the desired and actual replicas", deployment.Name),
Sensitive: []common.Sensitive{},
failures = append(failures, common.Failure{
Text: fmt.Sprintf("Deployment %s/%s has %d replicas but %d are available", deployment.Namespace, deployment.Name, *deployment.Spec.Replicas, deployment.Status.Replicas),
Sensitive: []common.Sensitive{
{},
},
}
result := common.Result{
Kind: "Deployment",
Name: fmt.Sprintf("%s/%s", deployment.Namespace, deployment.Name),
Error: failureDetails,
ParentObject: "",
}
results = append(results, result)
})
}
if len(failures) > 0 {
preAnalysis[fmt.Sprintf("%s/%s", deployment.Namespace, deployment.Name)] = common.PreAnalysis{
FailureDetails: failures,
Deployment: deployment,
}
}
}
return results, nil
for key, value := range preAnalysis {
var currentAnalysis = common.Result{
Kind: "Deployment",
Name: key,
Error: value.FailureDetails,
}
a.Results = append(a.Results, currentAnalysis)
}
return a.Results, nil
}