Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

Commit 0e1d583

Browse files
Merge pull request #27 from lpiwowar/lpiwowar/OSPRH-21185
[OSPRH-21185] Install OLS operator
2 parents b28a6c5 + 1c63181 commit 0e1d583

18 files changed

Lines changed: 824 additions & 222 deletions

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ build: manifests generate fmt vet ## Build manager binary.
146146

147147
.PHONY: run
148148
run: manifests generate fmt vet ## Run a controller from your host.
149-
go run ./cmd/main.go
149+
source ./scripts/env.sh && go run ./cmd/main.go
150150

151151
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
152152
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
@@ -217,18 +217,18 @@ undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.
217217
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
218218

219219
# Deploy using the catalog image.
220-
.PHONY: catalog-deploy
221-
catalog-deploy: export OUTPUT_DIR = out
222-
catalog-deploy: ## Deploy using a catalog image.
220+
.PHONY: openstack-lightspeed-deploy
221+
openstack-lightspeed-deploy: export OUTPUT_DIR = out
222+
openstack-lightspeed-deploy: ## Deploy using a catalog image.
223223
bash scripts/gen-catalog.sh $(CATALOG_IMG) $(CATALOG_NAME)
224224
oc apply -f $(OUTPUT_DIR)/catalog
225225
bash scripts/gen-rhosls.sh $(CATALOG_NAME) $(CATALOG_CHANNEL)
226226
oc apply -f $(OUTPUT_DIR)/rhosls
227227

228228
# Deploy using the catalog image.
229-
.PHONY: catalog-undeploy
230-
catalog-undeploy: export OUTPUT_DIR = out
231-
catalog-undeploy: ## Undeploy using a catalog image.
229+
.PHONY: openstack-lightspeed-undeploy
230+
openstack-lightspeed-undeploy: export OUTPUT_DIR = out
231+
openstack-lightspeed-undeploy: ## Undeploy using a catalog image.
232232
find out/{catalog,rhosls} -name "*.yaml" -printf " -f %p" | xargs oc delete --ignore-not-found=true
233233

234234
CATALOG_NAME ?= openstack-lightspeed-catalog
@@ -250,7 +250,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
250250

251251
## Tool Versions
252252
KUSTOMIZE_VERSION ?= v5.4.2
253-
CONTROLLER_TOOLS_VERSION ?= v0.15.0
253+
CONTROLLER_TOOLS_VERSION ?= v0.16.5
254254
ENVTEST_VERSION ?= release-0.18
255255
GOLANGCI_LINT_VERSION ?= v2.6.0
256256

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ eval $(crc oc-env)
3737
cd ../..
3838
```
3939

40-
### Deploy OpenShift and OpenStack Lightspeed Operators
40+
### Deploy OpenStack Lightspeed Operator
4141

4242
Get the operator repository:
4343

@@ -46,20 +46,15 @@ git clone https://github.com/openstack-lightspeed/operator.git
4646
cd operator
4747
```
4848

49-
First, deploy OpenShift Lightspeed, then proceed to deploy OpenStack Lightspeed:
49+
First, deploy OpenStack Lightspeed Operator:
5050

5151
```bash
52-
make ols-deploy
53-
make catalog-deploy
52+
make openstack-lightspeed-deploy
5453
```
5554

56-
Now verify that they are up and running:
55+
Next, verify that the OpenStack Lightspeed Operator pod is running:
5756

5857
```bash
59-
$ oc get -n openshift-lightspeed pods
60-
NAME READY STATUS RESTARTS AGE
61-
lightspeed-operator-controller-manager-7f4698b55c-8w8vn 1/1 Running 0 81s
62-
6358
$ oc get -n openstack-lightspeed pods
6459
NAME READY STATUS RESTARTS AGE
6560
openstack-lightspeed-operator-controller-manager-76df7fbfb5wggr 1/1 Running 0 72s

api/v1beta1/conditions.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const (
2222
// OpenStackLightspeedReadyCondition Status=True condition which indicates if OpenStackLightspeedReadyCondition
2323
// is configured and operational
2424
OpenStackLightspeedReadyCondition condition.Type = "OpenStackLightspeedReady"
25+
26+
// OpenShift Lightspeed Operator Status=True condition which indicates if OpenShift Lightspeed is installed and
27+
// operational and it can be used by OpenStack Lihgtspeed operator.
28+
OpenShiftLightspeedOperatorReadyCondition condition.Type = "OpenShiftLightspeedOperatorReady"
2529
)
2630

2731
// Common Messages used by API objects.
@@ -34,4 +38,10 @@ const (
3438

3539
// OpenStackLightspeedWaitingVectorDBMessage
3640
OpenStackLightspeedWaitingVectorDBMessage = "Waiting for OpenStackLightspeed vector DB pod to become ready"
41+
42+
// OpenShiftLightspeedOperatorWaiting
43+
OpenShiftLightspeedOperatorWaiting = "Waiting for the OpenShift Lightspeed operator to deploy."
44+
45+
// OpenShiftLigthspeedOperatorReady
46+
OpenShiftLightspeedOperatorReady = "OpenShift Lightspeed operator is ready."
3747
)

api/v1beta1/openstacklightspeed_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ type OpenStackLightspeedCore struct {
6767
// +kubebuilder:validation:Optional
6868
// MaxTokensForResponse defines the maximum number of tokens to be used for the response generation
6969
MaxTokensForResponse int `json:"maxTokensForResponse,omitempty"`
70+
71+
// +kubebuilder:validation:Optional
72+
// +kubebuilder:default="openshift-marketplace"
73+
// Namespace where the CatalogSource containing the OLS operator is located
74+
CatalogSourceNamespace string `json:"catalogSourceNamespace"`
75+
76+
// +kubebuilder:validation:Optional
77+
// +kubebuilder:default="redhat-operators"
78+
// Name of the CatalogSource that contains the OLS Operator
79+
CatalogSourceName string `json:"catalogSourceName"`
7080
}
7181

7282
// OpenStackLightspeedStatus defines the observed state of OpenStackLightspeed

cmd/main.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919
import (
2020
"crypto/tls"
2121
"flag"
22+
"fmt"
2223
"os"
2324

2425
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
@@ -29,12 +30,15 @@ import (
2930
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3031
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3132
ctrl "sigs.k8s.io/controller-runtime"
33+
"sigs.k8s.io/controller-runtime/pkg/cache"
3234
"sigs.k8s.io/controller-runtime/pkg/healthz"
3335
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3436
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
3537
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3638
"sigs.k8s.io/controller-runtime/pkg/webhook"
3739

40+
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
41+
3842
apiv1beta1 "github.com/openstack-lightspeed/operator/api/v1beta1"
3943
"github.com/openstack-lightspeed/operator/internal/controller"
4044
// +kubebuilder:scaffold:imports
@@ -48,6 +52,8 @@ var (
4852
func init() {
4953
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
5054

55+
utilruntime.Must(operatorsv1alpha1.AddToScheme(scheme))
56+
5157
utilruntime.Must(apiv1beta1.AddToScheme(scheme))
5258
// +kubebuilder:scaffold:scheme
5359
}
@@ -120,13 +126,23 @@ func main() {
120126
metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
121127
}
122128

129+
watchNamespace, err := getWatchNamespace()
130+
if err != nil {
131+
setupLog.Error(err, "unable to get WatchNamespace, "+
132+
"the manager will watch and manage resources in all namespaces")
133+
os.Exit(1)
134+
}
135+
123136
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
124137
Scheme: scheme,
125138
Metrics: metricsServerOptions,
126139
WebhookServer: webhookServer,
127140
HealthProbeBindAddress: probeAddr,
128141
LeaderElection: enableLeaderElection,
129142
LeaderElectionID: "c83b0a4f.lightspeed.openstack.org",
143+
Cache: cache.Options{
144+
DefaultNamespaces: map[string]cache.Config{watchNamespace: {}},
145+
},
130146
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
131147
// when the Manager ends. This requires the binary to immediately end when the
132148
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
@@ -171,3 +187,17 @@ func main() {
171187
os.Exit(1)
172188
}
173189
}
190+
191+
// getWatchNamespace returns the Namespace the operator should be watching for changes
192+
func getWatchNamespace() (string, error) {
193+
// WatchNamespaceEnvVar is the constant for env variable WATCH_NAMESPACE
194+
// which specifies the Namespace to watch.
195+
// An empty value means the operator is running with cluster scope.
196+
var watchNamespaceEnvVar = "WATCH_NAMESPACE"
197+
198+
ns, found := os.LookupEnv(watchNamespaceEnvVar)
199+
if !found {
200+
return "", fmt.Errorf("%s must be set", watchNamespaceEnvVar)
201+
}
202+
return ns, nil
203+
}

config/crd/bases/lightspeed.openstack.org_openstacklightspeeds.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.15.0
6+
controller-gen.kubebuilder.io/version: v0.16.5
77
name: openstacklightspeeds.lightspeed.openstack.org
88
spec:
99
group: lightspeed.openstack.org
@@ -40,6 +40,15 @@ spec:
4040
spec:
4141
description: OpenStackLightspeedSpec defines the desired state of OpenStackLightspeed
4242
properties:
43+
catalogSourceName:
44+
default: redhat-operators
45+
description: Name of the CatalogSource that contains the OLS Operator
46+
type: string
47+
catalogSourceNamespace:
48+
default: openshift-marketplace
49+
description: Namespace where the CatalogSource containing the OLS
50+
operator is located
51+
type: string
4352
llmCredentials:
4453
description: |-
4554
Secret name containing API token for the LLMEndpoint. The key for the field

config/manager/manager.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ spec:
6565
- --health-probe-bind-address=:8081
6666
image: controller:latest
6767
name: manager
68+
env:
69+
- name: "OPENSHIFT_LIGHTSPEED_OPERATOR_VERSION"
70+
value: "latest"
71+
- name: WATCH_NAMESPACE
72+
valueFrom:
73+
fieldRef:
74+
fieldPath: metadata.namespace
6875
securityContext:
6976
allowPrivilegeEscalation: false
7077
capabilities:

config/manifests/bases/openstack-lightspeed-operator.clusterserviceversion.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ metadata:
44
annotations:
55
alm-examples: '[]'
66
capabilities: Basic Install
7-
operatorframework.io/suggested-namespace: openstack-lightspeed
7+
operatorframework.io/suggested-namespace: openshift-lightspeed
88
repository: https://github.com/openstack-lightspeed/operator
99
name: openstack-lightspeed-operator.v0.0.0
10-
namespace: openstack-lightspeed
10+
namespace: openshift-lightspeed
1111
spec:
1212
apiservicedefinitions: {}
1313
customresourcedefinitions: {}

config/rbac/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ resources:
77
- service_account.yaml
88
- role.yaml
99
- role_binding.yaml
10+
- namespace_role_binding.yaml
1011
- leader_election_role.yaml
1112
- leader_election_role_binding.yaml
1213
# The following RBAC configurations are used to protect
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: RoleBinding
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: openstack-lightspeed-operator
6+
app.kubernetes.io/managed-by: kustomize
7+
name: manager-rolebinding
8+
namespace: openstack-lightspeed
9+
roleRef:
10+
apiGroup: rbac.authorization.k8s.io
11+
kind: Role
12+
name: manager-role
13+
subjects:
14+
- kind: ServiceAccount
15+
name: controller-manager
16+
namespace: system
17+

0 commit comments

Comments
 (0)