Skip to content

Commit

Permalink
PostgreSQL integration
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuchalla authored and syedriko committed Sep 18, 2024
1 parent 2180aab commit fb3d7a9
Show file tree
Hide file tree
Showing 25 changed files with 1,761 additions and 330 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@ build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/main.go

LIGHTSPEED_SERVICE_IMG ?= quay.io/openshift-lightspeed/lightspeed-service-api:latest
LIGHTSPEED_SERVICE_POSTGRES_IMG ?= registry.redhat.io/rhel9/postgresql-16@sha256:0d52a138698bf42dbbf5b9e4f35f4925b6155eef9f447e436c6db1a7ae304239
CONSOLE_PLUGIN_IMG ?= quay.io/openshift-lightspeed/lightspeed-console-plugin:latest
.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
#TODO: Update DB
go run ./cmd/main.go --service-image="$(LIGHTSPEED_SERVICE_IMG)" --console-image="$(CONSOLE_PLUGIN_IMG)"
go run ./cmd/main.go --service-image="$(LIGHTSPEED_SERVICE_IMG)" --postgres-image="$(LIGHTSPEED_SERVICE_POSTGRES_IMG)" --console-image="$(CONSOLE_PLUGIN_IMG)"

# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
Expand Down
38 changes: 26 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ spec:
url: "https://myendpoint.openai.azure.com/"
ols:
conversationCache:
redis:
maxMemory: 2000mb
maxMemoryPolicy: allkeys-lru
type: redis
postgres:
sharedBuffers: 256MB
maxConnections: 2000
type: postgres
defaultModel: gpt-3.5-turbo
defaultProvider: openai
logLevel: INFO
Expand Down Expand Up @@ -187,22 +187,25 @@ openshift-service-ca.crt 1 33m
➜ oc get services -n openshift-lightspeed
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
lightspeed-app-server ClusterIP 172.31.165.151 <none> 8443/TCP 22m
lightspeed-console-plugin ClusterIP 172.31.158.29 <none> 9443/TCP 29m
lightspeed-operator-controller-manager-service ClusterIP 172.31.63.140 <none> 8443/TCP 24m
lightspeed-app-server ClusterIP 172.30.176.179 <none> 8080/TCP 4m47s
lightspeed-postgres-server ClusterIP 172.30.85.42 <none> 6379/TCP 4m47s
lightspeed-operator-controller-manager-metrics-service ClusterIP 172.30.35.253 <none> 8443/TCP 4m47s
lightspeed-console-plugin ClusterIP 172.31.158.29 <none> 9443/TCP 29m
lightspeed-operator-controller-manager-service ClusterIP 172.31.63.140 <none> 8443/TCP 24m
➜ oc get deployments -n openshift-lightspeed
NAME READY UP-TO-DATE AVAILABLE AGE
lightspeed-app-server 1/1 1 1 23m
lightspeed-app-server 1/1 1 1 7m5s
lightspeed-postgres-server 1/1 1 1 7m5s
lightspeed-operator-controller-manager 1/1 1 1 2d15h
lightspeed-console-plugin 2/2 2 2 30m
lightspeed-operator-controller-manager 1/1 1 1 25m
➜ oc get pods -n openshift-lightspeed
NAME READY STATUS RESTARTS AGE
lightspeed-operator-controller-manager-7c849865ff-9vwj9 2/2 Running 0 7m19s
lightspeed-postgres-server-7b75497676-np7zk 1/1 Running 0 6m47s
lightspeed-app-server-97c9c6d96-6tv6j 2/2 Running 0 23m
lilightspeed-console-plugin-7f6cd7c9fd-6lp7x 1/1 Running 0 30m
lightspeed-console-plugin-7f6cd7c9fd-wctj8 1/1 Running 0 30m
lightspeed-operator-controller-manager-69585cc7fc-xltpc 1/1 Running 0 26m
➜ oc logs lightspeed-app-server-f7fd6cf6-k7s7p -n openshift-lightspeed
2024-02-02 12:00:06,982 [ols.app.main:main.py:29] INFO: Embedded Gradio UI is disabled. To enable set enable_dev_ui: true in the dev section of the configuration file
Expand All @@ -212,6 +215,17 @@ INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)
```

#### Postgres Secret Management
By default postgres server spins up with a randomly generated password located in the secret `lightspeed-postgres-secret`. One can go edit password their password to a desired value to get it reflected across the system. In addition to that postgres secret name can also be explicitly specified in cluster CR as shown in the below example.
```
conversationCache:
postgres:
sharedBuffers: "256MB"
maxConnections: 2000
credentialsSecret: xyz
type: postgres
```
### Modifying the API definitions
If you have updated the API definitions, you must update the CRD manifests with the following command
Expand Down Expand Up @@ -255,7 +269,7 @@ When using Visual Studio Code, we can use the debugger settings below to execute

### End to End tests

To run the end to end tests with a Openshift cluster, we need to have a running operator in the namespace `openshift-lightspeed`.
To run the end to end tests with a OpenShift cluster, we need to have a running operator in the namespace `openshift-lightspeed`.
Please refer to the section [Running on the cluster](#running-on-the-cluster).
Then we should set 2 environment variables:

Expand Down
41 changes: 21 additions & 20 deletions api/v1alpha1/olsconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package v1alpha1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand Down Expand Up @@ -123,39 +122,41 @@ type ConsoleContainerConfig struct {
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
}

// +kubebuilder:validation:Enum=redis
// +kubebuilder:validation:Enum=postgres
type CacheType string

const (
Redis CacheType = "redis"
Postgres CacheType = "postgres"
)

// ConversationCacheSpec defines the desired state of OLS conversation cache.
type ConversationCacheSpec struct {
// Conversation cache type. Default: "redis"
// +kubebuilder:default=redis
// Conversation cache type. Default: "postgres"
// +kubebuilder:default=postgres
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Cache Type"
Type CacheType `json:"type,omitempty"`
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Redis"
Redis RedisSpec `json:"redis,omitempty"`
Postgres PostgresSpec `json:"postgres,omitempty"`
}

// RedisSpec defines the desired state of Redis.
type RedisSpec struct {
// Secret that holds redis credentials
// +kubebuilder:default="lightspeed-redis-secret"
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Credentials secret"
// PostgresSpec defines the desired state of Postgres.
type PostgresSpec struct {
// Postgres user name
// +kubebuilder:default="postgres"
User string `json:"user,omitempty"`
// Postgres database name
// +kubebuilder:default="postgres"
DbName string `json:"dbName,omitempty"`
// Secret that holds postgres credentials
// +kubebuilder:default="lightspeed-postgres-secret"
CredentialsSecret string `json:"credentialsSecret,omitempty"`
// Redis maxmemory
// Postgres sharedbuffers
// +kubebuilder:validation:XIntOrString
// +kubebuilder:default="1024mb"
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Max Memory"
MaxMemory *intstr.IntOrString `json:"maxMemory,omitempty"`
// Redis maxmemory policy. Default: "allkeys-lru"
// +kubebuilder:default=allkeys-lru
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Max Memory Policy"
MaxMemoryPolicy string `json:"maxMemoryPolicy,omitempty"`
// +kubebuilder:default="256MB"
SharedBuffers string `json:"sharedBuffers,omitempty"`
// Postgres maxconnections. Default: "2000"
// +kubebuilder:default=2000
MaxConnections int `json:"maxConnections,omitempty"`
}

// QueryFiltersSpec defines filters to manipulate questions/queries.
Expand Down
40 changes: 17 additions & 23 deletions api/v1alpha1/zz_generated.deepcopy.go

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

31 changes: 20 additions & 11 deletions bundle/manifests/lightspeed-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,27 @@ spec:
path: llm.providers[0].type
- displayName: OLS Settings
path: ols
- displayName: Redis
path: ols.conversationCache.redis
- description: Secret that holds redis credentials
- displayName: Postgres
path: ols.conversationCache.postgres
- description: Secret that holds Postgres credentials
displayName: Credentials secret
path: ols.conversationCache.redis.credentialsSecret
- description: Redis maxmemory
displayName: Max Memory
path: ols.conversationCache.redis.maxMemory
- description: 'Redis maxmemory policy. Default: "allkeys-lru"'
displayName: Max Memory Policy
path: ols.conversationCache.redis.maxMemoryPolicy
- description: 'Conversation cache type. Default: "redis"'
path: ols.conversationCache.postgres.credentialsSecret
- description: Postgres database name
displayName: Database name
path: ols.conversationCache.postgres.dbName
- description: Postgres max connections
displayName: Max connections
path: ols.conversationCache.postgres.maxConnections
- description: Postgres max connections
displayName: Max connections
path: ols.conversationCache.postgres.maxConnections
- description: Postgres shared buffers
displayName: Shared buffers
path: ols.conversationCache.postgres.sharedBuffers
- description: Postgres user name
displayName: User name
path: ols.conversationCache.postgres.user
- description: 'Conversation cache type. Default: "postgres"'
displayName: Cache Type
path: ols.conversationCache.type
- description: Default model for usage
Expand Down
38 changes: 22 additions & 16 deletions bundle/manifests/ols.openshift.io_olsconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,30 +133,36 @@ spec:
conversationCache:
description: Conversation cache settings
properties:
redis:
description: RedisSpec defines the desired state of Redis.
postgres:
description: PostgresSpec defines the desired state of Postgres.
properties:
credentialsSecret:
default: lightspeed-redis-secret
description: Secret that holds redis credentials
default: lightspeed-postgres-secret
description: Secret that holds postgres credentials
type: string
dbName:
default: postgres
description: Postgres database name
type: string
maxConnections:
default: 2000
description: 'Postgres maxconnections. Default: "2000"'
type: integer
sharedBuffers:
default: 256MB
description: Postgres sharedbuffers
type: string
maxMemory:
anyOf:
- type: integer
- type: string
default: 1024mb
description: Redis maxmemory
x-kubernetes-int-or-string: true
maxMemoryPolicy:
default: allkeys-lru
description: 'Redis maxmemory policy. Default: "allkeys-lru"'
user:
default: postgres
description: Postgres user name
type: string
type: object
type:
default: redis
description: 'Conversation cache type. Default: "redis"'
default: postgres
description: 'Conversation cache type. Default: "postgres"'
enum:
- redis
- postgres
type: string
type: object
defaultModel:
Expand Down
Loading

0 comments on commit fb3d7a9

Please sign in to comment.