k8sgpt-ai / k8sgpt-operator

Automatic SRE Superpowers within your Kubernetes cluster
https://k8sgpt.ai
Apache License 2.0
314 stars 89 forks source link

[BUG]: "namespace not found" when trivy integration is active #311

Open jkleinlercher opened 9 months ago

jkleinlercher commented 9 months ago

Checklist

Affected Components

K8sGPT Version

v0.0.27

Kubernetes Version

No response

Host OS and its Version

No response

Steps to reproduce

  1. install trivy-operator without helm (e.g. argocd)
  2. install k8sgpt-operator with the following stanza in K8sGPT cr:
  integrations:
    trivy:
      enabled: true
      namespace: suxess-it-trivy
      skipInstall: true
  1. in the k8sgpt deployment you will see logs like this

{"level":"info","ts":1704729522.83985,"caller":"server/log.go:50","msg":"request failed. rpc error: code = NotFound desc = namespace not found","duration_ms":82,"method":"/schema.v1.ServerService/ListIntegrations","request":"","remote_addr":"10.130.2.33:36380","status_code":5}

Expected behaviour

k8sgpt should just work, enable trivy integration and recognize that trivy is installed in the configured namespace

Actual behaviour

k8sgpt checks in https://github.com/k8sgpt-ai/k8sgpt/blob/5c17c240550609d9fb7771fe67fe1ab19660b4da/pkg/integration/trivy/trivy.go#L70C26-L80 if trivy is installed via helm, which is not true when trivy is deployed via argocd

Additional Information

No response

aryasoni98 commented 9 months ago

I would like to work on it .

jkleinlercher commented 8 months ago

@aryasoni98 great! If you need some additional information, feel free to ask

intonet commented 7 months ago

I had the same issue.

dirac34 commented 2 months ago

have you got install k8sgpt operator with trivy?

Hemant-Sadana commented 3 weeks ago

Any plans to fix this ? I am also getting the same error while using the operator way of deployment. Trivy integration works for the first time, but when PreAnalysis step is called next time, it fails with following error:

{"level":"info","ts":1728376981.8452039,"caller":"server/log.go:50","msg":"request failed. rpc error: code = NotFound desc = namespace not found","duration_ms":17,"method":"/schema.v1.ServerConfigService/ListIntegrations","request":"","remote_addr":"100.100.193.215:56946","status_code":5}

Looks like the following part of code has some issue (it has the comment as well that it does not work):

_pkg/integration/trivy/trivy.go_

// This doesnt work
func (t *Trivy) GetNamespace() (string, error) {
    releases, err := t.helm.ListDeployedReleases()
    if err != nil {
        return "", err
    }
    for _, rel := range releases {
        if rel.Name == ReleaseName {
            return rel.Namespace, nil
        }
    }
    return "", status.Error(codes.NotFound, "trivy release not found")
}

Steps that I followed for trivy integration:

Installed trivy manually under trivy-system namespace and have set skipInstall to true in K8sGPT.