Skip to content
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

netstandard2 extendable lib model, basic rest #793

Merged
merged 20 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from 16 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: 5 additions & 5 deletions .github/workflows/draft.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Nuget
name: Draft Release

on:
push:
Expand Down Expand Up @@ -35,13 +35,13 @@ jobs:
- name: dotnet test
run: dotnet test

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

- name: create release
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$VERSION = Get-ChildItem -Path pkg/*.nupkg -Name | Select-String -Pattern '\d+.\d+.\d+' | foreach {$_.Matches.Value}
gh release create -d --generate-notes $VERSION
gh release create -d --generate-notes v$env:NBGV_NuGetPackageVersion
2 changes: 1 addition & 1 deletion .github/workflows/nuget.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: dotnet test

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

- name: dotnet nuget push
run: dotnet nuget push pkg\*.nupkg -s https://www.nuget.org/ -k ${{ secrets.nuget_api_key }}
26 changes: 26 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,30 @@
<PropertyGroup>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)\kubernetes-client.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<PropertyGroup>
<Authors>The Kubernetes Project Authors</Authors>
<Copyright>2017 The Kubernetes Project Authors</Copyright>
<Description>Client library for the Kubernetes open source container orchestrator.</Description>

<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/kubernetes-client/csharp</PackageProjectUrl>
<PackageIconUrl>https://raw.githubusercontent.com/kubernetes/kubernetes/master/logo/logo.png</PackageIconUrl>
<PackageTags>kubernetes;docker;containers;</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<!-- Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>

<!-- Build symbol package (.snupkg) to distribute the PDB containing Source Link -->
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<LangVersion>10.0</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
</Project>
11 changes: 4 additions & 7 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>All</PrivateAssets>
</PackageReference>

<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0" PrivateAssets="all" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.255" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"sdk": {
"version": "6.0.100",
"rollForward": "latestMajor"
},
"msbuild-sdks": {
"Microsoft.Build.Traversal" : "3.1.6"
}
}
30 changes: 30 additions & 0 deletions kubernetes-client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "prometheus", "examples\prom
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "yaml", "examples\yaml\yaml.csproj", "{17AB0AD8-6C90-42DD-880C-16B5AC4A373F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KubernetesClient.Models", "src\KubernetesClient.Models\KubernetesClient.Models.csproj", "{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KubernetesClient.Basic", "src\KubernetesClient.Basic\KubernetesClient.Basic.csproj", "{927995F5-05CC-4078-8805-8E6CC06914D8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -299,6 +303,30 @@ Global
{17AB0AD8-6C90-42DD-880C-16B5AC4A373F}.Release|x64.Build.0 = Release|Any CPU
{17AB0AD8-6C90-42DD-880C-16B5AC4A373F}.Release|x86.ActiveCfg = Release|Any CPU
{17AB0AD8-6C90-42DD-880C-16B5AC4A373F}.Release|x86.Build.0 = Release|Any CPU
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Debug|x64.ActiveCfg = Debug|Any CPU
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Debug|x64.Build.0 = Debug|Any CPU
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Debug|x86.ActiveCfg = Debug|Any CPU
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Debug|x86.Build.0 = Debug|Any CPU
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Release|Any CPU.Build.0 = Release|Any CPU
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Release|x64.ActiveCfg = Release|Any CPU
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Release|x64.Build.0 = Release|Any CPU
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Release|x86.ActiveCfg = Release|Any CPU
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8}.Release|x86.Build.0 = Release|Any CPU
{927995F5-05CC-4078-8805-8E6CC06914D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{927995F5-05CC-4078-8805-8E6CC06914D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{927995F5-05CC-4078-8805-8E6CC06914D8}.Debug|x64.ActiveCfg = Debug|Any CPU
{927995F5-05CC-4078-8805-8E6CC06914D8}.Debug|x64.Build.0 = Debug|Any CPU
{927995F5-05CC-4078-8805-8E6CC06914D8}.Debug|x86.ActiveCfg = Debug|Any CPU
{927995F5-05CC-4078-8805-8E6CC06914D8}.Debug|x86.Build.0 = Debug|Any CPU
{927995F5-05CC-4078-8805-8E6CC06914D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{927995F5-05CC-4078-8805-8E6CC06914D8}.Release|Any CPU.Build.0 = Release|Any CPU
{927995F5-05CC-4078-8805-8E6CC06914D8}.Release|x64.ActiveCfg = Release|Any CPU
{927995F5-05CC-4078-8805-8E6CC06914D8}.Release|x64.Build.0 = Release|Any CPU
{927995F5-05CC-4078-8805-8E6CC06914D8}.Release|x86.ActiveCfg = Release|Any CPU
{927995F5-05CC-4078-8805-8E6CC06914D8}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -324,6 +352,8 @@ Global
{DFBB1025-BD22-459D-A04D-E2AB31E129E2} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
{682B94E4-1761-48FF-B5D0-87B45DC0C735} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
{17AB0AD8-6C90-42DD-880C-16B5AC4A373F} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
{F066A4D8-2EF0-4C07-AC0D-BD325DE3FFA8} = {3D1864AA-1FFC-4512-BB13-46055E410F73}
{927995F5-05CC-4078-8805-8E6CC06914D8} = {3D1864AA-1FFC-4512-BB13-46055E410F73}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {049A763A-C891-4E8D-80CF-89DD3E22ADC7}
Expand Down
74 changes: 74 additions & 0 deletions src/KubernetesClient.Basic/AbstractKubernetes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using k8s.Autorest;
using System.Net.Http.Headers;


namespace k8s
{
public abstract partial class AbstractKubernetes
{
private sealed class QueryBuilder
{
private List<string> parameters = new List<string>();

public void Append(string key, params object[] values)
{
foreach (var value in values)
{
switch (value)
{
case int intval:
parameters.Add($"{key}={intval}");
break;
case string strval:
parameters.Add($"{key}={Uri.EscapeDataString(strval)}");
break;
case bool boolval:
parameters.Add($"{key}={(boolval ? "true" : "false")}");
break;
default:
// null
break;
}
}
}

public override string ToString()
{
if (parameters.Count > 0)
{
return "?" + string.Join("&", parameters);
}

return "";
}
}

private Task<HttpResponseMessage> SendRequest<T>(T body, HttpRequestMessage httpRequest, CancellationToken cancellationToken)
{
if (body != null)
{
var requestContent = KubernetesJson.Serialize(body);
httpRequest.Content = new StringContent(requestContent, System.Text.Encoding.UTF8);
httpRequest.Content.Headers.ContentType = GetHeader(body);
return SendRequestRaw(requestContent, httpRequest, cancellationToken);
}

return SendRequestRaw("", httpRequest, cancellationToken);
}

public virtual TimeSpan HttpClientTimeout { get; set; } = TimeSpan.FromSeconds(100);

protected abstract Task<HttpOperationResponse<T>> CreateResultAsync<T>(HttpRequestMessage httpRequest, HttpResponseMessage httpResponse, bool? watch, CancellationToken cancellationToken);

protected abstract HttpRequestMessage CreateRequest(string relativeUri, string method, IDictionary<string, IList<string>> customHeaders);

protected abstract MediaTypeHeaderValue GetHeader(object body);

protected abstract Task<HttpResponseMessage> SendRequestRaw(string requestContent, HttpRequestMessage httpRequest, CancellationToken cancellationToken);
}
}
5 changes: 5 additions & 0 deletions src/KubernetesClient.Basic/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("KubernetesClient")]
[assembly: InternalsVisibleTo("KubernetesClient.VanillaRest")]
[assembly: InternalsVisibleTo("KubernetesClient.Tests")]
5 changes: 5 additions & 0 deletions src/KubernetesClient.Basic/Global.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Text.Json;
global using System.Text.Json.Serialization;
18 changes: 18 additions & 0 deletions src/KubernetesClient.Basic/KubernetesClient.Basic.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<RootNamespace>k8s</RootNamespace>
</PropertyGroup>

<ItemGroup>
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="Generator" />
<AdditionalFiles Include="..\..\swagger.json" Generator="api" />
<ProjectReference Include="..\KubernetesClient.Models\KubernetesClient.Models.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\LibKubernetesGenerator\LibKubernetesGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private sealed class KubernetesDateTimeOffsetConverter : JsonConverter<DateTimeO
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var str = reader.GetString();
return DateTimeOffset.ParseExact(str, new[] { Iso8601Format, SerializeFormat }, CultureInfo.InvariantCulture);
return DateTimeOffset.ParseExact(str, new[] { Iso8601Format, SerializeFormat }, CultureInfo.InvariantCulture, DateTimeStyles.None);
}

public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
Expand Down
5 changes: 5 additions & 0 deletions src/KubernetesClient.Models/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("KubernetesClient")]
[assembly: InternalsVisibleTo("KubernetesClient.Basic")]
[assembly: InternalsVisibleTo("KubernetesClient.Tests")]
5 changes: 5 additions & 0 deletions src/KubernetesClient.Models/Global.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Text.Json;
global using System.Text.Json.Serialization;
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public override IntstrIntOrString Read(ref Utf8JsonReader reader, Type typeToCon

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

var s = value?.Value;

if (long.TryParse(s, out var intv))
Expand Down
18 changes: 18 additions & 0 deletions src/KubernetesClient.Models/KubernetesClient.Models.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<RootNamespace>k8s.Models</RootNamespace>
</PropertyGroup>

<ItemGroup>
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="Generator" />
<AdditionalFiles Include="..\..\swagger.json" Generator="model,modelext,versionconverter" />
<ProjectReference Include="..\LibKubernetesGenerator\LibKubernetesGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="6.0.0" />
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="Fractions" Version="7.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public override ResourceQuantity Read(ref Utf8JsonReader reader, Type typeToConv

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

writer.WriteStringValue(value?.ToString());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System.Globalization;
using System.Numerics;
using Fractions;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;

namespace k8s.Models
{
Expand Down Expand Up @@ -57,7 +54,7 @@ namespace k8s.Models
/// cause implementors to also use a fixed point implementation.
/// </summary>
[JsonConverter(typeof(QuantityConverter))]
public partial class ResourceQuantity : IYamlConvertible
public partial class ResourceQuantity
{
public enum SuffixFormat
{
Expand Down Expand Up @@ -201,28 +198,6 @@ private static bool HasMantissa(Fraction value)
return BigInteger.Remainder(value.Numerator, value.Denominator) > 0;
}

/// <inheritdoc/>
public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
{
if (expectedType != typeof(ResourceQuantity))
{
throw new ArgumentOutOfRangeException(nameof(expectedType));
}

if (parser?.Current is Scalar)
{
Value = ((Scalar)parser.Current).Value;
parser.MoveNext();
CustomInit();
}
}

/// <inheritdoc/>
public void Write(IEmitter emitter, ObjectSerializer nestedObjectSerializer)
{
emitter?.Emit(new Scalar(ToString()));
}

public static implicit operator decimal(ResourceQuantity v)
{
return v?.ToDecimal() ?? 0;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public override V1Patch Read(ref Utf8JsonReader reader, Type typeToConvert, Json

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

var content = value?.Content;
if (content is string s)
{
Expand Down
2 changes: 1 addition & 1 deletion src/KubernetesClient/IKubernetes.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace k8s;

public partial interface IKubernetes : IDisposable
public partial interface IKubernetes : IBasicKubernetes, IDisposable
{
/// <summary>
/// The base URI of the service.
Expand Down
7 changes: 0 additions & 7 deletions src/KubernetesClient/Kubernetes.ConfigInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ namespace k8s
{
public partial class Kubernetes
{
/// <summary>
/// Timeout of REST calls to Kubernetes server
/// Does not apply to watch related api
/// </summary>
/// <value>timeout</value>
public TimeSpan HttpClientTimeout { get; set; } = TimeSpan.FromSeconds(100);

/// <summary>
/// Initializes a new instance of the <see cref="Kubernetes" /> class.
/// </summary>
Expand Down
Loading