Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion examples/csrApproval/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ string GenerateCertificate(string name)

var replace = new List<V1CertificateSigningRequestCondition>
{
new ("True", "Approved", DateTime.UtcNow, DateTime.UtcNow, "This certificate was approved by k8s client", "Approve"),
new V1CertificateSigningRequestCondition
{
Type = "Approved",
Status = "True",
Reason = "Approve",
Message = "This certificate was approved by k8s client",
LastUpdateTime = DateTime.UtcNow,
LastTransitionTime = DateTime.UtcNow,
},
};
readCert.Status.Conditions = replace;

Expand Down
4 changes: 2 additions & 2 deletions examples/customResource/cResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public override string ToString()
}
}

public class CResourceSpec
public record CResourceSpec
{
[JsonPropertyName("cityName")]
public string CityName { get; set; }
}

public class CResourceStatus : V1Status
public record CResourceStatus : V1Status
{
[JsonPropertyName("temperature")]
public string Temperature { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion examples/resize/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{
Requests = new Dictionary<string, ResourceQuantity>()
{
["cpu"] = new ResourceQuantity("100m"),
["cpu"] = "100m",
},
},
},
Expand Down
4 changes: 1 addition & 3 deletions src/KubernetesClient.Aot/KubernetesClient.Aot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
<Compile Include="..\KubernetesClient\IMetadata.cs" />
<Compile Include="..\KubernetesClient\Models\IntOrStringJsonConverter.cs" />
<Compile Include="..\KubernetesClient\Models\IntOrStringYamlConverter.cs" />
<Compile Include="..\KubernetesClient\Models\IntstrIntOrString.cs" />
<Compile Include="..\KubernetesClient\Models\IntOrString.cs" />
<Compile Include="..\KubernetesClient\ISpec.cs" />
<Compile Include="..\KubernetesClient\IStatus.cs" />
<Compile Include="..\KubernetesClient\IValidate.cs" />
<Compile Include="..\KubernetesClient\Models\KubernetesEntityAttribute.cs" />
<Compile Include="..\KubernetesClient\Models\KubernetesList.cs" />
<Compile Include="..\KubernetesClient\KubernetesObject.cs" />
<Compile Include="..\KubernetesClient\Models\ModelExtensions.cs" />
<Compile Include="..\KubernetesClient\Models\ModelVersionConverter.cs" />
<Compile Include="..\KubernetesClient\Models\NodeMetrics.cs" />
<Compile Include="..\KubernetesClient\Models\NodeMetricsList.cs" />
<Compile Include="..\KubernetesClient\Models\PodMetrics.cs" />
Expand Down
5 changes: 5 additions & 0 deletions src/KubernetesClient.Classic/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// IntOrString.cs(7,36): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit { }

Check warning on line 4 in src/KubernetesClient.Classic/IsExternalInit.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 4 in src/KubernetesClient.Classic/IsExternalInit.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

}
4 changes: 1 addition & 3 deletions src/KubernetesClient.Classic/KubernetesClient.Classic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@
<Compile Include="..\KubernetesClient\IMetadata.cs" />
<Compile Include="..\KubernetesClient\Models\IntOrStringJsonConverter.cs" />
<Compile Include="..\KubernetesClient\Models\IntOrStringYamlConverter.cs" />
<Compile Include="..\KubernetesClient\Models\IntstrIntOrString.cs" />
<Compile Include="..\KubernetesClient\Models\IntOrString.cs" />
<Compile Include="..\KubernetesClient\ISpec.cs" />
<Compile Include="..\KubernetesClient\IStatus.cs" />
<Compile Include="..\KubernetesClient\IValidate.cs" />
<Compile Include="..\KubernetesClient\Models\KubernetesEntityAttribute.cs" />
<Compile Include="..\KubernetesClient\KubernetesJson.cs" />
<Compile Include="..\KubernetesClient\Models\KubernetesList.cs" />
<Compile Include="..\KubernetesClient\KubernetesObject.cs" />
<Compile Include="..\KubernetesClient\KubernetesYaml.cs" />
<Compile Include="..\KubernetesClient\Models\ModelExtensions.cs" />
<Compile Include="..\KubernetesClient\Models\ModelVersionConverter.cs" />
<Compile Include="..\KubernetesClient\Models\NodeMetrics.cs" />
<Compile Include="..\KubernetesClient\Models\NodeMetricsList.cs" />
<Compile Include="..\KubernetesClient\Models\PodMetrics.cs" />
Expand Down
13 changes: 0 additions & 13 deletions src/KubernetesClient/IValidate.cs

This file was deleted.

40 changes: 40 additions & 0 deletions src/KubernetesClient/Models/IntOrString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Globalization;

namespace k8s.Models
{
[JsonConverter(typeof(IntOrStringJsonConverter))]
public struct IntOrString
{
public string Value { get; private init; }

public static implicit operator IntOrString(int v)
{
return Convert.ToString(v);
}

public static implicit operator IntOrString(long v)
{
return Convert.ToString(v);
}

public static implicit operator string(IntOrString v)
{
return v.Value;
}

public static implicit operator IntOrString(string v)
{
return new IntOrString { Value = v };
}

public override string ToString()
{
return Value;
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

ToString() can return null when Value is null, which may cause issues for consumers expecting a non-null string. Consider returning string.Empty or a default value when Value is null.

Suggested change
return Value;
return Value ?? string.Empty;

Copilot uses AI. Check for mistakes.

}

public int ToInt()
{
return int.Parse(Value, CultureInfo.InvariantCulture);
}
}
}
8 changes: 4 additions & 4 deletions src/KubernetesClient/Models/IntOrStringJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace k8s.Models
{
internal sealed class IntOrStringJsonConverter : JsonConverter<IntstrIntOrString>
internal sealed class IntOrStringJsonConverter : JsonConverter<IntOrString>
{
public override IntstrIntOrString Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override IntOrString Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
switch (reader.TokenType)
{
Expand All @@ -17,14 +17,14 @@ public override IntstrIntOrString Read(ref Utf8JsonReader reader, Type typeToCon
throw new NotSupportedException();
}

public override void Write(Utf8JsonWriter writer, IntstrIntOrString value, JsonSerializerOptions options)
public override void Write(Utf8JsonWriter writer, IntOrString value, JsonSerializerOptions options)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}

var s = value?.Value;
var s = value.Value;

if (long.TryParse(s, out var intv))
{
Expand Down
8 changes: 4 additions & 4 deletions src/KubernetesClient/Models/IntOrStringYamlConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class IntOrStringYamlConverter : IYamlTypeConverter
{
public bool Accepts(Type type)
{
return type == typeof(IntstrIntOrString);
return type == typeof(IntOrString);
}

public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
Expand All @@ -21,7 +21,7 @@ public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeseria
return null;
}

return new IntstrIntOrString(scalar?.Value);
return scalar?.Value;
}
finally
{
Expand All @@ -34,8 +34,8 @@ public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeseria

public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer)
{
var obj = (IntstrIntOrString)value;
emitter?.Emit(new YamlDotNet.Core.Events.Scalar(obj?.Value));
var obj = (IntOrString)value;
emitter?.Emit(new YamlDotNet.Core.Events.Scalar(obj.Value));
}
}
}
56 changes: 0 additions & 56 deletions src/KubernetesClient/Models/IntstrIntOrString.cs

This file was deleted.

19 changes: 0 additions & 19 deletions src/KubernetesClient/Models/KubernetesList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,5 @@ public KubernetesList(IList<T> items, string apiVersion = default, string kind =
/// </summary>
[JsonPropertyName("metadata")]
public V1ListMeta Metadata { get; set; }

/// <summary>
/// Validate the object.
/// </summary>
public void Validate()
{
if (Items == null)
{
throw new ArgumentNullException("Items");
}

if (Items != null)
{
foreach (var element in Items.OfType<IValidate>())
{
element.Validate();
}
}
}
}
}
21 changes: 0 additions & 21 deletions src/KubernetesClient/Models/ModelVersionConverter.cs

This file was deleted.

49 changes: 10 additions & 39 deletions src/KubernetesClient/Models/ResourceQuantity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace k8s.Models
/// cause implementors to also use a fixed point implementation.
/// </summary>
[JsonConverter(typeof(ResourceQuantityJsonConverter))]
public partial class ResourceQuantity
public struct ResourceQuantity
{
public enum SuffixFormat
{
Expand Down Expand Up @@ -97,39 +97,6 @@ public override string ToString()
return CanonicalizeString();
}

protected bool Equals(ResourceQuantity other)
{
return _unitlessValue.Equals(other?._unitlessValue);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}

if (ReferenceEquals(this, obj))
{
return true;
}

if (obj.GetType() != GetType())
{
return false;
}

return Equals((ResourceQuantity)obj);
}

public override int GetHashCode()
{
unchecked
{
return ((int)Format * 397) ^ _unitlessValue.GetHashCode();
}
}

//
// CanonicalizeString = go version CanonicalizeBytes
// CanonicalizeBytes returns the canonical form of q and its suffix (see comment on Quantity).
Expand Down Expand Up @@ -157,18 +124,17 @@ public string CanonicalizeString(SuffixFormat suffixFormat)
return Suffixer.AppendMaxSuffix(_unitlessValue, suffixFormat);
}

// ctor
partial void CustomInit()
public ResourceQuantity(string v)
{
if (Value == null)
if (v == null)
{
// No value has been defined, initialize to 0.
_unitlessValue = new Fraction(0);
Format = SuffixFormat.BinarySI;
return;
}

var value = Value.Trim();
var value = v.Trim();

var si = value.IndexOfAny(SuffixChars);
if (si == -1)
Expand All @@ -188,6 +154,11 @@ partial void CustomInit()
}
}

public static implicit operator ResourceQuantity(string v)
{
return new ResourceQuantity(v);
}

private static bool HasMantissa(Fraction value)
{
if (value.IsZero)
Expand All @@ -200,7 +171,7 @@ private static bool HasMantissa(Fraction value)

public static implicit operator decimal(ResourceQuantity v)
{
return v?.ToDecimal() ?? 0;
return v.ToDecimal();
}
Comment on lines 172 to 175
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

The implicit operator calls ToDecimal() on a struct that could be in an uninitialized state. Since ResourceQuantity is now a struct, accessing _unitlessValue when uninitialized could cause issues. Consider adding null/default checks.

Copilot uses AI. Check for mistakes.


public static implicit operator ResourceQuantity(decimal v)
Expand Down
Loading
Loading