Skip to content

Commit 8e86191

Browse files
authored
netstandard2 extendable lib model, basic rest (#793)
* first lib model * add missing files * happy test * add vanilla rest for extend * fix new url pattern * address comments * add v to tag * bump ver * add missing file when ren * support multi pkg * fix gh action * fix env var * ren title * use gh action to set ver * remove unused * remove unused
1 parent 0f09a33 commit 8e86191

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+333
-895
lines changed

.github/workflows/draft.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Nuget
1+
name: Draft Release
22

33
on:
44
push:
@@ -35,13 +35,13 @@ jobs:
3535
- name: dotnet test
3636
run: dotnet test
3737

38-
- name: dotnet pack
39-
run: dotnet pack -c Release src/KubernetesClient -o pkg --include-symbols
38+
- uses: dotnet/nbgv@master
39+
with:
40+
setAllVars: true
4041

4142
- name: create release
4243
shell: pwsh
4344
env:
4445
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4546
run: |
46-
$VERSION = Get-ChildItem -Path pkg/*.nupkg -Name | Select-String -Pattern '\d+.\d+.\d+' | foreach {$_.Matches.Value}
47-
gh release create -d --generate-notes v$VERSION
47+
gh release create -d --generate-notes v$env:NBGV_NuGetPackageVersion

.github/workflows/nuget.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
run: dotnet test
3737

3838
- name: dotnet pack
39-
run: dotnet pack -c Release src/KubernetesClient -o pkg --include-symbols
39+
run: dotnet pack -c Release src/nuget.proj -o pkg --include-symbols
4040

4141
- name: dotnet nuget push
4242
run: dotnet nuget push pkg\*.nupkg -s https://www.nuget.org/ -k ${{ secrets.nuget_api_key }}

Directory.Build.props

+31
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,35 @@
55
<EnableNETAnalyzers>true</EnableNETAnalyzers>
66
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
77
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<Authors>The Kubernetes Project Authors</Authors>
11+
<Copyright>2017 The Kubernetes Project Authors</Copyright>
12+
<Description>Client library for the Kubernetes open source container orchestrator.</Description>
13+
14+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
15+
<PackageProjectUrl>https://github.com/kubernetes-client/csharp</PackageProjectUrl>
16+
<PackageIconUrl>https://raw.githubusercontent.com/kubernetes/kubernetes/master/logo/logo.png</PackageIconUrl>
17+
<PackageIcon>logo.png</PackageIcon>
18+
<PackageTags>kubernetes;docker;containers;</PackageTags>
19+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
20+
21+
<!-- Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
22+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
23+
24+
<!-- Build symbol package (.snupkg) to distribute the PDB containing Source Link -->
25+
<IncludeSymbols>true</IncludeSymbols>
26+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
27+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
28+
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
29+
<LangVersion>10.0</LangVersion>
30+
</PropertyGroup>
31+
32+
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
33+
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
34+
</PropertyGroup>
35+
36+
<ItemGroup>
37+
<None Include="../../logo.png" Pack="true" Visible="false" PackagePath="" />
38+
</ItemGroup>
839
</Project>

Directory.Build.targets

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<ItemGroup>
3-
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
4-
<PrivateAssets>All</PrivateAssets>
5-
</PackageReference>
6-
7-
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
8-
<PrivateAssets>All</PrivateAssets>
9-
</PackageReference>
3+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
4+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0" PrivateAssets="all" />
5+
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.255" PrivateAssets="all" />
6+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
107
</ItemGroup>
118

129
<ItemGroup>

examples/attach/Attach.cs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Threading.Tasks;
33
using k8s;
44
using k8s.Models;
5-
using k8s.Autorest;
65

76
namespace attach
87
{

examples/watch/Program.cs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Threading.Tasks;
44
using k8s;
55
using k8s.Models;
6-
using k8s.Autorest;
76

87
namespace watch
98
{

examples/yaml/Program.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
43
using System.Threading.Tasks;
54
using k8s;
65
using k8s.Models;

global.json

+3
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"sdk": {
44
"version": "6.0.100",
55
"rollForward": "latestMajor"
6+
},
7+
"msbuild-sdks": {
8+
"Microsoft.Build.Traversal" : "3.1.6"
69
}
710
}

kubernetes-client.sln

+30
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "prometheus", "examples\prom
4949
EndProject
5050
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "yaml", "examples\yaml\yaml.csproj", "{17AB0AD8-6C90-42DD-880C-16B5AC4A373F}"
5151
EndProject
52+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KubernetesClient.Models", "src\KubernetesClient.Models\KubernetesClient.Models.csproj", "{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}"
53+
EndProject
54+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KubernetesClient.Basic", "src\KubernetesClient.Basic\KubernetesClient.Basic.csproj", "{927995F5-05CC-4078-8805-8E6CC06914D8}"
55+
EndProject
5256
Global
5357
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5458
Debug|Any CPU = Debug|Any CPU
@@ -299,6 +303,30 @@ Global
299303
{17AB0AD8-6C90-42DD-880C-16B5AC4A373F}.Release|x64.Build.0 = Release|Any CPU
300304
{17AB0AD8-6C90-42DD-880C-16B5AC4A373F}.Release|x86.ActiveCfg = Release|Any CPU
301305
{17AB0AD8-6C90-42DD-880C-16B5AC4A373F}.Release|x86.Build.0 = Release|Any CPU
306+
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
307+
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
308+
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Debug|x64.ActiveCfg = Debug|Any CPU
309+
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Debug|x64.Build.0 = Debug|Any CPU
310+
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Debug|x86.ActiveCfg = Debug|Any CPU
311+
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Debug|x86.Build.0 = Debug|Any CPU
312+
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
313+
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Release|Any CPU.Build.0 = Release|Any CPU
314+
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Release|x64.ActiveCfg = Release|Any CPU
315+
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Release|x64.Build.0 = Release|Any CPU
316+
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Release|x86.ActiveCfg = Release|Any CPU
317+
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Release|x86.Build.0 = Release|Any CPU
318+
{927995F5-05CC-4078-8805-8E6CC06914D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
319+
{927995F5-05CC-4078-8805-8E6CC06914D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
320+
{927995F5-05CC-4078-8805-8E6CC06914D8}.Debug|x64.ActiveCfg = Debug|Any CPU
321+
{927995F5-05CC-4078-8805-8E6CC06914D8}.Debug|x64.Build.0 = Debug|Any CPU
322+
{927995F5-05CC-4078-8805-8E6CC06914D8}.Debug|x86.ActiveCfg = Debug|Any CPU
323+
{927995F5-05CC-4078-8805-8E6CC06914D8}.Debug|x86.Build.0 = Debug|Any CPU
324+
{927995F5-05CC-4078-8805-8E6CC06914D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
325+
{927995F5-05CC-4078-8805-8E6CC06914D8}.Release|Any CPU.Build.0 = Release|Any CPU
326+
{927995F5-05CC-4078-8805-8E6CC06914D8}.Release|x64.ActiveCfg = Release|Any CPU
327+
{927995F5-05CC-4078-8805-8E6CC06914D8}.Release|x64.Build.0 = Release|Any CPU
328+
{927995F5-05CC-4078-8805-8E6CC06914D8}.Release|x86.ActiveCfg = Release|Any CPU
329+
{927995F5-05CC-4078-8805-8E6CC06914D8}.Release|x86.Build.0 = Release|Any CPU
302330
EndGlobalSection
303331
GlobalSection(SolutionProperties) = preSolution
304332
HideSolutionNode = FALSE
@@ -324,6 +352,8 @@ Global
324352
{DFBB1025-BD22-459D-A04D-E2AB31E129E2} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
325353
{682B94E4-1761-48FF-B5D0-87B45DC0C735} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
326354
{17AB0AD8-6C90-42DD-880C-16B5AC4A373F} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
355+
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8} = {3D1864AA-1FFC-4512-BB13-46055E410F73}
356+
{927995F5-05CC-4078-8805-8E6CC06914D8} = {3D1864AA-1FFC-4512-BB13-46055E410F73}
327357
EndGlobalSection
328358
GlobalSection(ExtensibilityGlobals) = postSolution
329359
SolutionGuid = {049A763A-C891-4E8D-80CF-89DD3E22ADC7}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Net.Http;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using k8s.Autorest;
5+
using System.Net.Http.Headers;
6+
7+
8+
namespace k8s
9+
{
10+
public abstract partial class AbstractKubernetes
11+
{
12+
private sealed class QueryBuilder
13+
{
14+
private List<string> parameters = new List<string>();
15+
16+
public void Append(string key, params object[] values)
17+
{
18+
foreach (var value in values)
19+
{
20+
switch (value)
21+
{
22+
case int intval:
23+
parameters.Add($"{key}={intval}");
24+
break;
25+
case string strval:
26+
parameters.Add($"{key}={Uri.EscapeDataString(strval)}");
27+
break;
28+
case bool boolval:
29+
parameters.Add($"{key}={(boolval ? "true" : "false")}");
30+
break;
31+
default:
32+
// null
33+
break;
34+
}
35+
}
36+
}
37+
38+
public override string ToString()
39+
{
40+
if (parameters.Count > 0)
41+
{
42+
return "?" + string.Join("&", parameters);
43+
}
44+
45+
return "";
46+
}
47+
}
48+
49+
private Task<HttpResponseMessage> SendRequest<T>(T body, HttpRequestMessage httpRequest, CancellationToken cancellationToken)
50+
{
51+
if (body != null)
52+
{
53+
var requestContent = KubernetesJson.Serialize(body);
54+
httpRequest.Content = new StringContent(requestContent, System.Text.Encoding.UTF8);
55+
httpRequest.Content.Headers.ContentType = GetHeader(body);
56+
return SendRequestRaw(requestContent, httpRequest, cancellationToken);
57+
}
58+
59+
return SendRequestRaw("", httpRequest, cancellationToken);
60+
}
61+
62+
public virtual TimeSpan HttpClientTimeout { get; set; } = TimeSpan.FromSeconds(100);
63+
64+
protected abstract Task<HttpOperationResponse<T>> CreateResultAsync<T>(HttpRequestMessage httpRequest, HttpResponseMessage httpResponse, bool? watch, CancellationToken cancellationToken);
65+
66+
protected abstract HttpRequestMessage CreateRequest(string relativeUri, string method, IDictionary<string, IList<string>> customHeaders);
67+
68+
protected abstract MediaTypeHeaderValue GetHeader(object body);
69+
70+
protected abstract Task<HttpResponseMessage> SendRequestRaw(string requestContent, HttpRequestMessage httpRequest, CancellationToken cancellationToken);
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("KubernetesClient")]
4+
[assembly: InternalsVisibleTo("KubernetesClient.VanillaRest")]
5+
[assembly: InternalsVisibleTo("KubernetesClient.Tests")]

src/KubernetesClient.Basic/Global.cs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
global using System;
2+
global using System.Collections.Generic;
3+
global using System.Linq;
4+
global using System.Text.Json;
5+
global using System.Text.Json.Serialization;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
5+
<RootNamespace>k8s</RootNamespace>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="Generator" />
10+
<AdditionalFiles Include="..\..\swagger.json" Generator="api" />
11+
<ProjectReference Include="..\KubernetesClient.Models\KubernetesClient.Models.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\LibKubernetesGenerator\LibKubernetesGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
16+
</ItemGroup>
17+
18+
</Project>

src/KubernetesClient/KubernetesJson.cs renamed to src/KubernetesClient.Basic/KubernetesJson.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private sealed class KubernetesDateTimeOffsetConverter : JsonConverter<DateTimeO
3232
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3333
{
3434
var str = reader.GetString();
35-
return DateTimeOffset.ParseExact(str, new[] { Iso8601Format, SerializeFormat }, CultureInfo.InvariantCulture);
35+
return DateTimeOffset.ParseExact(str, new[] { Iso8601Format, SerializeFormat }, CultureInfo.InvariantCulture, DateTimeStyles.None);
3636
}
3737

3838
public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("KubernetesClient")]
4+
[assembly: InternalsVisibleTo("KubernetesClient.Basic")]
5+
[assembly: InternalsVisibleTo("KubernetesClient.Tests")]

src/KubernetesClient.Models/Global.cs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
global using System;
2+
global using System.Collections.Generic;
3+
global using System.Linq;
4+
global using System.Text.Json;
5+
global using System.Text.Json.Serialization;
File renamed without changes.

src/KubernetesClient/IntOrStringConverter.cs renamed to src/KubernetesClient.Models/IntOrStringConverter.cs

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public override IntstrIntOrString Read(ref Utf8JsonReader reader, Type typeToCon
1919

2020
public override void Write(Utf8JsonWriter writer, IntstrIntOrString value, JsonSerializerOptions options)
2121
{
22+
if (writer == null)
23+
{
24+
throw new ArgumentNullException(nameof(writer));
25+
}
26+
2227
var s = value?.Value;
2328

2429
if (long.TryParse(s, out var intv))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
4+
<RootNamespace>k8s.Models</RootNamespace>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="Generator" />
9+
<AdditionalFiles Include="..\..\swagger.json" Generator="model,modelext,versionconverter" />
10+
<ProjectReference Include="..\LibKubernetesGenerator\LibKubernetesGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="System.Text.Json" Version="6.0.0" />
15+
<PackageReference Include="AutoMapper" Version="10.1.1" />
16+
<PackageReference Include="Fractions" Version="7.0.0" />
17+
</ItemGroup>
18+
</Project>

src/KubernetesClient/QuantityConverter.cs renamed to src/KubernetesClient.Models/QuantityConverter.cs

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ public override ResourceQuantity Read(ref Utf8JsonReader reader, Type typeToConv
99

1010
public override void Write(Utf8JsonWriter writer, ResourceQuantity value, JsonSerializerOptions options)
1111
{
12+
if (writer == null)
13+
{
14+
throw new ArgumentNullException(nameof(writer));
15+
}
16+
1217
writer.WriteStringValue(value?.ToString());
1318
}
1419
}

src/KubernetesClient/ResourceQuantity.cs renamed to src/KubernetesClient.Models/ResourceQuantity.cs

+1-26
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System.Globalization;
22
using System.Numerics;
33
using Fractions;
4-
using YamlDotNet.Core;
5-
using YamlDotNet.Core.Events;
6-
using YamlDotNet.Serialization;
74

85
namespace k8s.Models
96
{
@@ -57,7 +54,7 @@ namespace k8s.Models
5754
/// cause implementors to also use a fixed point implementation.
5855
/// </summary>
5956
[JsonConverter(typeof(QuantityConverter))]
60-
public partial class ResourceQuantity : IYamlConvertible
57+
public partial class ResourceQuantity
6158
{
6259
public enum SuffixFormat
6360
{
@@ -201,28 +198,6 @@ private static bool HasMantissa(Fraction value)
201198
return BigInteger.Remainder(value.Numerator, value.Denominator) > 0;
202199
}
203200

204-
/// <inheritdoc/>
205-
public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
206-
{
207-
if (expectedType != typeof(ResourceQuantity))
208-
{
209-
throw new ArgumentOutOfRangeException(nameof(expectedType));
210-
}
211-
212-
if (parser?.Current is Scalar)
213-
{
214-
Value = ((Scalar)parser.Current).Value;
215-
parser.MoveNext();
216-
CustomInit();
217-
}
218-
}
219-
220-
/// <inheritdoc/>
221-
public void Write(IEmitter emitter, ObjectSerializer nestedObjectSerializer)
222-
{
223-
emitter?.Emit(new Scalar(ToString()));
224-
}
225-
226201
public static implicit operator decimal(ResourceQuantity v)
227202
{
228203
return v?.ToDecimal() ?? 0;

src/KubernetesClient/V1PatchJsonConverter.cs renamed to src/KubernetesClient.Models/V1PatchJsonConverter.cs

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ public override V1Patch Read(ref Utf8JsonReader reader, Type typeToConvert, Json
99

1010
public override void Write(Utf8JsonWriter writer, V1Patch value, JsonSerializerOptions options)
1111
{
12+
if (writer == null)
13+
{
14+
throw new ArgumentNullException(nameof(writer));
15+
}
16+
1217
var content = value?.Content;
1318
if (content is string s)
1419
{

0 commit comments

Comments
 (0)