Skip to content
Open
Show file tree
Hide file tree
Changes from 13 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
6 changes: 1 addition & 5 deletions .github/workflows/buildtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ jobs:
dotnet-version: |
8.0.x
9.0.x
# - name: Check Format
# # don't check formatting on Windows b/c of CRLF issues.
# if: matrix.os == 'ubuntu-latest'
# run: dotnet format --severity error --verify-no-changes --exclude ./src/KubernetesClient/generated/
- name: Build
run: dotnet build --configuration Release -v detailed
run: dotnet build --configuration Release
- name: Test
run: dotnet test --configuration Release --collect:"Code Coverage;Format=Cobertura" --logger trx --results-directory TestResults --settings CodeCoverage.runsettings --no-build
- name: Upload coverage to Codecov
Expand Down
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
3 changes: 1 addition & 2 deletions src/KubernetesClient.Aot/KubernetesClient.Aot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
<Compile Include="..\KubernetesClient\Models\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\Models\ISpec.cs" />
<Compile Include="..\KubernetesClient\Models\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 { }
}
3 changes: 1 addition & 2 deletions src/KubernetesClient.Classic/KubernetesClient.Classic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<Compile Include="..\KubernetesClient\Models\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\Models\ISpec.cs" />
<Compile Include="..\KubernetesClient\Models\IStatus.cs" />
<Compile Include="..\KubernetesClient\IValidate.cs" />
Expand All @@ -37,7 +37,6 @@
<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.

38 changes: 38 additions & 0 deletions src/KubernetesClient/Models/IntOrString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace k8s.Models
{
[JsonConverter(typeof(IntOrStringJsonConverter))]
public struct IntOrString
{
public string? Value { get; private init; }

Check warning on line 6 in src/KubernetesClient/Models/IntOrString.cs

View workflow job for this annotation

GitHub Actions / Dotnet build (macOS-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 6 in src/KubernetesClient/Models/IntOrString.cs

View workflow job for this annotation

GitHub Actions / Dotnet build (macOS-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 6 in src/KubernetesClient/Models/IntOrString.cs

View workflow job for this annotation

GitHub Actions / Dotnet build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 6 in src/KubernetesClient/Models/IntOrString.cs

View workflow job for this annotation

GitHub Actions / Dotnet build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 6 in src/KubernetesClient/Models/IntOrString.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 6 in src/KubernetesClient/Models/IntOrString.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 6 in src/KubernetesClient/Models/IntOrString.cs

View workflow job for this annotation

GitHub Actions / MSBuild build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 6 in src/KubernetesClient/Models/IntOrString.cs

View workflow job for this annotation

GitHub Actions / MSBuild build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 6 in src/KubernetesClient/Models/IntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 6 in src/KubernetesClient/Models/IntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

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);
}
}
}
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.

Loading
Loading