From 8f39c5168edcc31cbfe6bc22bc6da4e7ad410713 Mon Sep 17 00:00:00 2001 From: Shahrooz Aghili Date: Mon, 30 Sep 2024 12:30:13 +0200 Subject: [PATCH] feat: add minio cache #464 Signed-off-by: Shahrooz Aghili --- README.md | 41 ++++++++++++++++++++ api/v1alpha1/k8sgpt_types.go | 3 ++ config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml | 5 +++ pkg/client/config.go | 2 + pkg/resources/k8sgpt.go | 19 +++++---- 5 files changed, 60 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 53833005..13c88663 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,47 @@ EOF +
+ +Minio + +1. Install the operator from the [Installation](#installation) section. + +2. Create secret: +```sh +kubectl create secret generic k8sgpt-sample-cache-secret --from-literal=minio_access_key= --from-literal=minio_secret_key= -n k8sgpt-operator-system +``` + +3. Apply the K8sGPT configuration object: +``` +kubectl apply -f - << EOF +apiVersion: core.k8sgpt.ai/v1alpha1 +kind: K8sGPT +metadata: + name: k8sgpt-sample + namespace: k8sgpt-operator-system +spec: + ai: + enabled: true + secret: + name: bedrock-sample-secret + model: anthropic.claude-v2 + region: eu-central-1 + backend: amazonbedrock + noCache: false + version: v0.3.41 + remoteCache: + credentials: + name: k8sgpt-sample-cache-secret + s3: + bucketName: k8sgpt-cache-123456789 + endpoint: http://minio.k8sgpt-operator-system.svc.cluster.local:9000 + insecure: true +EOF +``` + +
+ ## Other AI Backend Examples diff --git a/api/v1alpha1/k8sgpt_types.go b/api/v1alpha1/k8sgpt_types.go index d531e181..ad59c3f0 100644 --- a/api/v1alpha1/k8sgpt_types.go +++ b/api/v1alpha1/k8sgpt_types.go @@ -50,6 +50,9 @@ type RemoteCacheRef struct { type S3Backend struct { BucketName string `json:"bucketName,omitempty"` Region string `json:"region,omitempty"` + Endpoint string `json:"endpoint,omitempty"` + // +kubebuilder:default:=false + Insecure bool `json:"insecure,omitempty"` } type AzureBackend struct { diff --git a/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml b/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml index bece81c5..ec940201 100644 --- a/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml +++ b/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml @@ -183,6 +183,11 @@ spec: properties: bucketName: type: string + endpoint: + type: string + insecure: + default: false + type: boolean region: type: string type: object diff --git a/pkg/client/config.go b/pkg/client/config.go index 3a6b8363..3dea229f 100644 --- a/pkg/client/config.go +++ b/pkg/client/config.go @@ -22,6 +22,8 @@ func (c *Client) AddConfig(config *v1alpha1.K8sGPT) error { S3Cache: &schemav1.S3Cache{ BucketName: config.Spec.RemoteCache.S3.BucketName, Region: config.Spec.RemoteCache.S3.Region, + Endpoint: config.Spec.RemoteCache.S3.Endpoint, + Insecure: config.Spec.RemoteCache.S3.Insecure, }, }, } diff --git a/pkg/resources/k8sgpt.go b/pkg/resources/k8sgpt.go index 6075b1b0..a6e0dc2d 100644 --- a/pkg/resources/k8sgpt.go +++ b/pkg/resources/k8sgpt.go @@ -266,8 +266,15 @@ func GetDeployment(config v1alpha1.K8sGPT, outOfClusterMode bool, c client.Clien addRemoteCacheEnvVar("AZURE_TENANT_ID", "azure_tenant_id") addRemoteCacheEnvVar("AZURE_CLIENT_SECRET", "azure_client_secret") } else if config.Spec.RemoteCache.S3 != nil { - addRemoteCacheEnvVar("AWS_ACCESS_KEY_ID", "aws_access_key_id") - addRemoteCacheEnvVar("AWS_SECRET_ACCESS_KEY", "aws_secret_access_key") + if config.Spec.RemoteCache.S3.Endpoint != "" { + // MinIO + addRemoteCacheEnvVar("MINIO_ACCESS_KEY", "minio_access_key") + addRemoteCacheEnvVar("MINIO_SECRET_KEY", "minio_secret_key") + } else { + // AWS S3 + addRemoteCacheEnvVar("AWS_ACCESS_KEY_ID", "aws_access_key_id") + addRemoteCacheEnvVar("AWS_SECRET_ACCESS_KEY", "aws_secret_access_key") + } } } @@ -327,14 +334,6 @@ func GetDeployment(config v1alpha1.K8sGPT, outOfClusterMode bool, c client.Clien }, ) } - // Add checks for ibmwatsonxai - if config.Spec.AI.Backend == v1alpha1.IBMWatsonxAI { - if config.Spec.AI.Secret != nil { - if err := addSecretAsEnvToDeployment(config.Spec.AI.Secret.Name, "K8SGPT_PROVIDER_ID", config, c, &deployment); err != nil { - return &appsv1.Deployment{}, err - } - } - } return &deployment, nil }