Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: kyverno operator support #1210

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d5cd7ef
enables operator but not finished
ronaldpetty Jul 29, 2024
ceb018a
enables operator but not finished
ronaldpetty Jul 29, 2024
89ca9a7
Merge branch 'kyverno-operator' of github.com:ronaldpetty/k8sgpt into…
ronaldpetty Jul 29, 2024
0fc3008
Merge branch 'main' of https://github.com/k8sgpt-ai/k8sgpt into kyver…
ronaldpetty Aug 17, 2024
d6c9ba5
fix: add default maxToken value of watsonxai backend (#1209)
liyanwei93 Aug 2, 2024
7e5f0c0
chore(deps): update anchore/sbom-action action to v0.17.0 (#1197)
renovate[bot] Aug 2, 2024
1a2ec0b
fix(deps): update module github.com/schollz/progressbar/v3 to v3.14.5…
renovate[bot] Aug 2, 2024
ea3dbb6
feat: initial custom analysis server mode (#1205)
AlexsJones Aug 4, 2024
da1cb19
chore(main): release 0.3.40 (#1202)
github-actions[bot] Aug 4, 2024
412340e
fix: segmentation violation during serve (#1215)
yankay Aug 7, 2024
4538a42
chore(deps): update actions/upload-artifact digest to 834a144 (#1214)
renovate[bot] Aug 7, 2024
d4cf0ca
fix: set logger for controller-runtime (#1211)
yeahdongcn Aug 8, 2024
07582a3
docs: update "CLI Installation" section in README.md (#1126) (#1127)
ut-wangbo Aug 8, 2024
0098776
feat: add custom-analyzer cmd (#1207)
matthisholleville Aug 10, 2024
da105be
chore(deps): update actions/checkout digest to 692973e (#1129)
renovate[bot] Aug 13, 2024
a13285d
feat: add event failure handling in service analyzer (#1132)
magicsong Aug 13, 2024
19b04aa
fix(deps): update module github.com/docker/docker to v27.1.1+incompat…
renovate[bot] Aug 13, 2024
9d145f4
feat: refactoring to the new schema (#1219)
AlexsJones Aug 15, 2024
bed17d9
chore(deps): update anchore/sbom-action action to v0.17.1 (#1224)
renovate[bot] Aug 15, 2024
81352db
fix(deps): update module github.com/mittwald/go-helm-client to v0.12.…
renovate[bot] Aug 15, 2024
ace531d
Merge branch 'main' of https://github.com/k8sgpt-ai/k8sgpt into kyver…
ronaldpetty Aug 17, 2024
96f7a02
updating from main
ronaldpetty Aug 17, 2024
c3ccfe3
changed back to normal schema repo
ronaldpetty Aug 18, 2024
b2d0a0b
xdg missing?
ronaldpetty Aug 18, 2024
f0f0777
fixed dup
ronaldpetty Aug 18, 2024
228702d
remove hack to fix race, figure out real fix
ronaldpetty Aug 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ BUILDFILE = "./main.go"
BUILDAPP = "$(OUTPUT_DIR)/k8sgpt"

.PHONY: all
all: tidy add-copyright lint cover build
all: tidy lint cover build

# ==============================================================================
# Targets
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ require (

)

require github.com/adrg/xdg v0.4.0

require (
buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc-ecosystem/gateway/v2 v2.21.0-20240807134501-ea98c104104d.1
buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go v1.5.1-20240807134501-ea98c104104d.1
Expand All @@ -36,6 +34,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.3.2
github.com/IBM/watsonx-go v1.0.1
github.com/adrg/xdg v0.5.0
github.com/aws/aws-sdk-go v1.53.21
github.com/cohere-ai/cohere-go/v2 v2.7.3
github.com/go-logr/zapr v1.3.0
Expand Down Expand Up @@ -115,6 +114,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20240723171418-e6d459c13d2a // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
knative.dev/pkg v0.0.0-20230616134650-eb63a40adfb0 // indirect
)

Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,8 @@ github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d h1:UrqY+r/O
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ=
github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
github.com/adrg/xdg v0.5.0 h1:dDaZvhMXatArP1NPHhnfaQUqWBLBsmx1h1HXQdMoFCY=
github.com/adrg/xdg v0.5.0/go.mod h1:dDdY4M4DF9Rjy4kHPeNL+ilVF+p2lK8IdM9/rTSGcI4=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY=
Expand Down Expand Up @@ -1789,7 +1789,6 @@ golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down Expand Up @@ -2238,8 +2237,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
helm.sh/helm/v3 v3.15.2 h1:/3XINUFinJOBjQplGnjw92eLGpgXXp1L8chWPkCkDuw=
helm.sh/helm/v3 v3.15.2/go.mod h1:FzSIP8jDQaa6WAVg9F+OkKz7J0ZmAga4MABtTbsb9WQ=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
5 changes: 3 additions & 2 deletions pkg/custom/client.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package custom

import (
rpc "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go/schema/v1/schemav1grpc"
schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1"
"context"
"fmt"

rpc "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go/schema/v1/schemav1grpc"
schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1"
"github.com/k8sgpt-ai/k8sgpt/pkg/common"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand Down
3 changes: 2 additions & 1 deletion pkg/server/analyze/analyze.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package analyze

import (
schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1"
"context"
json "encoding/json"

schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1"
"github.com/k8sgpt-ai/k8sgpt/pkg/analysis"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/server/config/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package config

import (
schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1"
"context"

schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1"
"github.com/k8sgpt-ai/k8sgpt/pkg/cache"
"github.com/k8sgpt-ai/k8sgpt/pkg/custom"
"github.com/spf13/viper"
Expand Down
31 changes: 29 additions & 2 deletions pkg/server/config/integration.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package config

import (
schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1"
"context"
"fmt"

schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1"
"github.com/k8sgpt-ai/k8sgpt/pkg/analyzer"
"github.com/k8sgpt-ai/k8sgpt/pkg/integration"
"github.com/spf13/viper"
Expand All @@ -12,7 +13,8 @@
)

const (
trivyName = "trivy"
trivyName = "trivy"
kyvernoName = "kyverno"
)

// syncIntegration is aware of the following events
Expand Down Expand Up @@ -111,12 +113,37 @@
if err != nil {
return nil, status.Error(codes.NotFound, "trivy integration")
}

// TODO: RP kyverno for operator
kyverno, err := integrationProvider.Get(kyvernoName)
kyvernoActive := kyverno.IsActivate()

var kyvernoNamespace string = ""
if kyvernoActive {
kyvernoNamespace, err = kyverno.GetNamespace()
if err != nil {
return nil, status.Error(codes.NotFound, "namespace not found")
}
if kyvernoNamespace == "" {
skipInstall = true
}
}

if err != nil {
return nil, status.Error(codes.NotFound, "kyverno integration")
}

resp := &schemav1.ListIntegrationsResponse{
Trivy: &schemav1.Trivy{
Enabled: active,
Namespace: namespace,
SkipInstall: skipInstall,
},
Kyverno: &schemav1.Kyverno{

Check failure on line 142 in pkg/server/config/integration.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci] reported by reviewdog 🐢 unknown field Kyverno in struct literal of type schemav1.ListIntegrationsResponse Raw Output: pkg/server/config/integration.go:142:3: unknown field Kyverno in struct literal of type schemav1.ListIntegrationsResponse

Check failure on line 142 in pkg/server/config/integration.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci] reported by reviewdog 🐢 undefined: schemav1.Kyverno (typecheck) Raw Output: pkg/server/config/integration.go:142:22: undefined: schemav1.Kyverno (typecheck) package config

Check failure on line 142 in pkg/server/config/integration.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci] reported by reviewdog 🐢 unknown field Kyverno in struct literal of type schemav1.ListIntegrationsResponse Raw Output: pkg/server/config/integration.go:142:3: unknown field Kyverno in struct literal of type schemav1.ListIntegrationsResponse

Check failure on line 142 in pkg/server/config/integration.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci] reported by reviewdog 🐢 undefined: schemav1.Kyverno) (typecheck) Raw Output: pkg/server/config/integration.go:142:22: undefined: schemav1.Kyverno) (typecheck) "github.com/k8sgpt-ai/k8sgpt/pkg/server/config" ^

Check failure on line 142 in pkg/server/config/integration.go

View workflow job for this annotation

GitHub Actions / build

unknown field Kyverno in struct literal of type schemav1.ListIntegrationsResponse

Check failure on line 142 in pkg/server/config/integration.go

View workflow job for this annotation

GitHub Actions / build

undefined: schemav1.Kyverno
Enabled: kyvernoActive,
Namespace: kyvernoNamespace,
SkipInstall: true,
},
}

return resp, nil
Expand Down
7 changes: 4 additions & 3 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
"context"
"errors"
"fmt"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/k8sgpt-ai/k8sgpt/pkg/server/analyze"
"github.com/k8sgpt-ai/k8sgpt/pkg/server/config"
"log"
"net"
"net/http"
"strings"
"time"

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/k8sgpt-ai/k8sgpt/pkg/server/analyze"
"github.com/k8sgpt-ai/k8sgpt/pkg/server/config"

Check failure on line 28 in pkg/server/server.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci] reported by reviewdog 🐢 could not import github.com/k8sgpt-ai/k8sgpt/pkg/server/config (-: # github.com/k8sgpt-ai/k8sgpt/pkg/server/config Raw Output: pkg/server/server.go:28:2: could not import github.com/k8sgpt-ai/k8sgpt/pkg/server/config (-: # github.com/k8sgpt-ai/k8sgpt/pkg/server/config

gw2 "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc-ecosystem/gateway/v2/schema/v1/server_analyzer_service/schemav1gateway"
gw "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc-ecosystem/gateway/v2/schema/v1/server_config_service/schemav1gateway"
rpc "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go/schema/v1/schemav1grpc"
Expand Down
Loading