From d51cc3ead261387365d5e3333f358b8a8db8cb85 Mon Sep 17 00:00:00 2001 From: Aris Boutselis Date: Sat, 6 May 2023 21:39:04 +0300 Subject: [PATCH] feat: add azureopenai backend (#62) * feat: add azureopenai backend Signed-off-by: Aris Boutselis * chore: update Helm chart and bump its version. Signed-off-by: Aris Boutselis --------- Signed-off-by: Aris Boutselis Co-authored-by: Aris Boutselis --- api/v1alpha1/k8sgpt_types.go | 8 ++++++-- chart/operator/Chart.yaml | 4 ++-- chart/operator/templates/k8sgpt-crd.yaml | 10 +++++++++- config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml | 8 ++++++++ pkg/resources/k8sgpt.go | 13 +++++++++++++ 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/api/v1alpha1/k8sgpt_types.go b/api/v1alpha1/k8sgpt_types.go index 31b33afa..927dbcaa 100644 --- a/api/v1alpha1/k8sgpt_types.go +++ b/api/v1alpha1/k8sgpt_types.go @@ -30,9 +30,13 @@ type SecretRef struct { // K8sGPTSpec defines the desired state of K8sGPT type K8sGPTSpec struct { - Backend string `json:"backend,omitempty"` - BaseUrl string `json:"baseUrl,omitempty"` + // +kubebuilder:default:=openai + // +kubebuilder:validation:Enum=openai;localai;azureopenai + Backend string `json:"backend,omitempty"` + BaseUrl string `json:"baseUrl,omitempty"` + // +kubebuilder:default:=gpt-3.5-turbo Model string `json:"model,omitempty"` + Engine string `json:"engine,omitempty"` Secret *SecretRef `json:"secret,omitempty"` Version string `json:"version,omitempty"` EnableAI bool `json:"enableAI,omitempty"` diff --git a/chart/operator/Chart.yaml b/chart/operator/Chart.yaml index e3a5b79c..0a22b939 100644 --- a/chart/operator/Chart.yaml +++ b/chart/operator/Chart.yaml @@ -26,9 +26,9 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.0.9 # x-release-please-version +version: 0.0.10 # x-release-please-version # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "0.0.9" # x-release-please-version +appVersion: "0.0.10" # x-release-please-version diff --git a/chart/operator/templates/k8sgpt-crd.yaml b/chart/operator/templates/k8sgpt-crd.yaml index 71da8ede..cdc3304f 100644 --- a/chart/operator/templates/k8sgpt-crd.yaml +++ b/chart/operator/templates/k8sgpt-crd.yaml @@ -36,12 +36,20 @@ spec: description: K8sGPTSpec defines the desired state of K8sGPT properties: backend: + default: openai + enum: + - openai + - localai + - azureopenai type: string baseUrl: type: string enableAI: type: boolean + engine: + type: string model: + default: gpt-3.5-turbo type: string noCache: type: boolean @@ -68,4 +76,4 @@ status: kind: "" plural: "" conditions: [] - storedVersions: [] \ No newline at end of file + storedVersions: [] diff --git a/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml b/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml index 63ea12ae..be105be5 100644 --- a/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml +++ b/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml @@ -36,12 +36,20 @@ spec: description: K8sGPTSpec defines the desired state of K8sGPT properties: backend: + default: openai + enum: + - openai + - localai + - azureopenai type: string baseUrl: type: string enableAI: type: boolean + engine: + type: string model: + default: gpt-3.5-turbo type: string noCache: type: boolean diff --git a/pkg/resources/k8sgpt.go b/pkg/resources/k8sgpt.go index 5e8f85a2..ec2a9945 100644 --- a/pkg/resources/k8sgpt.go +++ b/pkg/resources/k8sgpt.go @@ -16,6 +16,7 @@ package resources import ( "context" + err "errors" "github.com/k8sgpt-ai/k8sgpt-operator/api/v1alpha1" appsv1 "k8s.io/api/apps/v1" @@ -232,6 +233,18 @@ func GetDeployment(config v1alpha1.K8sGPT) (*appsv1.Deployment, error) { deployment.Spec.Template.Spec.Containers[0].Env, baseUrl, ) } + // Engine is required only when azureopenai is the ai backend + if config.Spec.Engine != "" && config.Spec.Backend == "azureopenai" { + engine := v1.EnvVar{ + Name: "K8SGPT_ENGINE", + Value: config.Spec.Engine, + } + deployment.Spec.Template.Spec.Containers[0].Env = append( + deployment.Spec.Template.Spec.Containers[0].Env, engine, + ) + } else if config.Spec.Engine != "" && config.Spec.Backend != "azureopenai" { + return &appsv1.Deployment{}, err.New("Engine is supported only by azureopenai provider.") + } return &deployment, nil }