-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matthis Holleville <matthish29@gmail.com>
- Loading branch information
1 parent
cad2b38
commit 5e1275f
Showing
4 changed files
with
66 additions
and
0 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
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,58 @@ | ||
package analyzer | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/k8sgpt-ai/k8sgpt/pkg/ai" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/util" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func AnalyzeIngress(ctx context.Context, config *AnalysisConfiguration, client *kubernetes.Client, aiClient ai.IAI, | ||
analysisResults *[]Analysis) error { | ||
|
||
list, err := client.GetClient().NetworkingV1().Ingresses(config.Namespace).List(ctx, metav1.ListOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var preAnalysis = map[string]PreAnalysis{} | ||
|
||
for _, ing := range list.Items { | ||
var failures []string | ||
// loop over rules | ||
for _, rule := range ing.Spec.Rules { | ||
// loop over paths | ||
for _, path := range rule.HTTP.Paths { | ||
_, err := client.GetClient().CoreV1().Services(ing.Namespace).Get(ctx, path.Backend.Service.Name, metav1.GetOptions{}) | ||
if err != nil { | ||
failures = append(failures, fmt.Sprintf("Ingress uses the service %s/%s which does not exist.", ing.Namespace, path.Backend.Service.Name)) | ||
} | ||
} | ||
} | ||
|
||
if len(failures) > 0 { | ||
preAnalysis[fmt.Sprintf("%s/%s", ing.Namespace, ing.Name)] = PreAnalysis{ | ||
Ingress: ing, | ||
FailureDetails: failures, | ||
} | ||
} | ||
|
||
} | ||
|
||
for key, value := range preAnalysis { | ||
var currentAnalysis = Analysis{ | ||
Kind: "Ingress", | ||
Name: key, | ||
Error: value.FailureDetails, | ||
} | ||
|
||
parent, _ := util.GetParent(client, value.Endpoint.ObjectMeta) | ||
currentAnalysis.ParentObject = parent | ||
*analysisResults = append(*analysisResults, currentAnalysis) | ||
} | ||
|
||
return nil | ||
} |