chore: additional analyzers

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
Alex Jones
2023-04-13 21:25:41 +01:00
parent 5dcc19038f
commit 23071fd2e6
11 changed files with 527 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
package analyzer
import (
"context"
"fmt"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/k8sgpt-ai/k8sgpt/pkg/common"
)
// DeploymentAnalyzer is an analyzer that checks for misconfigured Deployments
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
}
for _, deployment := range deployments.Items {
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{},
},
}
result := common.Result{
Kind: "Deployment",
Name: fmt.Sprintf("%s/%s", deployment.Namespace, deployment.Name),
Error: failureDetails,
ParentObject: "",
}
results = append(results, result)
}
}
return results, nil
}