Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add proxysettings for azureopenai and openai #415

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -80,6 +80,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"
arbreezy marked this conversation as resolved.
Show resolved Hide resolved
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