Skip to content

Commit

Permalink
feat: rework cache & add gcs cache option (#262)
Browse files Browse the repository at this point in the history
* feat: rework cache & add gcs cache option

Signed-off-by: Matthis Holleville <matthish29@gmail.com>

* feat: update dependencies

Signed-off-by: Matthis Holleville <matthish29@gmail.com>

* feat: update cache sample

Signed-off-by: Matthis Holleville <matthish29@gmail.com>

* feat: update crd

Signed-off-by: Matthis Holleville <matthish29@gmail.com>

---------

Signed-off-by: Matthis Holleville <matthish29@gmail.com>
Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
  • Loading branch information
matthisholleville and AlexsJones authored Nov 18, 2023
1 parent 1ca833b commit c9f1290
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 16 deletions.
7 changes: 7 additions & 0 deletions api/v1alpha1/k8sgpt_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type CredentialsRef struct {

type RemoteCacheRef struct {
Credentials *CredentialsRef `json:"credentials,omitempty"`
GCS *GCSBackend `json:"gcs,omitempty"`
S3 *S3Backend `json:"s3,omitempty"`
Azure *AzureBackend `json:"azure,omitempty"`
}
Expand All @@ -56,6 +57,12 @@ type AzureBackend struct {
ContainerName string `json:"containerName,omitempty"`
}

type GCSBackend struct {
BucketName string `json:"bucketName,omitempty"`
Region string `json:"region,omitempty"`
ProjectId string `json:"projectId,omitempty"`
}

type WebhookRef struct {
// +kubebuilder:validation:Enum=slack
Type string `json:"type,omitempty"`
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions chart/operator/templates/k8sgpt-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ spec:
name:
type: string
type: object
gcs:
properties:
bucketName:
type: string
projectId:
type: string
region:
type: string
type: object
s3:
properties:
bucketName:
Expand Down
9 changes: 9 additions & 0 deletions config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ spec:
name:
type: string
type: object
gcs:
properties:
bucketName:
type: string
projectId:
type: string
region:
type: string
type: object
s3:
properties:
bucketName:
Expand Down
11 changes: 6 additions & 5 deletions config/samples/core_v1alpha1_k8sgpt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ spec:
key: openai-api-key
noCache: false
version: v0.3.17
# remoteCache:
# credentials:
# name: k8sgpt-sample-cache-secret
# bucketName: k8sgpt-debug-test
# region: eu-west-2
# remoteCache:
# credentials:
# name: k8sgpt-sample-cache-secret
# s3:
# bucketName: foo
# region: us-west-1
integrations:
trivy:
enabled: false
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/k8sgpt-ai/k8sgpt-operator
go 1.19

require (
buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go v1.3.0-20231002095256-194bc640518b.1
buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go v1.31.0-20231002095256-194bc640518b.1
buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go v1.3.0-20231116211251-9f5041346631.2
buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go v1.28.1-20231116211251-9f5041346631.4
github.com/onsi/ginkgo/v2 v2.13.1
github.com/onsi/gomega v1.30.0
github.com/prometheus/client_golang v1.17.0
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go v1.3.0-20231002095256-194bc640518b.1 h1:xYEAhcdWh89HNtbM5Uv4b2xu+4/MkNffR9JNrnnEjXU=
buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go v1.3.0-20231002095256-194bc640518b.1/go.mod h1:j2QJ3L7VTtI+VeK6t03h9X934FolVTb3FwXUc76bQMQ=
buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go v1.28.1-20231002095256-194bc640518b.4/go.mod h1:i/s4ALHwKvjA1oGNKpoHg0FpEOTbufoOm/NdTE6YQAE=
buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go v1.31.0-20231002095256-194bc640518b.1 h1:Bt8mnCodD/BqChxt/r3xYayGLoOAn334qC1tN7VqUTE=
buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go v1.31.0-20231002095256-194bc640518b.1/go.mod h1:gtnk2yAUexdY5nTuUg0SH5WCCGvpKzr7pd3Xbi7MWjE=
buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go v1.3.0-20231116211251-9f5041346631.2 h1:lr4kHFzPIzoWIHF6s/B+0Wb/WknraHrbqNguavOzP70=
buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go v1.3.0-20231116211251-9f5041346631.2/go.mod h1:g/UdFu0wAAS44ncCfX3zjna7WC1gp6BENVL6LPJ9tow=
buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go v1.28.1-20231116211251-9f5041346631.4 h1:f7e94G/tYVs+QDTvjU9sFolC5tuJxlOjzUBJ84XMwkg=
buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go v1.28.1-20231116211251-9f5041346631.4/go.mod h1:i/s4ALHwKvjA1oGNKpoHg0FpEOTbufoOm/NdTE6YQAE=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
Expand Down
26 changes: 22 additions & 4 deletions pkg/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,31 @@ func (c *Client) AddConfig(config *v1alpha1.K8sGPT) error {
// which emulates the behaviour of K8sGPT cli
if config.Spec.RemoteCache.S3 != nil {
req.Cache = &schemav1.Cache{
BucketName: config.Spec.RemoteCache.S3.BucketName,
Region: config.Spec.RemoteCache.S3.Region,
CacheType: &schemav1.Cache_S3Cache{
S3Cache: &schemav1.S3Cache{
BucketName: config.Spec.RemoteCache.S3.BucketName,
Region: config.Spec.RemoteCache.S3.Region,
},
},
}
} else if config.Spec.RemoteCache.Azure != nil {
req.Cache = &schemav1.Cache{
StorageAccount: config.Spec.RemoteCache.Azure.StorageAccount,
ContainerName: config.Spec.RemoteCache.Azure.ContainerName,
CacheType: &schemav1.Cache_AzureCache{
AzureCache: &schemav1.AzureCache{
StorageAccount: config.Spec.RemoteCache.Azure.StorageAccount,
ContainerName: config.Spec.RemoteCache.Azure.ContainerName,
},
},
}
} else if config.Spec.RemoteCache.GCS != nil {
req.Cache = &schemav1.Cache{
CacheType: &schemav1.Cache_GcsCache{
GcsCache: &schemav1.GCSCache{
BucketName: config.Spec.RemoteCache.GCS.BucketName,
Region: config.Spec.RemoteCache.GCS.Region,
ProjectId: config.Spec.RemoteCache.GCS.ProjectId,
},
},
}
}

Expand Down

0 comments on commit c9f1290

Please sign in to comment.