From 8adde6bf873b46f365146bc14fc4c8f46d82f8dc Mon Sep 17 00:00:00 2001 From: Patrick Pichler Date: Tue, 25 Apr 2023 12:59:24 +0200 Subject: [PATCH 1/3] fix: report failure if network policy doesn't match any pods Before, there was no failure reported by the netpol analyzer, if the matcher on the policy doesn't match any pods. Signed-off-by: Patrick Pichler --- pkg/analyzer/netpol.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/analyzer/netpol.go b/pkg/analyzer/netpol.go index c7d97d1c9a..a604c17547 100644 --- a/pkg/analyzer/netpol.go +++ b/pkg/analyzer/netpol.go @@ -54,23 +54,23 @@ func (NetworkPolicyAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) }, }, }) - continue - } - // Check if policy is not applied to any pods - podList, err := util.GetPodListByLabels(a.Client.GetClient(), a.Namespace, policy.Spec.PodSelector.MatchLabels) - if err != nil { - return nil, err - } - if len(podList.Items) == 0 { - failures = append(failures, common.Failure{ - Text: fmt.Sprintf("Network policy is not applied to any pods: %s", policy.Name), - Sensitive: []common.Sensitive{ - { - Unmasked: policy.Name, - Masked: util.MaskString(policy.Name), + } else { + // Check if policy is not applied to any pods + podList, err := util.GetPodListByLabels(a.Client.GetClient(), a.Namespace, policy.Spec.PodSelector.MatchLabels) + if err != nil { + return nil, err + } + if len(podList.Items) == 0 { + failures = append(failures, common.Failure{ + Text: fmt.Sprintf("Network policy is not applied to any pods: %s", policy.Name), + Sensitive: []common.Sensitive{ + { + Unmasked: policy.Name, + Masked: util.MaskString(policy.Name), + }, }, - }, - }) + }) + } } if len(failures) > 0 { From 947e94f35379712a2fb1e2a2c90636606e0e44b6 Mon Sep 17 00:00:00 2001 From: Patrick Pichler Date: Tue, 25 Apr 2023 13:08:42 +0200 Subject: [PATCH 2/3] fix: use correct result slice for cronjob analyzer Signed-off-by: Patrick Pichler --- pkg/analyzer/cronjob.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/analyzer/cronjob.go b/pkg/analyzer/cronjob.go index 31fb4e800d..b9ab541cee 100644 --- a/pkg/analyzer/cronjob.go +++ b/pkg/analyzer/cronjob.go @@ -33,11 +33,9 @@ func (analyzer CronJobAnalyzer) Analyze(a common.Analyzer) ([]common.Result, err "analyzer_name": kind, }) - var results []common.Result - cronJobList, err := a.Client.GetClient().BatchV1().CronJobs(a.Namespace).List(a.Context, v1.ListOptions{}) if err != nil { - return results, err + return nil, err } var preAnalysis = map[string]common.PreAnalysis{} @@ -114,7 +112,7 @@ func (analyzer CronJobAnalyzer) Analyze(a common.Analyzer) ([]common.Result, err Name: key, Error: value.FailureDetails, } - a.Results = append(results, currentAnalysis) + a.Results = append(a.Results, currentAnalysis) } } From c29860d418faa316bc167721e443f7b64eafd970 Mon Sep 17 00:00:00 2001 From: Patrick Pichler Date: Tue, 25 Apr 2023 13:12:41 +0200 Subject: [PATCH 3/3] fix: remove dead code Signed-off-by: Patrick Pichler --- cmd/serve/serve.go | 1 - pkg/ai/prompts.go | 3 --- 2 files changed, 4 deletions(-) diff --git a/cmd/serve/serve.go b/cmd/serve/serve.go index 6177a92478..8a556a6e62 100644 --- a/cmd/serve/serve.go +++ b/cmd/serve/serve.go @@ -26,7 +26,6 @@ import ( var ( port string backend string - token string ) var ServeCmd = &cobra.Command{ diff --git a/pkg/ai/prompts.go b/pkg/ai/prompts.go index e5b40db05b..6ba5d07053 100644 --- a/pkg/ai/prompts.go +++ b/pkg/ai/prompts.go @@ -2,7 +2,4 @@ package ai const ( default_prompt = "Simplify the following Kubernetes error message and provide a solution in %s: %s" - prompt_a = "Read the following input %s and provide possible scenarios for remediation in %s" - prompt_b = "Considering the following input from the Kubernetes resource %s and the error message %s, provide possible scenarios for remediation in %s" - prompt_c = "Reading the following %s error message and it's accompanying log message %s, how would you simplify this message?" )