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: refactor the ai spec #159

Merged
merged 4 commits into from
Jun 19, 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
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ helm install release k8sgpt/k8sgpt-operator -n k8sgpt-operator-system --create-n

2. Create secret:
```sh
kubectl create secret generic k8sgpt-sample-secret --from-literal=openai-api-key=$OPENAI_TOKEN -n k8sgpt-
operator-system
kubectl create secret generic k8sgpt-sample-secret --from-literal=openai-api-key=$OPENAI_TOKEN -n k8sgpt-operator-system
```

3. Apply the K8sGPT configuration object:
Expand All @@ -37,11 +36,15 @@ metadata:
name: k8sgpt-sample
namespace: k8sgpt-operator-system
spec:
model: gpt-3.5-turbo
backend: openai
ai:
enabled: true
model: gpt-3.5-turbo
backend: openai
secret:
name: k8sgpt-sample-secret
key: openai-api-key
noCache: false
version: v0.3.0
enableAI: true
# filters:
# - Ingress
# sink:
Expand All @@ -50,9 +53,6 @@ spec:
# extraOptions:
# backstage:
# enabled: true
secret:
name: k8sgpt-sample-secret
key: openai-api-key
EOF
```

Expand Down Expand Up @@ -81,8 +81,7 @@ you will be able to see the Results objects of the analysis after some minutes (

2. Create secret:
```sh
kubectl create secret generic k8sgpt-sample-secret --from-literal=azure-api-key=$AZURE_TOKEN -n k8sgpt-
operator-system
kubectl create secret generic k8sgpt-sample-secret --from-literal=azure-api-key=$AZURE_TOKEN -n k8sgpt-operator-system
```

3. Apply the K8sGPT configuration object:
Expand All @@ -94,16 +93,17 @@ metadata:
name: k8sgpt-sample
namespace: k8sgpt-operator-system
spec:
model: gpt-35-turbo
backend: azureopenai
baseUrl: https://k8sgpt.openai.azure.com/
engine: llm
ai:
enabled: true
secret:
name: k8sgpt-sample-secret
key: azure-api-key
model: gpt-35-turbo
backend: azureopenai
baseUrl: https://k8sgpt.openai.azure.com/
engine: llm
noCache: false
version: v0.3.2
enableAI: true
secret:
name: k8sgpt-sample-secret
key: azure-api-key
EOF
```

Expand All @@ -127,12 +127,13 @@ metadata:
name: k8sgpt-local-ai
namespace: default
spec:
model: ggml-gpt4all-j
backend: localai
baseUrl: http://local-ai.local-ai.svc.cluster.local:8080/v1
ai:
enabled: true
model: ggml-gpt4all-j
backend: localai
baseUrl: http://local-ai.local-ai.svc.cluster.local:8080/v1
noCache: false
version: v0.3.4
enableAI: true
EOF
```
Note: ensure that the value of `baseUrl` is a properly constructed [DNS name](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#services) for the LocalAI Service. It should take the form: `http://local-ai.<namespace_local_ai_was_installed_in>.svc.cluster.local:8080/v1`.
Expand Down
16 changes: 10 additions & 6 deletions api/v1alpha1/k8sgpt_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,26 @@ type WebhookRef struct {
Endpoint string `json:"webhook,omitempty"`
}

// K8sGPTSpec defines the desired state of K8sGPT
type K8sGPTSpec struct {
type AISpec struct {
// +kubebuilder:default:=openai
// +kubebuilder:validation:Enum=openai;localai;azureopenai
Backend string `json:"backend"`
BaseUrl string `json:"baseUrl,omitempty"`
// +kubebuilder:default:=gpt-3.5-turbo
Model string `json:"model,omitempty"`
Engine string `json:"engine,omitempty"`
Secret *SecretRef `json:"secret,omitempty"`
Model string `json:"model,omitempty"`
Engine string `json:"engine,omitempty"`
Secret *SecretRef `json:"secret,omitempty"`
Enabled bool `json:"enabled,omitempty"`
}

// K8sGPTSpec defines the desired state of K8sGPT
type K8sGPTSpec struct {
Version string `json:"version,omitempty"`
EnableAI bool `json:"enableAI,omitempty"`
NoCache bool `json:"noCache,omitempty"`
Filters []string `json:"filters,omitempty"`
ExtraOptions *ExtraOptionsRef `json:"extraOptions,omitempty"`
Sink *WebhookRef `json:"sink,omitempty"`
AI *AISpec `json:"ai,omitempty"`
}

const (
Expand Down
40 changes: 23 additions & 17 deletions api/v1alpha1/k8sgpt_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ var _ = Describe("The test cases for the K8sGPT CRDs", func() {
Namespace: Namespace,
},
Spec: K8sGPTSpec{
Backend: OpenAI,
BaseUrl: baseUrl,
Model: model,
Secret: &secretRef,
Version: version,
EnableAI: true,
NoCache: true,
AI: &AISpec{
Backend: OpenAI,
BaseUrl: baseUrl,
Model: model,
Enabled: true,
Secret: &secretRef,
},
Version: version,

NoCache: true,
},
}

Expand All @@ -69,13 +72,16 @@ var _ = Describe("The test cases for the K8sGPT CRDs", func() {
Namespace: Namespace,
},
Spec: K8sGPTSpec{
Backend: AzureOpenAI,
BaseUrl: baseUrl,
Model: model,
Secret: &secretRef,
Version: version,
EnableAI: false,
NoCache: false,
AI: &AISpec{
Backend: OpenAI,
BaseUrl: baseUrl,
Model: model,
Secret: &secretRef,
Enabled: false,
},
Version: version,

NoCache: false,
},
}

Expand Down Expand Up @@ -107,7 +113,7 @@ var _ = Describe("The test cases for the K8sGPT CRDs", func() {
// Check the K8sGPT CRDs object's name and the APIVersion.
Expect(k8sGPTObject.Name).Should(Equal("k8s-gpt"))
Expect(k8sGPTObject.APIVersion).Should(Equal(GroupVersion.String()))
Expect(k8sGPTObject.Spec.EnableAI).Should(Equal(true))
Expect(k8sGPTObject.Spec.AI.Enabled).Should(Equal(true))

//get K8sGPT CRD by resource name
Expect(fakeClient.Get(ctx, types.NamespacedName{Name: "k8s-gpt-2", Namespace: Namespace}, &k8sGPTObject)).Should(Succeed())
Expand All @@ -132,10 +138,10 @@ var _ = Describe("The test cases for the K8sGPT CRDs", func() {
// Get the K8sGPT CRDs by the name and namespace.
Expect(fakeClient.Get(ctx, typeNamespace, &k8sGPTObject)).Should(Succeed())
// Update the K8sGPT CRDs.
k8sGPTObject.Spec.EnableAI = false
k8sGPTObject.Spec.AI.Enabled = false
Expect(fakeClient.Update(ctx, &k8sGPTObject)).Should(Succeed())
// check the K8sGPT CRDs should be equal to false
Expect(k8sGPTObject.Spec.EnableAI).Should(Equal(false))
Expect(k8sGPTObject.Spec.AI.Enabled).Should(Equal(false))
})

// Delete the K8sGPT CRDs.
Expand Down
30 changes: 25 additions & 5 deletions api/v1alpha1/zz_generated.deepcopy.go

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

57 changes: 31 additions & 26 deletions chart/operator/templates/k8sgpt-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,34 @@ spec:
spec:
description: K8sGPTSpec defines the desired state of K8sGPT
properties:
backend:
default: openai
enum:
- openai
- localai
- azureopenai
type: string
baseUrl:
type: string
enableAI:
type: boolean
engine:
type: string
ai:
properties:
backend:
default: openai
enum:
- openai
- localai
- azureopenai
type: string
baseUrl:
type: string
enabled:
type: boolean
engine:
type: string
model:
default: gpt-3.5-turbo
type: string
secret:
properties:
key:
type: string
name:
type: string
type: object
required:
- backend
type: object
extraOptions:
properties:
backstage:
Expand All @@ -56,22 +71,12 @@ spec:
type: boolean
type: object
type: object
model:
default: gpt-3.5-turbo
type: string
noCache:
type: boolean
filters:
items:
type: string
type: array
secret:
properties:
key:
type: string
name:
type: string
type: object
noCache:
type: boolean
sink:
properties:
type:
Expand All @@ -97,4 +102,4 @@ status:
kind: ""
plural: ""
conditions: []
storedVersions: []
storedVersions: []
18 changes: 14 additions & 4 deletions chart/operator/templates/result-crd.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 All @@ -86,4 +96,4 @@ status:
kind: ""
plural: ""
conditions: []
storedVersions: []
storedVersions: []
Loading