Skip to content

Commit

Permalink
feat: add azureopenai backend (#62)
Browse files Browse the repository at this point in the history
* feat: add azureopenai backend

Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com>

* chore: update Helm chart and bump its version.

Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com>

---------

Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com>
Co-authored-by: Aris Boutselis <arisboutselis08@gmail.com>
  • Loading branch information
Aris Boutselis and arbreezy committed May 6, 2023
1 parent 59583eb commit d51cc3e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
8 changes: 6 additions & 2 deletions api/v1alpha1/k8sgpt_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions chart/operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion chart/operator/templates/k8sgpt-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -68,4 +76,4 @@ status:
kind: ""
plural: ""
conditions: []
storedVersions: []
storedVersions: []
8 changes: 8 additions & 0 deletions config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions pkg/resources/k8sgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package resources

import (
"context"
err "errors"

"github.com/k8sgpt-ai/k8sgpt-operator/api/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit d51cc3e

Please sign in to comment.