Skip to content
Open
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
31 changes: 31 additions & 0 deletions api/v1beta1/openstacklightspeed_dev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2026

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import "encoding/json"

// ParseDevConfig unmarshals the Dev RawExtension into a DevSpec.
// Returns a zero-value DevSpec and an error on malformed input.
func (instance *OpenStackLightspeed) ParseDevConfig() (DevSpec, error) {
var devConfig DevSpec
if len(instance.Spec.Dev.Raw) > 0 {
if err := json.Unmarshal(instance.Spec.Dev.Raw, &devConfig); err != nil {
return devConfig, err
}
}
return devConfig, nil
}
98 changes: 98 additions & 0 deletions api/v1beta1/openstacklightspeed_images.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
Copyright 2025.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

func resolveContainerImage(manifestImage, defaultImage string) string {
if manifestImage != "" {
return manifestImage
}
return defaultImage
}

// RAGContainerImage returns the RAG init-container image for this instance.
func (instance *OpenStackLightspeed) RAGContainerImage() string {
manifestImage := ""
if instance.Spec.RAG != nil {
manifestImage = instance.Spec.RAG.ContainerImage
}
return resolveContainerImage(manifestImage, OpenStackLightspeedDefaultValues.RAGImageURL)
}

// OGXContainerImage returns the OGX/llama-stack container image for this instance.
func (instance *OpenStackLightspeed) OGXContainerImage() string {
manifestImage := ""
if instance.Spec.OGX != nil {
manifestImage = instance.Spec.OGX.ContainerImage
}
return resolveContainerImage(manifestImage, OpenStackLightspeedDefaultValues.OGXImageURL)
}

// LightspeedContainerImage returns the lightspeed-service-api container image for this instance.
func (instance *OpenStackLightspeed) LightspeedContainerImage() string {
manifestImage := ""
if instance.Spec.Lightspeed != nil {
manifestImage = instance.Spec.Lightspeed.ContainerImage
}
return resolveContainerImage(manifestImage, OpenStackLightspeedDefaultValues.LCoreImageURL)
}

// ExporterContainerImage returns the dataverse exporter sidecar container image for this instance.
func (instance *OpenStackLightspeed) ExporterContainerImage() string {
manifestImage := ""
if instance.Spec.DataverseExporter != nil {
manifestImage = instance.Spec.DataverseExporter.ContainerImage
}
return resolveContainerImage(manifestImage, OpenStackLightspeedDefaultValues.ExporterImageURL)
}

// PostgresContainerImage returns the PostgreSQL container image for this instance.
func (instance *OpenStackLightspeed) PostgresContainerImage() string {
manifestImage := ""
if instance.Spec.Database != nil {
manifestImage = instance.Spec.Database.ContainerImage
}
return resolveContainerImage(manifestImage, OpenStackLightspeedDefaultValues.PostgresImageURL)
}

// OKPContainerImage returns the OKP container image for this instance.
func (instance *OpenStackLightspeed) OKPContainerImage() string {
manifestImage := ""
if instance.Spec.OKP != nil {
manifestImage = instance.Spec.OKP.ContainerImage
}
return resolveContainerImage(manifestImage, OpenStackLightspeedDefaultValues.OKPImageURL)
}

// ConsoleContainerImage returns the console plugin container image for this instance.
// When spec.console.containerImage is unset, ocpDefault is used (typically PF5/PF6 selection).
func (instance *OpenStackLightspeed) ConsoleContainerImage(ocpDefault string) string {
if instance.Spec.Console != nil && instance.Spec.Console.ContainerImage != "" {
return instance.Spec.Console.ContainerImage
}
return ocpDefault
}

// MCPContainerImage returns the MCP container image for this instance.
func (instance *OpenStackLightspeed) MCPContainerImage() string {
manifestImage := ""

devConfig, err := instance.ParseDevConfig()
if err == nil && devConfig.RhosMCP != nil && devConfig.RhosMCP.ContainerImage != "" {
manifestImage = devConfig.RhosMCP.ContainerImage
}
return resolveContainerImage(manifestImage, OpenStackLightspeedDefaultValues.MCPServerImageURL)
}
182 changes: 182 additions & 0 deletions api/v1beta1/openstacklightspeed_images_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
Copyright 2025.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
"testing"
)

func TestResolveContainerImage(t *testing.T) {
t.Parallel()

tests := []struct {
name string
manifestImage string
defaultImage string
expectedResult string
}{
{
name: "manifest override",
manifestImage: "example.com/custom:1.0",
defaultImage: "example.com/default:1.0",
expectedResult: "example.com/custom:1.0",
},
{
name: "empty manifest uses default",
manifestImage: "",
defaultImage: "example.com/default:1.0",
expectedResult: "example.com/default:1.0",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := resolveContainerImage(tt.manifestImage, tt.defaultImage); got != tt.expectedResult {
t.Errorf("resolveContainerImage() = %q, want %q", got, tt.expectedResult)
}
})
}
}

func TestOpenStackLightspeedContainerImages(t *testing.T) {
OpenStackLightspeedDefaultValues = OpenStackLightspeedDefaults{
RAGImageURL: "default/rag:1",
LCoreImageURL: "default/lcore:1",
OGXImageURL: "default/ogx:1",
ExporterImageURL: "default/exporter:1",
PostgresImageURL: "default/postgres:1",
OKPImageURL: "default/okp:1",
}

instance := &OpenStackLightspeed{
Spec: OpenStackLightspeedSpec{
OpenStackLightspeedCore: OpenStackLightspeedCore{
RAG: &RAG{ContainerImage: "custom/rag:2"},
OGX: &OGXSpec{ContainerImage: "custom/ogx:2"},
Lightspeed: &LightspeedSpec{ContainerImage: "custom/lcore:2"},
DataverseExporter: &DataverseExporter{ContainerImage: "custom/exporter:2"},
},
Console: &ConsoleSpec{ContainerImage: "custom/console:2"},
Database: &DatabaseSpec{ContainerImage: "custom/postgres:2"},
OKP: &OKPSpec{ContainerImage: "custom/okp:2"},
},
}

if got := instance.RAGContainerImage(); got != "custom/rag:2" {
t.Errorf("RAGContainerImage() = %q, want %q", got, "custom/rag:2")
}
if got := instance.OGXContainerImage(); got != "custom/ogx:2" {
t.Errorf("OGXContainerImage() = %q, want %q", got, "custom/ogx:2")
}
if got := instance.LightspeedContainerImage(); got != "custom/lcore:2" {
t.Errorf("LightspeedContainerImage() = %q, want %q", got, "custom/lcore:2")
}
if got := instance.ExporterContainerImage(); got != "custom/exporter:2" {
t.Errorf("ExporterContainerImage() = %q, want %q", got, "custom/exporter:2")
}
if got := instance.PostgresContainerImage(); got != "custom/postgres:2" {
t.Errorf("PostgresContainerImage() = %q, want %q", got, "custom/postgres:2")
}
if got := instance.OKPContainerImage(); got != "custom/okp:2" {
t.Errorf("OKPContainerImage() = %q, want %q", got, "custom/okp:2")
}
if got := instance.ConsoleContainerImage("default/console-pf5:1"); got != "custom/console:2" {
t.Errorf("ConsoleContainerImage() = %q, want %q", got, "custom/console:2")
}
}

func TestOpenStackLightspeedContainerImagesUseDefaults(t *testing.T) {
OpenStackLightspeedDefaultValues = OpenStackLightspeedDefaults{
RAGImageURL: "default/rag:1",
LCoreImageURL: "default/lcore:1",
OGXImageURL: "default/ogx:1",
ExporterImageURL: "default/exporter:1",
PostgresImageURL: "default/postgres:1",
OKPImageURL: "default/okp:1",
}

instance := &OpenStackLightspeed{
Spec: OpenStackLightspeedSpec{},
}

if got := instance.RAGContainerImage(); got != "default/rag:1" {
t.Errorf("RAGContainerImage() = %q, want %q", got, "default/rag:1")
}
if got := instance.OGXContainerImage(); got != "default/ogx:1" {
t.Errorf("OGXContainerImage() = %q, want %q", got, "default/ogx:1")
}
if got := instance.LightspeedContainerImage(); got != "default/lcore:1" {
t.Errorf("LightspeedContainerImage() = %q, want %q", got, "default/lcore:1")
}
if got := instance.ExporterContainerImage(); got != "default/exporter:1" {
t.Errorf("ExporterContainerImage() = %q, want %q", got, "default/exporter:1")
}
if got := instance.PostgresContainerImage(); got != "default/postgres:1" {
t.Errorf("PostgresContainerImage() = %q, want %q", got, "default/postgres:1")
}
if got := instance.OKPContainerImage(); got != "default/okp:1" {
t.Errorf("OKPContainerImage() = %q, want %q", got, "default/okp:1")
}
if got := instance.ConsoleContainerImage("default/console-pf5:1"); got != "default/console-pf5:1" {
t.Errorf("ConsoleContainerImage() = %q, want %q", got, "default/console-pf5:1")
}
}

func TestSetupDefaults_OGXImageURLFromEnv(t *testing.T) {
t.Setenv("RELATED_IMAGE_OGX_IMAGE_URL_DEFAULT", "env/ogx:1")
t.Setenv("RELATED_IMAGE_LCORE_IMAGE_URL_DEFAULT", "env/lcore:1")
t.Setenv("RELATED_IMAGE_OPENSTACK_LIGHTSPEED_IMAGE_URL_DEFAULT", "env/rag:1")
t.Setenv("RELATED_IMAGE_EXPORTER_IMAGE_URL_DEFAULT", "env/exporter:1")
t.Setenv("RELATED_IMAGE_POSTGRES_IMAGE_URL_DEFAULT", "env/postgres:1")
t.Setenv("RELATED_IMAGE_CONSOLE_IMAGE_URL_DEFAULT", "env/console:1")
t.Setenv("RELATED_IMAGE_CONSOLE_PF5_IMAGE_URL_DEFAULT", "env/console-pf5:1")
t.Setenv("RELATED_IMAGE_OKP_IMAGE_URL_DEFAULT", "env/okp:1")
t.Setenv("RELATED_IMAGE_MCP_SERVER_IMAGE_URL_DEFAULT", "env/mcp:1")

SetupDefaults()

if got := OpenStackLightspeedDefaultValues.OGXImageURL; got != "env/ogx:1" {
t.Errorf("OGXImageURL = %q, want %q", got, "env/ogx:1")
}
if got := OpenStackLightspeedDefaultValues.LCoreImageURL; got != "env/lcore:1" {
t.Errorf("LCoreImageURL = %q, want %q", got, "env/lcore:1")
}
}

func TestOpenStackLightspeedContainerImages_OGXAndLightspeedIndependent(t *testing.T) {
OpenStackLightspeedDefaultValues = OpenStackLightspeedDefaults{
LCoreImageURL: "default/lcore:1",
OGXImageURL: "default/ogx:1",
}

instance := &OpenStackLightspeed{
Spec: OpenStackLightspeedSpec{
OpenStackLightspeedCore: OpenStackLightspeedCore{
OGX: &OGXSpec{ContainerImage: "custom/ogx:2"},
Lightspeed: &LightspeedSpec{ContainerImage: "custom/lcore:2"},
},
},
}

if got := instance.OGXContainerImage(); got != "custom/ogx:2" {
t.Errorf("OGXContainerImage() = %q, want %q", got, "custom/ogx:2")
}
if got := instance.LightspeedContainerImage(); got != "custom/lcore:2" {
t.Errorf("LightspeedContainerImage() = %q, want %q", got, "custom/lcore:2")
}
}
Loading
Loading