Skip to content

feat: propagate context through Runtime interface for cancellation support - #1288

Open
shwetha-s-poojary wants to merge 7 commits into
IBM:mainfrom
shwetha-s-poojary:propagate_context
Open

feat: propagate context through Runtime interface for cancellation support#1288
shwetha-s-poojary wants to merge 7 commits into
IBM:mainfrom
shwetha-s-poojary:propagate_context

Conversation

@shwetha-s-poojary

@shwetha-s-poojary shwetha-s-poojary commented Aug 19, 2026

Copy link
Copy Markdown
Member

Added ctx context.Context to all methods on the Runtime interface so that cancellation signals propagate correctly through the entire call chain.

Why each group changed:

  • runtime/interface.go + implementations (Podman, OpenShift) — core change; every method now accepts ctx so callers can cancel in-flight operations
  • application/podman & openshift (create.go, delete.go) — deployment path: ctx now cancels image pulls, pod creation, and readiness waits mid-flight
  • cli/podman/deploy.go, cli/helpers/helper.go — readiness wait loops; cancellation stops waiting immediately
  • image/ — image pull respects cancellation
  • catalog/apiserver/services/deployment/, deletion/ — API-triggered create/delete path
  • application/{podman,openshift} (info.go, logs.go, ps.go, start.go, stop.go) + catalog/cli/configure/podman reset functions + catalog/apiserver/services/sync — accept and propagate ctx from the cmd layer (cmd.Context()) so the full call chain is consistent

Validation:

  • Applications deployed and deleted via catalog — no regressions
  • Applications created and deleted via CLI — no regressions

Note: cmd.Context() currently behaves the same as context.Background() since OS signal wiring at the root command is not yet in place. This change establishes the correct plumbing so that when signal handling is added (tracked separately), cancellation will propagate end-to-end with no further changes required in the internal packages.

@mayuka-c mayuka-c left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shwetha-s-poojary Please ensure its thoroughly validated and there are no regressions

Comment thread ai-services/internal/pkg/application/openshift/info.go Outdated
Comment thread ai-services/internal/pkg/application/openshift/logs.go Outdated
Comment thread ai-services/internal/pkg/application/openshift/ps.go Outdated
Comment thread ai-services/internal/pkg/application/podman/info.go Outdated
Comment thread ai-services/internal/pkg/application/podman/logs.go Outdated
Comment thread ai-services/internal/pkg/catalog/apiserver/services/sync/openshift.go Outdated
Comment thread ai-services/internal/pkg/catalog/apiserver/services/sync/podman.go Outdated
Comment thread ai-services/internal/pkg/catalog/apiserver/services/sync/podman.go Outdated
Comment thread ai-services/internal/pkg/catalog/cli/configure/podman/reset_certificate.go Outdated
Comment thread ai-services/internal/pkg/catalog/cli/configure/podman/reset_password.go Outdated

@yussufsh yussufsh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we already have the ctx in the podman and openshift client why are we not using it? If we are passing in each func call then please remove it from the client struct.

@shwetha-s-poojary

Copy link
Copy Markdown
Member Author

Wondering if we already have the ctx in the podman and openshift client why are we not using it? If we are passing in each func call then please remove it from the client struct

If you are referring to pc.Context and ctx, pc.Context on the Podman client is not a cancellation context - it carries the Podman connection handle, we have podmanCtx() to merge it with the caller's ctx to get both the connection value and cancellation.We can't remove it IMO.

@shwetha-s-poojary
shwetha-s-poojary force-pushed the propagate_context branch 2 times, most recently from 3eab0b2 to 1e3b4d7 Compare August 25, 2026 05:13
…pport

Signed-off-by: shwetha-s-poojary <shwetha.s-poojary@ibm.com>
Signed-off-by: shwetha-s-poojary <shwetha.s-poojary@ibm.com>
Add ctx context.Context as first parameter to all Runtime interface
methods and update all implementations (openshift, podman, remote),
the worker dispatch table, and every call site across the codebase.

Signed-off-by: shwetha-s-poojary <shwetha.s-poojary@ibm.com>
Signed-off-by: shwetha-s-poojary <shwetha.s-poojary@ibm.com>
Signed-off-by: shwetha-s-poojary <shwetha.s-poojary@ibm.com>
Signed-off-by: shwetha-s-poojary <shwetha.s-poojary@ibm.com>
Signed-off-by: shwetha-s-poojary <shwetha.s-poojary@ibm.com>
Comment on lines +94 to +97
secretExistsFn := func(nameOrID string) (bool, error) { return rt.SecretExists(ctx, nameOrID) }
volumeExistsFn := func(nameOrID string) (bool, error) { return rt.VolumeExists(ctx, nameOrID) }

if msg := validateResourceExistence(ctx, expectedSecretNames, "secret", secretExistsFn); msg != "" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this need for func vars?
You can change the signature of validateResourceExistence() itself.

}

// Wait before next poll
time.Sleep(pollInterval)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor concern: This waits for 5 seconds even if ctx is cancelled in future. If a signal arrives mid-sleep, the process will hang for up to 5 seconds before the next iteration. Let's add a TODO if it's complex, or fix it now.

// This orchestrates: deployContext gets pod name and route info from templates,
// caddy.Context queries Caddy for route domains and HTTPS port.
func GetCatalogRouteInfo(rt *rt.PodmanClient) (map[string]string, string, error) {
func GetCatalogRouteInfo(ctx context.Context, rt *rt.PodmanClient) (map[string]string, string, error) { //nolint:revive

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why nolint?
Something related to previous code?


// HealthCheck verifies Caddy is running and accessible.
func (c *caddyManager) HealthCheck() error {
func (c *caddyManager) HealthCheck(ctx context.Context) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are missing adding client ctx for GetRouteByID and UnregisterRoute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants