-
Notifications
You must be signed in to change notification settings - Fork 115
Thv registry deploy from controller #1931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jhrozek
wants to merge
14
commits into
main
Choose a base branch
from
thv-registry-deploy-from-controller
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ae56170
Add a service account and RBAC permissions for thv-registry-api
jhrozek 4a0fea3
Explicitly annotate mcpregistry controller to create deployments and …
jhrozek 7b32796
Optionally push the registry-api server to the kind cluster
jhrozek 8175b58
Create the deployment
jhrozek 560c59c
Create the service
jhrozek 6fe036d
Actually deploy the service and the deployment
jhrozek bd67810
fix lint
jhrozek 9607d0b
actually deploy fix
jhrozek 9d2cdb0
Replace DEPLOY_REGISTRY_API with ENABLE_EXPERIMENTAL_FEATURES
jhrozek e834e3e
Refactor registry-api deployment into a separate package
jhrozek 27ae78f
Regenerate helm docs
jhrozek 8fee475
Bump charts
jhrozek 79311d1
Reduce duplication with helper methods to get storage name and resour…
jhrozek f9db469
Consolidate constants
jhrozek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in general, I'd move the functions to deploy the registry API to a dedicated package There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in this push |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Package mcpregistrystatus provides status management and batched updates for MCPRegistry resources. | ||
package mcpregistrystatus | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
|
||
mcpv1alpha1 "github.com/stacklok/toolhive/cmd/thv-operator/api/v1alpha1" | ||
) | ||
|
||
// StatusCollector collects status changes during reconciliation | ||
// and applies them in a single batch update at the end. | ||
// It implements the Collector interface. | ||
type StatusCollector struct { | ||
mcpRegistry *mcpv1alpha1.MCPRegistry | ||
hasChanges bool | ||
phase *mcpv1alpha1.MCPRegistryPhase | ||
message *string | ||
apiEndpoint *string | ||
conditions map[string]metav1.Condition | ||
} | ||
|
||
// NewCollector creates a new status update collector for the given MCPRegistry resource. | ||
func NewCollector(mcpRegistry *mcpv1alpha1.MCPRegistry) Collector { | ||
return &StatusCollector{ | ||
mcpRegistry: mcpRegistry, | ||
conditions: make(map[string]metav1.Condition), | ||
} | ||
} | ||
|
||
// SetPhase sets the phase to be updated. | ||
func (s *StatusCollector) SetPhase(phase mcpv1alpha1.MCPRegistryPhase) { | ||
s.phase = &phase | ||
s.hasChanges = true | ||
} | ||
|
||
// SetMessage sets the message to be updated. | ||
func (s *StatusCollector) SetMessage(message string) { | ||
s.message = &message | ||
s.hasChanges = true | ||
} | ||
|
||
// SetAPIEndpoint sets the API endpoint to be updated. | ||
func (s *StatusCollector) SetAPIEndpoint(endpoint string) { | ||
s.apiEndpoint = &endpoint | ||
s.hasChanges = true | ||
} | ||
|
||
// SetAPIReadyCondition adds or updates the API ready condition. | ||
func (s *StatusCollector) SetAPIReadyCondition(reason, message string, status metav1.ConditionStatus) { | ||
s.conditions[mcpv1alpha1.ConditionAPIReady] = metav1.Condition{ | ||
Type: mcpv1alpha1.ConditionAPIReady, | ||
Status: status, | ||
Reason: reason, | ||
Message: message, | ||
} | ||
s.hasChanges = true | ||
} | ||
|
||
// Apply applies all collected status changes in a single batch update. | ||
func (s *StatusCollector) Apply(ctx context.Context, statusWriter client.StatusWriter) error { | ||
if !s.hasChanges { | ||
return nil | ||
} | ||
|
||
ctxLogger := log.FromContext(ctx) | ||
|
||
// Apply phase change | ||
if s.phase != nil { | ||
s.mcpRegistry.Status.Phase = *s.phase | ||
} | ||
|
||
// Apply message change | ||
if s.message != nil { | ||
s.mcpRegistry.Status.Message = *s.message | ||
} | ||
|
||
// Apply API endpoint change | ||
if s.apiEndpoint != nil { | ||
s.mcpRegistry.Status.APIEndpoint = *s.apiEndpoint | ||
} | ||
|
||
// Apply condition changes | ||
for _, condition := range s.conditions { | ||
meta.SetStatusCondition(&s.mcpRegistry.Status.Conditions, condition) | ||
} | ||
|
||
// Single status update | ||
if err := statusWriter.Update(ctx, s.mcpRegistry); err != nil { | ||
ctxLogger.Error(err, "Failed to apply batched status update") | ||
return fmt.Errorf("failed to apply batched status update: %w", err) | ||
} | ||
|
||
ctxLogger.V(1).Info("Applied batched status update", | ||
"phase", s.phase, | ||
"message", s.message, | ||
"conditionsCount", len(s.conditions)) | ||
|
||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Package mcpregistrystatus provides status management for MCPRegistry resources. | ||
package mcpregistrystatus | ||
|
||
import ( | ||
"context" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
mcpv1alpha1 "github.com/stacklok/toolhive/cmd/thv-operator/api/v1alpha1" | ||
) | ||
|
||
// Collector defines the interface for collecting MCPRegistry status updates. | ||
// It provides methods to collect status changes during reconciliation | ||
// and apply them in a single batch update at the end. | ||
type Collector interface { | ||
// SetAPIReadyCondition sets the API ready condition with the specified reason, message, and status | ||
SetAPIReadyCondition(reason, message string, status metav1.ConditionStatus) | ||
|
||
// SetAPIEndpoint sets the API endpoint in the status | ||
SetAPIEndpoint(endpoint string) | ||
|
||
// SetPhase sets the MCPRegistry phase in the status | ||
SetPhase(phase mcpv1alpha1.MCPRegistryPhase) | ||
|
||
// SetMessage sets the status message | ||
SetMessage(message string) | ||
|
||
// Apply applies all collected status changes in a single batch update | ||
Apply(ctx context.Context, statusWriter client.StatusWriter) error | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.