Skip to content

Commit 6277203

Browse files
committed
Add OpenStackAssistant CRD with MCP server support
Introduces a new OpenStackAssistant custom resource (assistant.openstack.org/v1beta1) that deploys a managed Goose AI agent pod for cluster diagnostics via Lightspeed Stack. OpenStackAssistant CRD and controller: - New CRD with spec fields for provider type, container image, Lightspeed Stack backend configuration, node selectors, and additional environment variables - GooseConfig supports model selection, recipe ConfigMaps (registered as Goose slash commands), hints ConfigMaps (written to .goosehints), and MCP server references - Controller creates a ServiceAccount, ClusterRole with read-only RBAC for cluster diagnostics, ClusterRoleBinding, ConfigMap with Goose configuration and entrypoint script, and the assistant Pod - Watches referenced Secrets and ConfigMaps; reconciles on changes and tracks input hashes to detect drift - Defaulting webhook sets the container image from an environment variable fallback - Condition-based status reporting (ServiceAccount, RBAC, ConfigMap, Pod readiness) MCP server sidecar support for OpenStackClient: - New MCPConfig struct (enabled flag, containerImage) on the OpenStackClient CR spec - When enabled, the OpenStackClient controller adds a rhos-mcps MCP server sidecar container sharing the same clouds.yaml/secure.yaml credential mounts - Controller creates a ConfigMap with rhos-mcps config (openstack enabled, openshift disabled, allow_write: false) and a Service on port 8080 for the MCP endpoint - OpenStackAssistant can reference an OpenStackClient CR by name via the openstackClientRef field; the controller auto-computes the service URL and TLS CA configuration Tests: - Unit tests for the OpenStackAssistant controller covering reconciliation, pod creation, config generation, and status conditions - Unit tests for helper functions (entrypoint script generation, config building, hash computation)
1 parent aaec97f commit 6277203

45 files changed

Lines changed: 4529 additions & 170 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
15+
package v1beta1
16+
17+
import (
18+
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
19+
)
20+
21+
// OpenStackAssistant Condition Types used by API objects.
22+
const (
23+
// OpenStackAssistantReadyCondition Status=True condition which indicates if OpenStackAssistant is configured and operational
24+
OpenStackAssistantReadyCondition condition.Type = "OpenStackAssistantReady"
25+
)
26+
27+
// Common Messages used by API objects.
28+
const (
29+
// OpenStackAssistantReadyInitMessage
30+
OpenStackAssistantReadyInitMessage = "OpenStack Assistant not started"
31+
32+
// OpenStackAssistantReadyRunningMessage
33+
OpenStackAssistantReadyRunningMessage = "OpenStack Assistant in progress"
34+
35+
// OpenStackAssistantReadyMessage
36+
OpenStackAssistantReadyMessage = "OpenStack Assistant created"
37+
38+
// OpenStackAssistantReadyErrorMessage
39+
OpenStackAssistantReadyErrorMessage = "OpenStack Assistant error occured %s"
40+
41+
// OpenStackAssistantProviderSecretWaitingMessage
42+
OpenStackAssistantProviderSecretWaitingMessage = "Waiting for lightspeed provider secret"
43+
44+
// OpenStackAssistantRecipesWaitingMessage
45+
OpenStackAssistantRecipesWaitingMessage = "Waiting for Goose recipes ConfigMap"
46+
47+
// OpenStackAssistantHintsWaitingMessage
48+
OpenStackAssistantHintsWaitingMessage = "Waiting for Goose hints ConfigMap"
49+
50+
// OpenStackAssistantSkillsWaitingMessage
51+
OpenStackAssistantSkillsWaitingMessage = "Waiting for Goose skills ConfigMap"
52+
)

‎api/assistant/v1beta1/groupversion_info.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022.
2+
Copyright 2026.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

‎api/assistant/v1beta1/openstackassistant_types.go‎

Lines changed: 194 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022.
2+
Copyright 2026.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -17,31 +17,164 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
21+
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
22+
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
23+
corev1 "k8s.io/api/core/v1"
2024
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2125
)
2226

23-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
27+
const (
28+
// OpenStackAssistantContainerImage is the fall-back container image for OpenStackAssistant
29+
OpenStackAssistantContainerImage = "quay.io/openstack-s2i-containers/openstack-goose:master-latest"
30+
)
31+
32+
// ProviderType defines the AI agent provider
33+
// +kubebuilder:validation:Enum=goose
34+
type ProviderType string
35+
36+
const (
37+
// ProviderGoose is the Goose AI agent provider
38+
ProviderGoose ProviderType = "goose"
39+
)
40+
41+
// LightspeedStackSpec defines connectivity to the Lightspeed Stack AI backend
42+
type LightspeedStackSpec struct {
43+
// ProviderSecret is the name of a Secret containing the lightspeed
44+
// provider config JSON (custom_providers/lightspeed.json content).
45+
// Must contain key "lightspeed.json".
46+
// +kubebuilder:validation:Required
47+
// +kubebuilder:validation:MinLength=1
48+
ProviderSecret string `json:"providerSecret"`
49+
}
50+
51+
// MCPServerRef references an MCP server endpoint to configure as a Goose extension.
52+
// Exactly one of URL or OpenStackClientRef must be specified.
53+
// +kubebuilder:validation:XValidation:rule="has(self.url) != has(self.openstackClientRef)",message="exactly one of url or openstackClientRef must be set"
54+
type MCPServerRef struct {
55+
// Name is the extension name in Goose config. It is used to derive the
56+
// MCP_SERVER_<name> environment variable, so it must be a valid
57+
// environment-variable name: start with a letter or underscore and
58+
// contain only letters, digits, and underscores (no dashes).
59+
// +kubebuilder:validation:Required
60+
// +kubebuilder:validation:MinLength=1
61+
// +kubebuilder:validation:MaxLength=63
62+
// +kubebuilder:validation:Pattern=`^[a-zA-Z_][a-zA-Z0-9_]*$`
63+
Name string `json:"name"`
64+
65+
// URL is the MCP server's Streamable HTTP endpoint.
66+
// Mutually exclusive with OpenStackClientRef.
67+
// +kubebuilder:validation:Optional
68+
// +kubebuilder:validation:MinLength=1
69+
// ensures that a string contains no control characters
70+
// +kubebuilder:validation:Pattern=`^[^\p{Cc}]*$`
71+
URL string `json:"url,omitempty"`
72+
73+
// OpenStackClientRef is the name of an OpenStackClient CR in the same
74+
// namespace that has MCP enabled. The controller reads the service URL
75+
// published in the OpenStackClient status.
76+
// Mutually exclusive with URL.
77+
// +kubebuilder:validation:Optional
78+
// +kubebuilder:validation:MinLength=1
79+
OpenStackClientRef string `json:"openstackClientRef,omitempty"`
80+
}
81+
82+
// GooseConfig defines Goose-specific provider configuration
83+
type GooseConfig struct {
84+
// Model is the model identifier for the Goose AI agent
85+
// (e.g., "gemini/models/gemini-2.5-flash"). Sets the GOOSE_MODEL env var.
86+
// +kubebuilder:validation:Optional
87+
Model string `json:"model,omitempty"`
2588

26-
// OpenStackAssistantSpec defines the desired state of OpenStackAssistant.
89+
// Recipes is a ConfigMap name containing Goose recipe YAML files.
90+
// Each key in the ConfigMap becomes a recipe file registered as a
91+
// Goose slash command (e.g., /cluster-health).
92+
// +kubebuilder:validation:Optional
93+
// +kubebuilder:validation:MinLength=1
94+
Recipes *string `json:"recipes,omitempty"`
95+
96+
// Skills is a ConfigMap name containing Goose Agent Skill files.
97+
// Each key in the ConfigMap becomes a skill named after the key
98+
// (extension stripped), written as ~/.config/goose/skills/<name>/SKILL.md.
99+
// Unlike Recipes, skills are not explicitly invoked - Goose loads
100+
// them automatically when their description matches the task at hand.
101+
// +kubebuilder:validation:Optional
102+
// +kubebuilder:validation:MinLength=1
103+
Skills *string `json:"skills,omitempty"`
104+
105+
// Hints is a ConfigMap name containing Goose hints/context.
106+
// The ConfigMap must have a key "hints" with the content that
107+
// will be written to ~/.goosehints in the pod.
108+
// +kubebuilder:validation:Optional
109+
// +kubebuilder:validation:MinLength=1
110+
Hints *string `json:"hints,omitempty"`
111+
112+
// MCPServers lists MCP server endpoints to configure as Goose extensions.
113+
// +kubebuilder:validation:Optional
114+
// +listType=map
115+
// +listMapKey=name
116+
MCPServers []MCPServerRef `json:"mcpServers,omitempty"`
117+
}
118+
119+
// OpenStackAssistantSpec defines the desired state of OpenStackAssistant
27120
type OpenStackAssistantSpec struct {
28-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29-
// Important: Run "make" to regenerate code after modifying this file
121+
// ContainerImage for the assistant container (will be set to environmental default if empty).
122+
// +kubebuilder:validation:Required
123+
ContainerImage string `json:"containerImage"`
124+
125+
// Provider is the AI agent provider type. Currently only "goose" is supported.
126+
// +kubebuilder:validation:Optional
127+
// +kubebuilder:default=goose
128+
Provider ProviderType `json:"provider,omitempty"`
129+
130+
// LightspeedStack configuration for the AI backend.
131+
// +kubebuilder:validation:Required
132+
LightspeedStack LightspeedStackSpec `json:"lightspeedStack"`
133+
134+
// Goose contains Goose-specific provider configuration.
135+
// Only applicable when provider is "goose".
136+
// +kubebuilder:validation:Optional
137+
Goose *GooseConfig `json:"goose,omitempty"`
138+
139+
// +kubebuilder:validation:Optional
140+
// +operator-sdk:csv:customresourcedefinitions:type=spec
141+
// Secret containing any CA certificates which should be added to the assistant pod.
142+
tls.Ca `json:",inline"`
143+
144+
// NodeSelector to target subset of worker nodes for pod scheduling.
145+
// +kubebuilder:validation:Optional
146+
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`
30147

31-
// Foo is an example field of OpenStackAssistant. Edit openstackassistant_types.go to remove/update
32-
Foo string `json:"foo,omitempty"`
148+
// Env is a list of additional environment variables for the container.
149+
// +kubebuilder:validation:Optional
150+
// +listType=map
151+
// +listMapKey=name
152+
Env []corev1.EnvVar `json:"env,omitempty"`
33153
}
34154

35-
// OpenStackAssistantStatus defines the observed state of OpenStackAssistant.
155+
// OpenStackAssistantStatus defines the observed state of OpenStackAssistant
36156
type OpenStackAssistantStatus struct {
37-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38-
// Important: Run "make" to regenerate code after modifying this file
157+
// PodName is the name of the running assistant pod
158+
PodName string `json:"podName,omitempty"`
159+
160+
// Conditions tracks the state of each sub-resource
161+
Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"`
162+
163+
// ObservedGeneration - the most recent generation observed
164+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
165+
166+
// Hash tracks input hashes to detect changes
167+
Hash map[string]string `json:"hash,omitempty"`
39168
}
40169

41170
// +kubebuilder:object:root=true
42171
// +kubebuilder:subresource:status
172+
// +operator-sdk:csv:customresourcedefinitions:displayName="OpenStack Assistant"
173+
// +kubebuilder:resource:shortName=osassistant;osassistants
174+
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[0].status",description="Status"
175+
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.conditions[0].message",description="Message"
43176

44-
// OpenStackAssistant is the Schema for the openstackassistants API.
177+
// OpenStackAssistant is the Schema for the openstackassistants API
45178
type OpenStackAssistant struct {
46179
metav1.TypeMeta `json:",inline"`
47180
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -52,7 +185,7 @@ type OpenStackAssistant struct {
52185

53186
// +kubebuilder:object:root=true
54187

55-
// OpenStackAssistantList contains a list of OpenStackAssistant.
188+
// OpenStackAssistantList contains a list of OpenStackAssistant
56189
type OpenStackAssistantList struct {
57190
metav1.TypeMeta `json:",inline"`
58191
metav1.ListMeta `json:"metadata,omitempty"`
@@ -62,3 +195,51 @@ type OpenStackAssistantList struct {
62195
func init() {
63196
SchemeBuilder.Register(&OpenStackAssistant{}, &OpenStackAssistantList{})
64197
}
198+
199+
// IsReady - returns true if OpenStackAssistant is reconciled successfully
200+
func (instance OpenStackAssistant) IsReady() bool {
201+
return instance.Status.Conditions.IsTrue(OpenStackAssistantReadyCondition)
202+
}
203+
204+
// RbacConditionsSet - set the conditions for the rbac object
205+
func (instance OpenStackAssistant) RbacConditionsSet(c *condition.Condition) {
206+
instance.Status.Conditions.Set(c)
207+
}
208+
209+
// RbacNamespace - return the namespace
210+
func (instance OpenStackAssistant) RbacNamespace() string {
211+
return instance.Namespace
212+
}
213+
214+
// RbacResourceName - return the name to be used for rbac objects (serviceaccount, role, rolebinding)
215+
func (instance OpenStackAssistant) RbacResourceName() string {
216+
return "openstackassistant-" + instance.Name
217+
}
218+
219+
// OpenStackAssistantDefaults holds defaults for the assistant
220+
type OpenStackAssistantDefaults struct {
221+
ContainerImageURL string
222+
}
223+
224+
var openStackAssistantDefaults OpenStackAssistantDefaults
225+
226+
// SetupOpenStackAssistantDefaults - initialize OpenStackAssistant spec defaults
227+
func SetupOpenStackAssistantDefaults(defaults OpenStackAssistantDefaults) {
228+
openStackAssistantDefaults = defaults
229+
}
230+
231+
// SetupDefaults - initializes any CRD field defaults based on environment variables
232+
func SetupDefaults() {
233+
openStackAssistantDefaults := OpenStackAssistantDefaults{
234+
ContainerImageURL: util.GetEnvVar("RELATED_IMAGE_OPENSTACK_ASSISTANT_IMAGE_URL_DEFAULT", OpenStackAssistantContainerImage),
235+
}
236+
237+
SetupOpenStackAssistantDefaults(openStackAssistantDefaults)
238+
}
239+
240+
// Default implements webhook.Defaulter
241+
func (r *OpenStackAssistant) Default() {
242+
if r.Spec.ContainerImage == "" {
243+
r.Spec.ContainerImage = openStackAssistantDefaults.ContainerImageURL
244+
}
245+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2026.
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+
"testing"
21+
22+
"github.com/onsi/gomega"
23+
)
24+
25+
func TestOpenStackAssistantDefaultCABundle(t *testing.T) {
26+
g := gomega.NewWithT(t)
27+
assistant := &OpenStackAssistant{}
28+
29+
assistant.Default()
30+
31+
g.Expect(assistant.Spec.CaBundleSecretName).To(gomega.BeEmpty())
32+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2026.
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+
"k8s.io/apimachinery/pkg/runtime"
21+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
22+
)
23+
24+
// ValidateCreate implements webhook.Validator
25+
func (r *OpenStackAssistant) ValidateCreate() (admission.Warnings, error) {
26+
return nil, nil
27+
}
28+
29+
// ValidateUpdate implements webhook.Validator
30+
func (r *OpenStackAssistant) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) {
31+
return nil, nil
32+
}
33+
34+
// ValidateDelete implements webhook.Validator
35+
func (r *OpenStackAssistant) ValidateDelete() (admission.Warnings, error) {
36+
return nil, nil
37+
}

0 commit comments

Comments
 (0)