-
Notifications
You must be signed in to change notification settings - Fork 309
feat: enhance Kubernetes client with watch functionality #1667
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the Kubernetes C# client with watch functionality by adding code generation support for watch operations. The implementation provides both callback-based and async enumerable patterns for watching Kubernetes resources.
- Adds watch operation code generation to client templates
- Introduces parameter filtering to exclude the "watch" parameter from generated methods
- Updates examples to demonstrate the new watch functionality
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
OperationsExtensions.cs.template | Adds watch operation generation with callback and async enumerable patterns |
Client.cs.template | Generates watch methods in client classes with filtered parameters |
TypeHelper.cs | Adds support for extracting single item types from list types |
ParamHelper.cs | Implements parameter filtering and watch-specific parameter handling |
KubernetesClient.Aot.csproj | Enables Watcher classes in AOT build |
Program.cs (examples) | Updates watch and clientset examples to use new API |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please also change e2e test and watcher related test?
and lets mark direct call to watch() deprecated, will be removed next version
…ling methods and add async enumerable support
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lqlive The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
I'm adding some unit tests for
|
…olete attribute formatting
@tg123 Please re-run CI. Yesterday I pulled the latest code |
… Obsolete attribute formatting
…ing TryGetItemTypeFromSchema method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall lgtm
lets close on weather hide bool watch
or watcherext
, then we can merge
/// <returns>IAsyncEnumerable of watch events</returns> | ||
[Obsolete("This method will be deprecated in future versions.")] | ||
public static IAsyncEnumerable<(WatchEventType, T)> WatchAsync<T, L>( | ||
this Task<HttpOperationResponse<L>> responseTask, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should not filter bool watch
in list at the moment
otherwise, this WatchExt cant work anymore for old code
so what do you think, make those internal
or keep compatible until next version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's best to just change it to internal
so we don't forget to remove it in a future version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @brendanburns for ideas
internal
it will create a big breaking change and users have to to migrate their code to new WatchXXX
do you think if it is nessary to wait one more big version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @brendanburns for ideas
internal
it will create a big breaking change and users have to to migrate their code to newWatchXXX
do you think if it is nessary to wait one more big version?
It seems that @ is wrong. It should be @brendandburns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
var listSchema = response?.Schema?.Reference; | ||
if (listSchema?.Properties?.TryGetValue("items", out var itemsProperty) != true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code attempts to access Properties
on Reference
which is incorrect. The Reference
property is a string reference to a schema definition, not the actual schema object. This should be accessing the resolved schema object instead of the reference.
var listSchema = response?.Schema?.Reference; | |
if (listSchema?.Properties?.TryGetValue("items", out var itemsProperty) != true) | |
// Resolve the schema reference to the actual schema object | |
var referencedSchema = response?.Schema?.ActualSchema; | |
if (referencedSchema?.Properties?.TryGetValue("items", out var itemsProperty) != true) |
Copilot uses AI. Check for mistakes.
…ributes; improve example method signature in Program.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
await client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(true); | ||
using var watcher = client.CoreV1.WatchListNamespacedPod("default", onEvent: (type, item) => { }); | ||
Assert.Equal(HttpVersion.Version20, handler.Version); | ||
await Task.CompletedTask.ConfigureAwait(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The statement await Task.CompletedTask.ConfigureAwait(true)
is unnecessary since Task.CompletedTask is already completed synchronously. This line can be removed.
await Task.CompletedTask.ConfigureAwait(true); |
Copilot uses AI. Check for mistakes.
var listSchema = response?.Schema?.Reference; | ||
if (listSchema?.Properties?.TryGetValue("items", out var itemsProperty) != true) | ||
{ | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method attempts to access Properties on a JsonReference object, but JsonReference doesn't have a Properties property. This will always return null. You should resolve the reference first to get the actual schema.
var listSchema = response?.Schema?.Reference; | |
if (listSchema?.Properties?.TryGetValue("items", out var itemsProperty) != true) | |
{ | |
return null; | |
} | |
// Resolve the reference to the actual schema before accessing Properties | |
var referencedSchema = response?.Schema?.Reference as JsonSchema; | |
if (referencedSchema == null) | |
{ | |
return null; | |
} | |
if (!referencedSchema.Properties.TryGetValue("items", out var itemsProperty)) | |
{ | |
return null; | |
} |
Copilot uses AI. Check for mistakes.
Base on #1662
@tg123 Hi ,This is my initial implementation. Could you help me see how much it differs from your ideas?
During my implementation, I thought of two issues:
1.Can the
ListNamespacedPodWithHttpMessagesAsync
method be set as protected or private to prevent external access?2.Replace the tuple
(WatchEventType, V1Pod)
inIAsyncEnumerable<(WatchEventType, V1Pod)>
with a new type, such as: