diff --git a/Makefile b/Makefile index 9f0e013a0e..b7928e6903 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/go.mod b/go.mod index 941c9d0756..7533d126a4 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 @@ -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 ) diff --git a/go.sum b/go.sum index 75e22faf9b..5315b05503 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/pkg/custom/client.go b/pkg/custom/client.go index c95cd7688e..94e3c70edb 100644 --- a/pkg/custom/client.go +++ b/pkg/custom/client.go @@ -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" diff --git a/pkg/server/analyze/analyze.go b/pkg/server/analyze/analyze.go index 3fc68b8b4b..6b76e0b83e 100644 --- a/pkg/server/analyze/analyze.go +++ b/pkg/server/analyze/analyze.go @@ -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" ) diff --git a/pkg/server/config/config.go b/pkg/server/config/config.go index 1fc1541946..f367d7f23e 100644 --- a/pkg/server/config/config.go +++ b/pkg/server/config/config.go @@ -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" diff --git a/pkg/server/config/integration.go b/pkg/server/config/integration.go index 9059c3e6f9..dc9f3f69d1 100644 --- a/pkg/server/config/integration.go +++ b/pkg/server/config/integration.go @@ -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" @@ -12,7 +13,8 @@ import ( ) const ( - trivyName = "trivy" + trivyName = "trivy" + kyvernoName = "kyverno" ) // syncIntegration is aware of the following events @@ -111,12 +113,37 @@ func (*Handler) ListIntegrations(ctx context.Context, req *schemav1.ListIntegrat 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{ + Enabled: kyvernoActive, + Namespace: kyvernoNamespace, + SkipInstall: true, + }, } return resp, nil diff --git a/pkg/server/server.go b/pkg/server/server.go index fb9f8e1d03..ecb4818219 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -17,15 +17,16 @@ import ( "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" + 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"