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
24 changes: 24 additions & 0 deletions cmd/thv-operator/api/v1alpha1/mcpremoteproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ const (

// ConditionTypeMCPRemoteProxyGroupRefValidated indicates whether the GroupRef is valid
ConditionTypeMCPRemoteProxyGroupRefValidated = "GroupRefValidated"

// ConditionTypeMCPRemoteProxyToolConfigValidated indicates whether the ToolConfigRef is valid
ConditionTypeMCPRemoteProxyToolConfigValidated = "ToolConfigValidated"

// ConditionTypeMCPRemoteProxyExternalAuthConfigValidated indicates whether the ExternalAuthConfigRef is valid
ConditionTypeMCPRemoteProxyExternalAuthConfigValidated = "ExternalAuthConfigValidated"
)

// Condition reasons for MCPRemoteProxy
Expand Down Expand Up @@ -217,6 +223,24 @@ const (

// ConditionReasonMCPRemoteProxyGroupRefNotReady indicates the referenced MCPGroup is not in the Ready state
ConditionReasonMCPRemoteProxyGroupRefNotReady = "GroupRefNotReady"

// ConditionReasonMCPRemoteProxyToolConfigValid indicates the ToolConfigRef is valid
ConditionReasonMCPRemoteProxyToolConfigValid = "ToolConfigValid"

// ConditionReasonMCPRemoteProxyToolConfigNotFound indicates the referenced MCPToolConfig was not found
ConditionReasonMCPRemoteProxyToolConfigNotFound = "ToolConfigNotFound"

// ConditionReasonMCPRemoteProxyToolConfigFetchError indicates an error occurred fetching the MCPToolConfig
ConditionReasonMCPRemoteProxyToolConfigFetchError = "ToolConfigFetchError"

// ConditionReasonMCPRemoteProxyExternalAuthConfigValid indicates the ExternalAuthConfigRef is valid
ConditionReasonMCPRemoteProxyExternalAuthConfigValid = "ExternalAuthConfigValid"

// ConditionReasonMCPRemoteProxyExternalAuthConfigNotFound indicates the referenced MCPExternalAuthConfig was not found
ConditionReasonMCPRemoteProxyExternalAuthConfigNotFound = "ExternalAuthConfigNotFound"

// ConditionReasonMCPRemoteProxyExternalAuthConfigFetchError indicates an error occurred fetching the MCPExternalAuthConfig
ConditionReasonMCPRemoteProxyExternalAuthConfigFetchError = "ExternalAuthConfigFetchError"
)

//+kubebuilder:object:root=true
Expand Down
68 changes: 60 additions & 8 deletions cmd/thv-operator/controllers/mcpremoteproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ func (r *MCPRemoteProxyReconciler) validateSpec(ctx context.Context, proxy *mcpv
func (r *MCPRemoteProxyReconciler) handleToolConfig(ctx context.Context, proxy *mcpv1alpha1.MCPRemoteProxy) error {
ctxLogger := log.FromContext(ctx)
if proxy.Spec.ToolConfigRef == nil {
// Remove condition if ToolConfigRef is not set
meta.RemoveStatusCondition(&proxy.Status.Conditions, mcpv1alpha1.ConditionTypeMCPRemoteProxyToolConfigValidated)
if proxy.Status.ToolConfigHash != "" {
proxy.Status.ToolConfigHash = ""
if err := r.Status().Update(ctx, proxy); err != nil {
Expand All @@ -363,12 +365,36 @@ func (r *MCPRemoteProxyReconciler) handleToolConfig(ctx context.Context, proxy *

toolConfig, err := ctrlutil.GetToolConfigForMCPRemoteProxy(ctx, r.Client, proxy)
if err != nil {
return err
if errors.IsNotFound(err) {
meta.SetStatusCondition(&proxy.Status.Conditions, metav1.Condition{
Type: mcpv1alpha1.ConditionTypeMCPRemoteProxyToolConfigValidated,
Status: metav1.ConditionFalse,
Reason: mcpv1alpha1.ConditionReasonMCPRemoteProxyToolConfigNotFound,
Message: fmt.Sprintf("MCPToolConfig '%s' not found in namespace '%s'",
proxy.Spec.ToolConfigRef.Name, proxy.Namespace),
ObservedGeneration: proxy.Generation,
})
return fmt.Errorf("MCPToolConfig '%s' not found in namespace '%s'",
proxy.Spec.ToolConfigRef.Name, proxy.Namespace)
}
meta.SetStatusCondition(&proxy.Status.Conditions, metav1.Condition{
Type: mcpv1alpha1.ConditionTypeMCPRemoteProxyToolConfigValidated,
Status: metav1.ConditionFalse,
Reason: mcpv1alpha1.ConditionReasonMCPRemoteProxyToolConfigFetchError,
Message: "Failed to fetch MCPToolConfig",
ObservedGeneration: proxy.Generation,
})
return fmt.Errorf("failed to fetch MCPToolConfig: %w", err)
}

if toolConfig == nil {
return fmt.Errorf("MCPToolConfig %s not found", proxy.Spec.ToolConfigRef.Name)
}
// ToolConfig found and valid
meta.SetStatusCondition(&proxy.Status.Conditions, metav1.Condition{
Type: mcpv1alpha1.ConditionTypeMCPRemoteProxyToolConfigValidated,
Status: metav1.ConditionTrue,
Reason: mcpv1alpha1.ConditionReasonMCPRemoteProxyToolConfigValid,
Message: fmt.Sprintf("MCPToolConfig '%s' is valid", toolConfig.Name),
ObservedGeneration: proxy.Generation,
})

if proxy.Status.ToolConfigHash != toolConfig.Status.ConfigHash {
ctxLogger.Info("MCPToolConfig has changed, updating MCPRemoteProxy",
Expand All @@ -390,6 +416,8 @@ func (r *MCPRemoteProxyReconciler) handleToolConfig(ctx context.Context, proxy *
func (r *MCPRemoteProxyReconciler) handleExternalAuthConfig(ctx context.Context, proxy *mcpv1alpha1.MCPRemoteProxy) error {
ctxLogger := log.FromContext(ctx)
if proxy.Spec.ExternalAuthConfigRef == nil {
// Remove condition if ExternalAuthConfigRef is not set
meta.RemoveStatusCondition(&proxy.Status.Conditions, mcpv1alpha1.ConditionTypeMCPRemoteProxyExternalAuthConfigValidated)
if proxy.Status.ExternalAuthConfigHash != "" {
proxy.Status.ExternalAuthConfigHash = ""
if err := r.Status().Update(ctx, proxy); err != nil {
Expand All @@ -401,12 +429,36 @@ func (r *MCPRemoteProxyReconciler) handleExternalAuthConfig(ctx context.Context,

externalAuthConfig, err := ctrlutil.GetExternalAuthConfigForMCPRemoteProxy(ctx, r.Client, proxy)
if err != nil {
return err
if errors.IsNotFound(err) {
meta.SetStatusCondition(&proxy.Status.Conditions, metav1.Condition{
Type: mcpv1alpha1.ConditionTypeMCPRemoteProxyExternalAuthConfigValidated,
Status: metav1.ConditionFalse,
Reason: mcpv1alpha1.ConditionReasonMCPRemoteProxyExternalAuthConfigNotFound,
Message: fmt.Sprintf("MCPExternalAuthConfig '%s' not found in namespace '%s'",
proxy.Spec.ExternalAuthConfigRef.Name, proxy.Namespace),
ObservedGeneration: proxy.Generation,
})
return fmt.Errorf("MCPExternalAuthConfig '%s' not found in namespace '%s'",
proxy.Spec.ExternalAuthConfigRef.Name, proxy.Namespace)
}
meta.SetStatusCondition(&proxy.Status.Conditions, metav1.Condition{
Type: mcpv1alpha1.ConditionTypeMCPRemoteProxyExternalAuthConfigValidated,
Status: metav1.ConditionFalse,
Reason: mcpv1alpha1.ConditionReasonMCPRemoteProxyExternalAuthConfigFetchError,
Message: "Failed to fetch MCPExternalAuthConfig",
ObservedGeneration: proxy.Generation,
})
return fmt.Errorf("failed to fetch MCPExternalAuthConfig: %w", err)
}

if externalAuthConfig == nil {
return fmt.Errorf("MCPExternalAuthConfig %s not found", proxy.Spec.ExternalAuthConfigRef.Name)
}
// ExternalAuthConfig found and valid
meta.SetStatusCondition(&proxy.Status.Conditions, metav1.Condition{
Type: mcpv1alpha1.ConditionTypeMCPRemoteProxyExternalAuthConfigValidated,
Status: metav1.ConditionTrue,
Reason: mcpv1alpha1.ConditionReasonMCPRemoteProxyExternalAuthConfigValid,
Message: fmt.Sprintf("MCPExternalAuthConfig '%s' is valid", externalAuthConfig.Name),
ObservedGeneration: proxy.Generation,
})

if proxy.Status.ExternalAuthConfigHash != externalAuthConfig.Status.ConfigHash {
ctxLogger.Info("MCPExternalAuthConfig has changed, updating MCPRemoteProxy",
Expand Down
Loading
Loading