Skip to content

Commit

Permalink
add support for local-ai backend (#8)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>
  • Loading branch information
TylerGillson committed Apr 27, 2023
1 parent 057ba6b commit 45544f8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
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

0 comments on commit 45544f8

Please sign in to comment.