Skip to content

feat(api): add resource topology endpoint for propagation chain visua…#493

Closed
SunsetB612 wants to merge 1 commit intokarmada-io:mainfrom
SunsetB612:feat/resource-topology-api
Closed

feat(api): add resource topology endpoint for propagation chain visua…#493
SunsetB612 wants to merge 1 commit intokarmada-io:mainfrom
SunsetB612:feat/resource-topology-api

Conversation

@SunsetB612
Copy link
Copy Markdown
Contributor

No description provided.

…lization

Signed-off-by: SunsetB612 <10235101575@stu.ecnu.edu.cn>
@karmada-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign rainbowmango for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Apr 8, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a resource topology feature to trace workload propagation from the Karmada control plane to member clusters. It includes a new API endpoint, shared informers with custom indexers for efficient resource lookups, and logic to construct a topology graph. Feedback focuses on improving performance by parallelizing synchronous API calls to member clusters, ensuring proper context propagation for request cancellation, and extending health check logic to support all workload types beyond Deployments.

resp.Edges = append(resp.Edges, TopologyEdge{Source: rbNodeID, Target: workNodeID})

// Step 4: Get member cluster workload status
memberStatus := getMemberWorkloadStatus(ctx, clusterName, namespace, name, kind)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Performing synchronous API calls to member clusters within a loop can lead to significant performance degradation, especially when a resource is propagated to a large number of clusters. This could cause the API request to time out. Consider fetching member cluster statuses in parallel using goroutines or an errgroup.

return
}

result, err := topology.GetResourceTopology(k8sClient, namespace, name, kind)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The request context should be passed to GetResourceTopology to ensure that downstream operations (like network calls to member clusters) can be cancelled if the client disconnects or the request times out.

Suggested change
result, err := topology.GetResourceTopology(k8sClient, namespace, name, kind)
result, err := topology.GetResourceTopology(c.Request.Context(), k8sClient, namespace, name, kind)

}
return NodeStatusProgressing
default:
return NodeStatusHealthy
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This default case returns NodeStatusHealthy for all resource types other than Deployment. Since getWorkload supports StatefulSet, DaemonSet, Job, and CronJob, this function should also implement health checks for those types to avoid providing misleading status information in the topology graph.

Comment on lines +26 to +29
func GetResourceTopology(
k8sClient kubeclient.Interface,
namespace, name, kind string) (*TopologyResponse, error) {
return traceChain(context.TODO(), k8sClient, namespace, name, kind)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The GetResourceTopology function should accept a context.Context instead of using context.TODO(). This allows the function to respect the lifecycle of the incoming API request.

func GetResourceTopology(
	ctx context.Context,
	k8sClient kubeclient.Interface,
	namespace, name, kind string) (*TopologyResponse, error) {
	return traceChain(ctx, k8sClient, namespace, name, kind)

@SunsetB612 SunsetB612 closed this Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants