|
| 1 | +/* |
| 2 | +Copyright 2025. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1beta1 |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/openstack-k8s-operators/lib-common/modules/common/condition" |
| 21 | + "github.com/openstack-k8s-operators/lib-common/modules/common/util" |
| 22 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 23 | +) |
| 24 | + |
| 25 | +const ( |
| 26 | + // Container image fall-back defaults |
| 27 | + |
| 28 | + // OpenStackLightspeedContainerImage is the fall-back container image for OpenStackLightspeed |
| 29 | + OpenStackLightspeedContainerImage = "quay.io/openstack-lightspeed/rag-content:os-docs-2024.2" |
| 30 | +) |
| 31 | + |
| 32 | +// OpenStackLightspeedSpec defines the desired state of OpenStackLightspeed |
| 33 | +type OpenStackLightspeedSpec struct { |
| 34 | + OpenStackLightspeedCore `json:",inline"` |
| 35 | + |
| 36 | + // +kubebuilder:validation:Optional |
| 37 | + // ContainerImage for the Openstack Lightspeed RAG container (will be set to environmental default if empty) |
| 38 | + RAGImage string `json:"ragImage"` |
| 39 | +} |
| 40 | + |
| 41 | +// OpenStackLightspeedCore defines the desired state of OpenStackLightspeed |
| 42 | +type OpenStackLightspeedCore struct { |
| 43 | + // +kubebuilder:validation:Required |
| 44 | + // URL pointing to the LLM |
| 45 | + LLMEndpoint string `json:"llmEndpoint"` |
| 46 | + |
| 47 | + // +kubebuilder:validation:Required |
| 48 | + // +kubebuilder:validation:Enum=azure_openai;bam;openai;watsonx;rhoai_vllm;rhelai_vllm;fake_provider |
| 49 | + // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Provider Type" |
| 50 | + // Type of the provider serving the LLM |
| 51 | + LLMEndpointType string `json:"llmEndpointType"` |
| 52 | + |
| 53 | + // +kubebuilder:validation:Required |
| 54 | + // Name of the model to use at the API endpoint provided in LLMEndpoint |
| 55 | + ModelName string `json:"modelName"` |
| 56 | + |
| 57 | + // +kubebuilder:validation:Required |
| 58 | + // Secret name containing API token for the LLMEndpoint. The key for the field |
| 59 | + // in the secret that holds the token should be "apitoken". |
| 60 | + LLMCredentials string `json:"llmCredentials"` |
| 61 | + |
| 62 | + // +kubebuilder:validation:Optional |
| 63 | + // Configmap name containing a CA Certificates bundle |
| 64 | + TLSCACertBundle string `json:"tlsCACertBundle"` |
| 65 | +} |
| 66 | + |
| 67 | +// OpenStackLightspeedStatus defines the observed state of OpenStackLightspeed |
| 68 | +type OpenStackLightspeedStatus struct { |
| 69 | + // Conditions |
| 70 | + Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"` |
| 71 | + |
| 72 | + // ObservedGeneration - the most recent generation observed for this object. |
| 73 | + ObservedGeneration int64 `json:"observedGeneration,omitempty"` |
| 74 | +} |
| 75 | + |
| 76 | +// +kubebuilder:object:root=true |
| 77 | +// +kubebuilder:subresource:status |
| 78 | +// +operator-sdk:csv:customresourcedefinitions:displayName="OpenStack Lightspeed" |
| 79 | +// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[0].status",description="Status" |
| 80 | +// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.conditions[0].message",description="Message" |
| 81 | + |
| 82 | +// OpenStackLightspeed is the Schema for the openstacklightspeeds API |
| 83 | +type OpenStackLightspeed struct { |
| 84 | + metav1.TypeMeta `json:",inline"` |
| 85 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 86 | + |
| 87 | + Spec OpenStackLightspeedSpec `json:"spec,omitempty"` |
| 88 | + Status OpenStackLightspeedStatus `json:"status,omitempty"` |
| 89 | +} |
| 90 | + |
| 91 | +//+kubebuilder:object:root=true |
| 92 | + |
| 93 | +// OpenStackLightspeedList contains a list of OpenStackLightspeed |
| 94 | +type OpenStackLightspeedList struct { |
| 95 | + metav1.TypeMeta `json:",inline"` |
| 96 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 97 | + Items []OpenStackLightspeed `json:"items"` |
| 98 | +} |
| 99 | + |
| 100 | +func init() { |
| 101 | + SchemeBuilder.Register(&OpenStackLightspeed{}, &OpenStackLightspeedList{}) |
| 102 | +} |
| 103 | + |
| 104 | +// IsReady - returns true if OpenStackLightspeed is reconciled successfully |
| 105 | +func (instance OpenStackLightspeed) IsReady() bool { |
| 106 | + return instance.Status.Conditions.IsTrue(OpenStackLightspeedReadyCondition) |
| 107 | +} |
| 108 | + |
| 109 | +type OpenStackLightspeedDefaults struct { |
| 110 | + RAGImageURL string |
| 111 | +} |
| 112 | + |
| 113 | +var OpenStackLightspeedDefaultValues OpenStackLightspeedDefaults |
| 114 | + |
| 115 | +// SetupDefaults - initializes OpenStackLightspeedDefaultValues with default values from env vars |
| 116 | +func SetupDefaults() { |
| 117 | + // Acquire environmental defaults and initialize OpenStackLightspeed defaults with them |
| 118 | + openStackLightspeedDefaults := OpenStackLightspeedDefaults{ |
| 119 | + RAGImageURL: util.GetEnvVar( |
| 120 | + "RELATED_IMAGE_OPENSTACK_LIGHTSPEED_IMAGE_URL_DEFAULT", OpenStackLightspeedContainerImage), |
| 121 | + } |
| 122 | + |
| 123 | + OpenStackLightspeedDefaultValues = openStackLightspeedDefaults |
| 124 | +} |
0 commit comments