Skip to content

Commit

Permalink
feat: add proxysettings for azureopenai and openai
Browse files Browse the repository at this point in the history
Signed-off-by: tanujd11 <dwiveditanuj41@gmail.com>
  • Loading branch information
tanujd11 committed Apr 17, 2024
1 parent 9172165 commit 9e78c71
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
3 changes: 2 additions & 1 deletion api/v1alpha1/k8sgpt_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ type AISpec struct {
// +kubebuilder:default:=true
Anonymize *bool `json:"anonymized,omitempty"`
// +kubebuilder:default:=english
Language string `json:"language,omitempty"`
Language string `json:"language,omitempty"`
ProxyEndpoint string `json:"proxyEndpoint,omitempty"`
}

type Trivy struct {
Expand Down
2 changes: 2 additions & 0 deletions chart/operator/templates/k8sgpt-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ spec:
model:
default: gpt-3.5-turbo
type: string
proxyEndpoint:
type: string
region:
type: string
secret:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ spec:
model:
default: gpt-3.5-turbo
type: string
proxyEndpoint:
type: string
region:
type: string
secret:
Expand Down
34 changes: 24 additions & 10 deletions pkg/resources/k8sgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/k8sgpt-ai/k8sgpt-operator/pkg/utils"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
r1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -52,11 +51,11 @@ func addSecretAsEnvToDeployment(secretName string, secretKey string,
if er != nil {
return err.New("secret does not exist, cannot add to env of deployment")
}
envVar := v1.EnvVar{
envVar := corev1.EnvVar{
Name: secretKey,
ValueFrom: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: secretName,
},
Key: secretKey,
Expand Down Expand Up @@ -316,7 +315,7 @@ func GetDeployment(config v1alpha1.K8sGPT, outOfClusterMode bool, c client.Clien
})
deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, corev1.Volume{
Name: "kubeconfig",
VolumeSource: v1.VolumeSource{
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: config.Spec.Kubeconfig.Name,
Items: []corev1.KeyToPath{
Expand Down Expand Up @@ -350,11 +349,11 @@ func GetDeployment(config v1alpha1.K8sGPT, outOfClusterMode bool, c client.Clien

// check to see if key/value exists
addRemoteCacheEnvVar := func(name, key string) {
envVar := v1.EnvVar{
envVar := corev1.EnvVar{
Name: name,
ValueFrom: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: config.Spec.RemoteCache.Credentials.Name,
},
Key: key,
Expand Down Expand Up @@ -396,6 +395,21 @@ func GetDeployment(config v1alpha1.K8sGPT, outOfClusterMode bool, c client.Clien
} else if config.Spec.AI.Engine != "" && config.Spec.AI.Backend != v1alpha1.AzureOpenAI {
return &appsv1.Deployment{}, err.New("engine is supported only by azureopenai provider")
}

// ProxyEndpoint is required only when azureopenai or openai is the ai backend
if config.Spec.AI.ProxyEndpoint != "" && (config.Spec.AI.Backend == v1alpha1.AzureOpenAI || config.Spec.AI.Backend == v1alpha1.OpenAI) {
proxyEndpoint := corev1.EnvVar{
Name: "K8SGPT_PROXY_ENDPOINT",
Value: config.Spec.AI.ProxyEndpoint,
}
deployment.Spec.Template.Spec.Containers[0].Env = append(
deployment.Spec.Template.Spec.Containers[0].Env, proxyEndpoint,
)
} else if config.Spec.AI.ProxyEndpoint != "" && config.Spec.AI.Backend != v1alpha1.AzureOpenAI && config.Spec.AI.Backend != v1alpha1.OpenAI {
return &appsv1.Deployment{}, err.New("proxyEndpoint is supported only by azureopenai and openai provider")

}

// Add checks for amazonbedrock
if config.Spec.AI.Backend == v1alpha1.AmazonBedrock {
if config.Spec.AI.Secret == nil {
Expand Down

0 comments on commit 9e78c71

Please sign in to comment.