-
Notifications
You must be signed in to change notification settings - Fork 0
feat: AddOrUpdate sets ApiVersion/Kind if not set #157
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,94 +1,94 @@ | ||||||||
| using System.Runtime.Serialization; | ||||||||
| using System.Text.Json; | ||||||||
| using System.Text.Json.Serialization; | ||||||||
|
|
||||||||
| namespace Function.SDK.CSharp.Models; | ||||||||
|
|
||||||||
| public sealed class V1ConversionReview | ||||||||
| { | ||||||||
| public const string KubeApiVersion = "v1"; | ||||||||
| public const string KubeKind = "ConversionReview"; | ||||||||
| public const string KubeGroup = "apiextensions.k8s.io"; | ||||||||
|
|
||||||||
| [JsonPropertyName("apiVersion")] | ||||||||
| public string ApiVersion { get; set; } = KubeGroup + "/" + KubeApiVersion; | ||||||||
|
|
||||||||
| [JsonPropertyName("kind")] | ||||||||
| public string Kind { get; set; } = KubeKind; | ||||||||
|
|
||||||||
| [JsonPropertyName("request")] | ||||||||
| public V1ConversionReviewRequest Request { get; set; } | ||||||||
|
|
||||||||
| [JsonPropertyName("response")] | ||||||||
| public V1ConversionReviewResponse Response { get; set; } = new(); | ||||||||
| } | ||||||||
|
|
||||||||
| public sealed class V1ConversionReviewRequest | ||||||||
| { | ||||||||
| /// <summary> | ||||||||
| /// Random uid uniquely identifying this conversion call | ||||||||
| /// </summary> | ||||||||
| [JsonPropertyName("uid")] | ||||||||
| public string Uid { get; set; } = default!; | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// The API group and version the objects should be converted to | ||||||||
| /// </summary> | ||||||||
| [JsonPropertyName("desiredAPIVersion")] | ||||||||
| public string DesiredApiVersion { get; set; } = default!; | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// # The list of objects to convert. May contain one or more objects, in one or more versions. | ||||||||
| /// </summary> | ||||||||
| [JsonPropertyName("objects")] | ||||||||
| public JsonElement[] Objects { get; set; } = default!; | ||||||||
| } | ||||||||
|
|
||||||||
| public sealed class V1ConversionReviewResponse | ||||||||
| { | ||||||||
| /// <summary> | ||||||||
| /// Must match <request.uid> | ||||||||
| /// </summary> | ||||||||
| [JsonPropertyName("uid")] | ||||||||
| public string Uid { get; set; } = ""; | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// Objects must match the order of request.objects, and have apiVersion set to <request.desiredAPIVersion>. | ||||||||
| /// kind, metadata.uid, metadata.name, and metadata.namespace fields must not be changed by the webhook. | ||||||||
| /// metadata.labels and metadata.annotations fields may be changed by the webhook. | ||||||||
| /// All other changes to metadata fields by the webhook are ignored. | ||||||||
| /// </summary> | ||||||||
| [JsonPropertyName("convertedObjects")] | ||||||||
| public List<JsonElement> ConvertedObjects { get; set; } = []; | ||||||||
|
|
||||||||
| [JsonPropertyName("result")] | ||||||||
| public V1ConversionReviewResponseStatus Result { get; set; } = new(); | ||||||||
| } | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// Webhook Response Status | ||||||||
| /// </summary> | ||||||||
| public enum V1ConversionReviewResponseStatusEnum | ||||||||
| { | ||||||||
| ///<summary>Success</summary> | ||||||||
| [EnumMember(Value = "Success"), JsonStringEnumMemberName("Success")] | ||||||||
| Success, | ||||||||
| ///<summary>Failure</summary> | ||||||||
| [EnumMember(Value = "Failure"), JsonStringEnumMemberName("Failure")] | ||||||||
| Failure, | ||||||||
| } | ||||||||
|
|
||||||||
| public sealed class V1ConversionReviewResponseStatus | ||||||||
| { | ||||||||
| [JsonPropertyName("status")] | ||||||||
| public V1ConversionReviewResponseStatusEnum Status { get; set; } | ||||||||
|
|
||||||||
| [JsonPropertyName("message")] | ||||||||
| public string? Message { get; set; } | ||||||||
|
|
||||||||
| [JsonPropertyName("reason")] | ||||||||
| public string? Reason { get; set; } | ||||||||
|
|
||||||||
| [JsonPropertyName("code")] | ||||||||
| public int Code { get; set; } = 200; | ||||||||
| using System.Runtime.Serialization; | ||||||||
| using System.Text.Json; | ||||||||
| using System.Text.Json.Serialization; | ||||||||
| namespace Function.SDK.CSharp.Models; | ||||||||
| public sealed class V1ConversionReview | ||||||||
|
Check warning on line 7 in src/Function.SDK.CSharp/Models/V1ConversionReview.cs
|
||||||||
| { | ||||||||
| public const string KubeApiVersion = "v1"; | ||||||||
|
Check warning on line 9 in src/Function.SDK.CSharp/Models/V1ConversionReview.cs
|
||||||||
| public const string KubeKind = "ConversionReview"; | ||||||||
|
Check warning on line 10 in src/Function.SDK.CSharp/Models/V1ConversionReview.cs
|
||||||||
| public const string KubeGroup = "apiextensions.k8s.io"; | ||||||||
|
Check warning on line 11 in src/Function.SDK.CSharp/Models/V1ConversionReview.cs
|
||||||||
| [JsonPropertyName("apiVersion")] | ||||||||
| public string ApiVersion { get; set; } = KubeGroup + "/" + KubeApiVersion; | ||||||||
|
Check warning on line 14 in src/Function.SDK.CSharp/Models/V1ConversionReview.cs
|
||||||||
| [JsonPropertyName("kind")] | ||||||||
| public string Kind { get; set; } = KubeKind; | ||||||||
|
Check warning on line 17 in src/Function.SDK.CSharp/Models/V1ConversionReview.cs
|
||||||||
| [JsonPropertyName("request")] | ||||||||
| public V1ConversionReviewRequest Request { get; set; } | ||||||||
|
Check warning on line 20 in src/Function.SDK.CSharp/Models/V1ConversionReview.cs
|
||||||||
|
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. Address the non-nullable property initialization warning. The Proposed fixesOption 1 (recommended): Use the [JsonPropertyName("request")]
-public V1ConversionReviewRequest Request { get; set; }
+public required V1ConversionReviewRequest Request { get; set; }Option 2: Make the property nullable if it's optional [JsonPropertyName("request")]
-public V1ConversionReviewRequest Request { get; set; }
+public V1ConversionReviewRequest? Request { get; set; }Option 3: Add a default value with null-forgiving operator [JsonPropertyName("request")]
-public V1ConversionReviewRequest Request { get; set; }
+public V1ConversionReviewRequest Request { get; set; } = default!;📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: PR Build & Test / 0_build-test _ Build & Test.txt[warning] 20-20: CS1591: Missing XML comment for publicly visible type or member 'V1ConversionReview.Request'. [warning] 20-20: CS8618: Non-nullable property 'Request' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable. 🪛 GitHub Actions: PR Build & Test / build-test _ Build & Test[warning] 20-20: warning CS8618: Non-nullable property 'Request' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable. (net9.0) [warning] 20-20: warning CS1591: Missing XML comment for publicly visible type or member 'V1ConversionReview.Request' (net9.0) [warning] 20-20: warning CS8618: Non-nullable property 'Request' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable. (net10.0) [warning] 20-20: warning CS1591: Missing XML comment for publicly visible type or member 'V1ConversionReview.Request' (net10.0) 🪛 GitHub Check: build-test / Build & Test[warning] 20-20: [warning] 20-20: [warning] 20-20: 🤖 Prompt for AI Agents |
||||||||
| [JsonPropertyName("response")] | ||||||||
| public V1ConversionReviewResponse Response { get; set; } = new(); | ||||||||
| } | ||||||||
| public sealed class V1ConversionReviewRequest | ||||||||
| { | ||||||||
| /// <summary> | ||||||||
| /// Random uid uniquely identifying this conversion call | ||||||||
| /// </summary> | ||||||||
| [JsonPropertyName("uid")] | ||||||||
| public string Uid { get; set; } = default!; | ||||||||
| /// <summary> | ||||||||
| /// The API group and version the objects should be converted to | ||||||||
| /// </summary> | ||||||||
| [JsonPropertyName("desiredAPIVersion")] | ||||||||
| public string DesiredApiVersion { get; set; } = default!; | ||||||||
| /// <summary> | ||||||||
| /// # The list of objects to convert. May contain one or more objects, in one or more versions. | ||||||||
| /// </summary> | ||||||||
| [JsonPropertyName("objects")] | ||||||||
| public JsonElement[] Objects { get; set; } = default!; | ||||||||
| } | ||||||||
| public sealed class V1ConversionReviewResponse | ||||||||
| { | ||||||||
| /// <summary> | ||||||||
| /// Must match <request.uid> | ||||||||
| /// </summary> | ||||||||
| [JsonPropertyName("uid")] | ||||||||
| public string Uid { get; set; } = ""; | ||||||||
| /// <summary> | ||||||||
| /// Objects must match the order of request.objects, and have apiVersion set to <request.desiredAPIVersion>. | ||||||||
| /// kind, metadata.uid, metadata.name, and metadata.namespace fields must not be changed by the webhook. | ||||||||
| /// metadata.labels and metadata.annotations fields may be changed by the webhook. | ||||||||
| /// All other changes to metadata fields by the webhook are ignored. | ||||||||
| /// </summary> | ||||||||
| [JsonPropertyName("convertedObjects")] | ||||||||
| public List<JsonElement> ConvertedObjects { get; set; } = []; | ||||||||
| [JsonPropertyName("result")] | ||||||||
| public V1ConversionReviewResponseStatus Result { get; set; } = new(); | ||||||||
| } | ||||||||
| /// <summary> | ||||||||
| /// Webhook Response Status | ||||||||
| /// </summary> | ||||||||
| public enum V1ConversionReviewResponseStatusEnum | ||||||||
| { | ||||||||
| ///<summary>Success</summary> | ||||||||
| [EnumMember(Value = "Success"), JsonStringEnumMemberName("Success")] | ||||||||
| Success, | ||||||||
| ///<summary>Failure</summary> | ||||||||
| [EnumMember(Value = "Failure"), JsonStringEnumMemberName("Failure")] | ||||||||
| Failure, | ||||||||
| } | ||||||||
| public sealed class V1ConversionReviewResponseStatus | ||||||||
| { | ||||||||
| [JsonPropertyName("status")] | ||||||||
| public V1ConversionReviewResponseStatusEnum Status { get; set; } | ||||||||
| [JsonPropertyName("message")] | ||||||||
| public string? Message { get; set; } | ||||||||
| [JsonPropertyName("reason")] | ||||||||
| public string? Reason { get; set; } | ||||||||
| [JsonPropertyName("code")] | ||||||||
| public int Code { get; set; } = 200; | ||||||||
| } | ||||||||
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.
Add null checks and error handling.
The method lacks defensive checks:
resourceparameterresource.Resource_These omissions can cause unhandled exceptions at runtime.
🛡️ Proposed fix with null checks and error handling
public static T GetKubeResource<T>(this Resource resource) { + if (resource == null) + throw new ArgumentNullException(nameof(resource)); + + if (resource.Resource_ == null) + throw new InvalidOperationException("Resource.Resource_ is null"); + + try + { var json = JsonFormatter.Default.Format(resource.Resource_); - return KubernetesJson.Deserialize<T>(json); + } + catch (Exception ex) + { + throw new InvalidOperationException($"Failed to deserialize resource to type {typeof(T).Name}", ex); + } }🤖 Prompt for AI Agents