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 additional printer columns to Result CR #114

Merged
merged 6 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 9 additions & 1 deletion api/v1alpha1/k8sgpt_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type SecretRef struct {
type K8sGPTSpec struct {
// +kubebuilder:default:=openai
// +kubebuilder:validation:Enum=openai;localai;azureopenai
Backend string `json:"backend,omitempty"`
Backend `json:"backend"`
BaseUrl string `json:"baseUrl,omitempty"`
// +kubebuilder:default:=gpt-3.5-turbo
Model string `json:"model,omitempty"`
Expand All @@ -44,6 +44,14 @@ type K8sGPTSpec struct {
Filters []string `json:"filters,omitempty"`
}

type Backend string

const (
OpenAI Backend = "openai"
AzureOpenAI Backend = "azureopenai"
LocalAI Backend = "localai"
)

// K8sGPTStatus defines the observed state of K8sGPT
type K8sGPTStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand Down
30 changes: 14 additions & 16 deletions api/v1alpha1/k8sgpt_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,46 @@ var _ = Describe("The test cases for the K8sGPT CRDs", func() {
Key: "k8s-gpt",
}

Kind = "K8sGPT"
Backend = "gpt"
Backend2 = "gpt-2"
BaseUrl = "https://api.k8s-gpt.localhost"
Model = "345M"
Version = "v1alpha1"
kind = "K8sGPT"
baseUrl = "https://api.k8s-gpt.localhost"
model = "345M"
version = "v1alpha1"

Namespace = "k8sGPT"

k8sGPT = K8sGPT{
TypeMeta: metav1.TypeMeta{
Kind: Kind,
Kind: kind,
},
ObjectMeta: metav1.ObjectMeta{
Name: "k8s-gpt",
Namespace: Namespace,
},
Spec: K8sGPTSpec{
Backend: Backend,
BaseUrl: BaseUrl,
Model: Model,
Backend: OpenAI,
BaseUrl: baseUrl,
Model: model,
Secret: &secretRef,
Version: Version,
Version: version,
EnableAI: true,
NoCache: true,
},
}

k8sGPT2 = K8sGPT{
TypeMeta: metav1.TypeMeta{
Kind: Kind,
Kind: kind,
},
ObjectMeta: metav1.ObjectMeta{
Name: "k8s-gpt-2",
Namespace: Namespace,
},
Spec: K8sGPTSpec{
Backend: Backend2,
BaseUrl: BaseUrl,
Model: Model,
Backend: AzureOpenAI,
BaseUrl: baseUrl,
Model: model,
Secret: &secretRef,
Version: Version,
Version: version,
EnableAI: false,
NoCache: false,
},
Expand Down
5 changes: 3 additions & 2 deletions api/v1alpha1/result_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ type Sensitive struct {

// ResultSpec defines the desired state of Result
type ResultSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
Backend `json:"backend"`
Kind string `json:"kind"`
Name string `json:"name"`
Error []Failure `json:"error"`
Expand All @@ -49,6 +48,8 @@ type ResultStatus struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Kind",type="string",JSONPath=".spec.kind",description="Kind"
//+kubebuilder:printcolumn:name="Backend",type="string",JSONPath=".spec.backend",description="Backend"

// Result is the Schema for the results API
type Result struct {
Expand Down
17 changes: 17 additions & 0 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 @@ -66,6 +66,8 @@ spec:
type: object
version:
type: string
required:
- backend
type: object
status:
description: K8sGPTStatus defines the observed state of K8sGPT
Expand Down
16 changes: 13 additions & 3 deletions config/crd/bases/core.k8sgpt.ai_results.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ spec:
singular: result
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- description: Kind
jsonPath: .spec.kind
name: Kind
type: string
- description: Backend
jsonPath: .spec.backend
name: Backend
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: Result is the Schema for the results API
Expand All @@ -35,6 +44,8 @@ spec:
spec:
description: ResultSpec defines the desired state of Result
properties:
backend:
type: string
details:
type: string
error:
Expand All @@ -54,14 +65,13 @@ spec:
type: object
type: array
kind:
description: 'INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
Important: Run "make" to regenerate code after modifying this file'
type: string
name:
type: string
parentObject:
type: string
required:
- backend
- details
- error
- kind
Expand Down
14 changes: 14 additions & 0 deletions config/samples/k8sgpt_localai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: core.k8sgpt.ai/v1alpha1
kind: K8sGPT
metadata:
name: k8sgpt-sample-localai
namespace: k8sgpt-operator-system
spec:
model: ggml-gpt4all-j-v1.3-groovy.bin
backend: localai
baseUrl: http://local-ai.local-ai.svc.cluster.local:8080/v1
noCache: false
enableAI: true
version: v0.3.0
# if not specified, k8s will marshal as a zero-valued SecretRef, which causes errors
secret: null
TylerGillson marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions controllers/k8sgpt_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ func (r *K8sGPTReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
k8sgptNumberOfResults.Set(float64(len(response.Results)))
rawResults := make(map[string]corev1alpha1.Result)
for _, resultSpec := range response.Results {
// FIXME: remove this once backend is populated in the k8sgpt response
if resultSpec.Backend == "" {
TylerGillson marked this conversation as resolved.
Show resolved Hide resolved
resultSpec.Backend = k8sgptConfig.Spec.Backend
}
name := strings.ReplaceAll(resultSpec.Name, "-", "")
name = strings.ReplaceAll(name, "/", "")
result := corev1alpha1.Result{
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *Client) ProcessAnalysis(deployment v1.Deployment, config *v1alpha1.K8sG
req := &schemav1.AnalyzeRequest{
Explain: config.Spec.EnableAI,
Nocache: config.Spec.NoCache,
Backend: config.Spec.Backend,
Backend: string(config.Spec.Backend),
Filters: config.Spec.Filters,
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/resources/k8sgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func GetDeployment(config v1alpha1.K8sGPT) (*appsv1.Deployment, error) {
},
{
Name: "K8SGPT_BACKEND",
Value: config.Spec.Backend,
Value: string(config.Spec.Backend),
},
},
Ports: []v1.ContainerPort{
Expand Down Expand Up @@ -235,15 +235,15 @@ func GetDeployment(config v1alpha1.K8sGPT) (*appsv1.Deployment, error) {
)
}
// Engine is required only when azureopenai is the ai backend
if config.Spec.Engine != "" && config.Spec.Backend == "azureopenai" {
if config.Spec.Engine != "" && config.Spec.Backend == v1alpha1.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" {
} else if config.Spec.Engine != "" && config.Spec.Backend != v1alpha1.AzureOpenAI {
return &appsv1.Deployment{}, err.New("Engine is supported only by azureopenai provider.")
}
return &deployment, nil
Expand Down