-
Notifications
You must be signed in to change notification settings - Fork 645
feat(substrate): bump agent substrate to 0.0.7 #2109
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -14,11 +14,13 @@ import ( | |
| "strings" | ||
| "time" | ||
|
|
||
| atev1alpha1 "github.com/agent-substrate/substrate/pkg/api/v1alpha1" | ||
| "github.com/hashicorp/go-multierror" | ||
| reconcilerutils "github.com/kagent-dev/kagent/go/core/internal/controller/reconciler/utils" | ||
| "github.com/kagent-dev/kagent/go/core/internal/controller/translator" | ||
| "github.com/kagent-dev/kagent/go/core/pkg/egress" | ||
| "github.com/kagent-dev/kagent/go/core/pkg/sandboxbackend" | ||
| "github.com/kagent-dev/kagent/go/core/pkg/sandboxbackend/substrate" | ||
| "github.com/kagent-dev/kmcp/api/v1alpha1" | ||
| appsv1 "k8s.io/api/apps/v1" | ||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
|
|
@@ -150,11 +152,19 @@ func (a *kagentReconciler) ReconcileKagentSandboxAgent(ctx context.Context, req | |
| } | ||
|
|
||
| err := a.reconcileSandboxAgent(ctx, sandboxAgent) | ||
| if errors.Is(err, substrate.ErrActorTemplateReconcilePending) { | ||
| // A spec-drift recreate is mid-flight; report not-ready without failing | ||
| // the resource and return the sentinel so the controller requeues. | ||
| if statusErr := a.reconcileSandboxAgentStatus(ctx, sandboxAgent, nil, true); statusErr != nil { | ||
| return statusErr | ||
| } | ||
| return err | ||
| } | ||
| if err != nil { | ||
| reconcileLog.Error(err, "failed to reconcile sandboxagent", "sandboxagent", req.NamespacedName) | ||
| } | ||
|
|
||
| return a.reconcileSandboxAgentStatus(ctx, sandboxAgent, err) | ||
| return a.reconcileSandboxAgentStatus(ctx, sandboxAgent, err, false) | ||
| } | ||
|
|
||
| func (a *kagentReconciler) handleDeletedAgentResource(ctx context.Context, req ctrl.Request, resourceName string) error { | ||
|
|
@@ -239,14 +249,18 @@ func (a *kagentReconciler) reconcileSandboxAgent(ctx context.Context, sa *v1alph | |
| }) | ||
| } | ||
|
|
||
| func (a *kagentReconciler) reconcileSandboxAgentStatus(ctx context.Context, sa *v1alpha2.SandboxAgent, reconcileErr error) error { | ||
| func (a *kagentReconciler) reconcileSandboxAgentStatus(ctx context.Context, sa *v1alpha2.SandboxAgent, reconcileErr error, actorTemplatePending bool) error { | ||
| deployedCondition := metav1.Condition{ | ||
| Type: v1alpha2.AgentConditionTypeReady, | ||
| Status: metav1.ConditionUnknown, | ||
| ObservedGeneration: sa.Generation, | ||
| } | ||
|
|
||
| if a.sandboxBackend == nil { | ||
| if actorTemplatePending { | ||
| deployedCondition.Status = metav1.ConditionFalse | ||
| deployedCondition.Reason = "ActorTemplateRecreating" | ||
| deployedCondition.Message = "waiting for ActorTemplate golden actor deletion and recreate" | ||
| } else if a.sandboxBackend == nil { | ||
| deployedCondition.Status = metav1.ConditionUnknown | ||
| deployedCondition.Reason = "SandboxBackendNotConfigured" | ||
| deployedCondition.Message = "Sandbox backend is not configured" | ||
|
|
@@ -924,12 +938,31 @@ func (r *kagentReconciler) GetOwnedResourceTypes() []client.Object { | |
| // Function initially copied from https://github.com/open-telemetry/opentelemetry-operator/blob/e6d96f006f05cff0bc3808da1af69b6b636fbe88/internal/controllers/common.go#L141-L192 | ||
| func (a *kagentReconciler) reconcileDesiredObjects(ctx context.Context, owner metav1.Object, desiredObjects []client.Object, ownedObjects map[types.UID]client.Object) error { | ||
| var errs []error | ||
| actorTemplatePending := false | ||
| for _, desired := range desiredObjects { | ||
| l := reconcileLog.WithValues( | ||
| "object_name", desired.GetName(), | ||
| "object_kind", desired.GetObjectKind(), | ||
| ) | ||
|
|
||
| // Substrate ActorTemplate.spec is immutable, delegate to the sandbox backend to handle spec drift. | ||
|
Contributor
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. We should separate these controllers in a follow-up, this is too specific to combine with the existing behavior IMO |
||
| if _, ok := desired.(*atev1alpha1.ActorTemplate); ok { | ||
| if r, ok := a.sandboxBackend.(actorTemplateReconciler); ok { | ||
| if err := r.ReconcileActorTemplate(ctx, desired); err != nil { | ||
| if errors.Is(err, substrate.ErrActorTemplateReconcilePending) { | ||
| actorTemplatePending = true | ||
| pruneOwnedActorTemplate(ownedObjects, desired) | ||
| continue | ||
| } | ||
| l.Error(err, "failed to reconcile ActorTemplate") | ||
| errs = append(errs, err) | ||
| continue | ||
| } | ||
| pruneOwnedActorTemplate(ownedObjects, desired) | ||
| continue | ||
| } | ||
| } | ||
|
|
||
| // existing is an object the controller runtime will hydrate for us | ||
| // we obtain the existing object by deep copying the desired object because it's the most convenient way | ||
| existing := desired.DeepCopyObject().(client.Object) | ||
|
|
@@ -951,6 +984,9 @@ func (a *kagentReconciler) reconcileDesiredObjects(ctx context.Context, owner me | |
| if len(errs) > 0 { | ||
| return fmt.Errorf("failed to create objects for %s: %w", owner.GetName(), errors.Join(errs...)) | ||
| } | ||
| if actorTemplatePending { | ||
| return substrate.ErrActorTemplateReconcilePending | ||
| } | ||
|
|
||
| // Pruning owned objects in the cluster which are not should not be present after the reconciliation. | ||
| err := a.deleteObjects(ctx, ownedObjects) | ||
|
|
@@ -961,6 +997,25 @@ func (a *kagentReconciler) reconcileDesiredObjects(ctx context.Context, owner me | |
| return nil | ||
| } | ||
|
|
||
| // actorTemplateReconciler is implemented by sandbox backends that own substrate | ||
| // ActorTemplate objects and need immutable-spec aware create/recreate semantics. | ||
| type actorTemplateReconciler interface { | ||
| ReconcileActorTemplate(ctx context.Context, desired client.Object) error | ||
| } | ||
|
|
||
| // pruneOwnedActorTemplate removes the live ActorTemplate matching desired from the | ||
| // prune set so it is not garbage collected. | ||
| func pruneOwnedActorTemplate(owned map[types.UID]client.Object, desired client.Object) { | ||
| for uid, obj := range owned { | ||
| if _, ok := obj.(*atev1alpha1.ActorTemplate); !ok { | ||
| continue | ||
| } | ||
| if obj.GetName() == desired.GetName() && obj.GetNamespace() == desired.GetNamespace() { | ||
| delete(owned, uid) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // modified version of controllerutil.CreateOrUpdate to support proto based objects like istio | ||
| func createOrUpdate(ctx context.Context, c client.Client, obj client.Object, f controllerutil.MutateFn) (controllerutil.OperationResult, error) { | ||
| key := client.ObjectKeyFromObject(obj) | ||
|
|
||
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
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
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
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.