From b8eda45ff032d75a3a19b55591782aa5d758bbb3 Mon Sep 17 00:00:00 2001 From: Apoorva Appadoo Srinivas Date: Sun, 20 Oct 2024 11:22:52 +0200 Subject: [PATCH] refactor: pass ollama url in env --- api/v1/model_types.go | 1 - config/crd/bases/ollama.ollama.startupnation_models.yaml | 3 --- internal/controller/model_controller.go | 9 ++++++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/api/v1/model_types.go b/api/v1/model_types.go index b8e2c59..fba2f69 100644 --- a/api/v1/model_types.go +++ b/api/v1/model_types.go @@ -28,7 +28,6 @@ type ModelSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file - OllamaUrl string `json:"ollamaUrl"` ModelName string `json:"modelName"` } diff --git a/config/crd/bases/ollama.ollama.startupnation_models.yaml b/config/crd/bases/ollama.ollama.startupnation_models.yaml index 3254b38..37e55b1 100644 --- a/config/crd/bases/ollama.ollama.startupnation_models.yaml +++ b/config/crd/bases/ollama.ollama.startupnation_models.yaml @@ -41,11 +41,8 @@ spec: properties: modelName: type: string - ollamaUrl: - type: string required: - modelName - - ollamaUrl type: object status: description: ModelStatus defines the observed state of Model diff --git a/internal/controller/model_controller.go b/internal/controller/model_controller.go index b8e3d49..2e99537 100644 --- a/internal/controller/model_controller.go +++ b/internal/controller/model_controller.go @@ -25,6 +25,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log" ollamav1 "github.com/StartUpNationLabs/simple-ollama-operator/api/v1" + "os" ) // ModelReconciler reconciles a Model object @@ -56,9 +57,15 @@ func (r *ModelReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl logger.Error(err, "unable to fetch Model") return ctrl.Result{}, client.IgnoreNotFound(err) } + // Read url from the Model instance + modelUrl := os.Getenv("OLLAMA_URL") + if modelUrl == "" { + logger.Error(err, "unable to fetch Ollama URL") + panic("OLLAMA_URL not set") + } // create a new Ollama Client - ollamaClient, err := ollama_client.NewClientWithResponses(model.Spec.OllamaUrl) + ollamaClient, err := ollama_client.NewClientWithResponses(modelUrl) if err != nil { logger.Error(err, "unable to create Ollama Client") return ctrl.Result{}, err