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 support for local-ai backend #8

Merged
merged 2 commits into from
Apr 27, 2023
Merged
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
15 changes: 8 additions & 7 deletions api/v1alpha1/k8sgpt_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ type SecretRef struct {

// K8sGPTSpec defines the desired state of K8sGPT
type K8sGPTSpec struct {
Backend string `json:"backend,omitempty"`
Model string `json:"model,omitempty"`
Secret SecretRef `json:"secret,omitempty"`
Namespace string `json:"namespace,omitempty"`
Version string `json:"version,omitempty"`
EnableAI bool `json:"enableAI,omitempty"`
NoCache bool `json:"noCache,omitempty"`
Backend string `json:"backend,omitempty"`
BaseUrl string `json:"baseUrl,omitempty"`
Model string `json:"model,omitempty"`
Secret *SecretRef `json:"secret,omitempty"`
Namespace string `json:"namespace,omitempty"`
Version string `json:"version,omitempty"`
EnableAI bool `json:"enableAI,omitempty"`
NoCache bool `json:"noCache,omitempty"`
}

// K8sGPTStatus defines the observed state of K8sGPT
Expand Down
8 changes: 6 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -37,6 +37,8 @@ spec:
properties:
backend:
type: string
baseUrl:
type: string
enableAI:
type: boolean
model:
Expand Down
36 changes: 25 additions & 11 deletions pkg/resources/k8sgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,6 @@ func GetDeployment(config v1alpha1.K8sGPT) (*appsv1.Deployment, error) {
"serve",
},
Env: []v1.EnvVar{
{
Name: "K8SGPT_PASSWORD",
ValueFrom: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: config.Spec.Secret.Name,
},
Key: config.Spec.Secret.Key,
},
},
},
{
Name: "K8SGPT_MODEL",
Value: config.Spec.Model,
Expand Down Expand Up @@ -218,6 +207,31 @@ func GetDeployment(config v1alpha1.K8sGPT) (*appsv1.Deployment, error) {
},
},
}
if config.Spec.Secret != nil {
password := v1.EnvVar{
Name: "K8SGPT_PASSWORD",
ValueFrom: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: config.Spec.Secret.Name,
},
Key: config.Spec.Secret.Key,
},
},
}
deployment.Spec.Template.Spec.Containers[0].Env = append(
deployment.Spec.Template.Spec.Containers[0].Env, password,
)
}
if config.Spec.BaseUrl != "" {
baseUrl := v1.EnvVar{
Name: "K8SGPT_BASEURL",
Value: config.Spec.BaseUrl,
}
deployment.Spec.Template.Spec.Containers[0].Env = append(
deployment.Spec.Template.Spec.Containers[0].Env, baseUrl,
)
}
return &deployment, nil
}

Expand Down