Skip to content

Apply style guideline #492

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

Merged
merged 1 commit into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions examples/attach/Attach.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ private static async Task Main(string[] args)

var list = client.ListNamespacedPod("default");
var pod = list.Items[0];
await AttachToPod(client, pod);
await AttachToPod(client, pod).ConfigureAwait(false);
}

private async static Task AttachToPod(IKubernetes client, V1Pod pod)
{
var webSocket =
await client.WebSocketNamespacedPodAttachAsync(pod.Metadata.Name, "default",
pod.Spec.Containers[0].Name);
pod.Spec.Containers[0].Name).ConfigureAwait(false);

var demux = new StreamDemuxer(webSocket);
demux.Start();
Expand Down
4 changes: 2 additions & 2 deletions examples/exec/Exec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ private static async Task Main(string[] args)

var list = client.ListNamespacedPod("default");
var pod = list.Items[0];
await ExecInPod(client, pod);
await ExecInPod(client, pod).ConfigureAwait(false);
}

private async static Task ExecInPod(IKubernetes client, V1Pod pod)
{
var webSocket =
await client.WebSocketNamespacedPodExecAsync(pod.Metadata.Name, "default", "ls",
pod.Spec.Containers[0].Name);
pod.Spec.Containers[0].Name).ConfigureAwait(false);

var demux = new StreamDemuxer(webSocket);
demux.Start();
Expand Down
4 changes: 2 additions & 2 deletions examples/httpClientFactory/PodListHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace httpClientFactory
{
// Learn more about IHostedServices at https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-2.2&tabs=visual-studio
internal class PodListHostedService : IHostedService
public class PodListHostedService : IHostedService
{
private readonly IKubernetes _kubernetesClient;
private readonly ILogger<PodListHostedService> _logger;
Expand All @@ -23,7 +23,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Starting Request!");

var list = await _kubernetesClient.ListNamespacedPodAsync("default", cancellationToken: cancellationToken);
var list = await _kubernetesClient.ListNamespacedPodAsync("default", cancellationToken: cancellationToken).ConfigureAwait(false);
foreach (var item in list.Items)
{
_logger.LogInformation(item.Metadata.Name);
Expand Down
2 changes: 1 addition & 1 deletion examples/logs/Logs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static async Task Main(string[] args)
var pod = list.Items[0];

var response = await client.ReadNamespacedPodLogWithHttpMessagesAsync(pod.Metadata.Name,
pod.Metadata.NamespaceProperty, follow: true);
pod.Metadata.NamespaceProperty, follow: true).ConfigureAwait(false);
var stream = response.Body;
stream.CopyTo(Console.OpenStandardOutput());
}
Expand Down
9 changes: 5 additions & 4 deletions examples/metrics/Metrics.cs → examples/metrics/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

namespace metrics
{
class Program
internal class Program
{
static async Task NodesMetrics(IKubernetes client)
private static async Task NodesMetrics(IKubernetes client)
{
var nodesMetrics = await client.GetKubernetesNodesMetricsAsync().ConfigureAwait(false);

Expand All @@ -22,7 +22,7 @@ static async Task NodesMetrics(IKubernetes client)
}
}

static async Task PodsMetrics(IKubernetes client)
private static async Task PodsMetrics(IKubernetes client)
{
var podsMetrics = await client.GetKubernetesPodsMetricsAsync().ConfigureAwait(false);

Expand All @@ -42,11 +42,12 @@ static async Task PodsMetrics(IKubernetes client)
Console.WriteLine($"{metric.Key}: {metric.Value}");
}
}

Console.Write(Environment.NewLine);
}
}

static async Task Main(string[] args)
private static async Task Main(string[] args)
{
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
var client = new Kubernetes(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace @namespace
{
class NamespaceExample
internal class NamespaceExample
{
static void ListNamespaces(IKubernetes client)
private static void ListNamespaces(IKubernetes client)
{
var list = client.ListNamespace();
foreach (var item in list.Items)
Expand All @@ -22,14 +22,14 @@ static void ListNamespaces(IKubernetes client)
}
}

static async Task DeleteAsync(IKubernetes client, string name, int delayMillis)
private static async Task DeleteAsync(IKubernetes client, string name, int delayMillis)
{
while (true)
{
await Task.Delay(delayMillis);
await Task.Delay(delayMillis).ConfigureAwait(false);
try
{
await client.ReadNamespaceAsync(name);
await client.ReadNamespaceAsync(name).ConfigureAwait(false);
}
catch (AggregateException ex)
{
Expand All @@ -43,7 +43,7 @@ static async Task DeleteAsync(IKubernetes client, string name, int delayMillis)
return;
}

throw ex;
throw;
}
}
}
Expand All @@ -54,12 +54,12 @@ static async Task DeleteAsync(IKubernetes client, string name, int delayMillis)
return;
}

throw ex;
throw;
}
}
}

static void Delete(IKubernetes client, string name, int delayMillis)
private static void Delete(IKubernetes client, string name, int delayMillis)
{
DeleteAsync(client, name, delayMillis).Wait();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
5 changes: 5 additions & 0 deletions gen/KubernetesWatchGenerator/ModelOperators.cs.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// <auto-generated>
// Code generated by gen/KubernetesWatchGenerator
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
using k8s.Versioning;

namespace k8s.Models
Expand Down
49 changes: 20 additions & 29 deletions gen/KubernetesWatchGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

namespace KubernetesWatchGenerator
{
class Program
internal class Program
{
private static HashSet<string> _classesWithValidation;
static readonly Dictionary<string, string> ClassNameMap = new Dictionary<string, string>();
private static readonly Dictionary<string, string> ClassNameMap = new Dictionary<string, string>();
private static Dictionary<JsonSchema4, string> _schemaToNameMap;
private static HashSet<string> _schemaDefinitionsInMultipleGroups;
private static Dictionary<string, string> _classNameToPluralMap;

static async Task Main(string[] args)
private static async Task Main(string[] args)
{
if (args.Length < 2)
{
Expand All @@ -31,7 +31,7 @@ static async Task Main(string[] args)

// Read the spec trimmed
// here we cache all name in gen project for later use
var swagger = await SwaggerDocument.FromFileAsync(Path.Combine(args[1], "swagger.json"));
var swagger = await SwaggerDocument.FromFileAsync(Path.Combine(args[1], "swagger.json")).ConfigureAwait(false);
foreach (var (k, v) in swagger.Definitions)
{
if (v.ExtensionData?.TryGetValue("x-kubernetes-group-version-kind", out var _) == true)
Expand All @@ -46,9 +46,8 @@ static async Task Main(string[] args)
}
}


// gen project removed all watch operations, so here we switch back to unprocessed version
swagger = await SwaggerDocument.FromFileAsync(Path.Combine(args[1], "swagger.json.unprocessed"));
swagger = await SwaggerDocument.FromFileAsync(Path.Combine(args[1], "swagger.json.unprocessed")).ConfigureAwait(false);
_schemaToNameMap = swagger.Definitions.ToDictionary(x => x.Value, x => x.Key);
_schemaDefinitionsInMultipleGroups = _schemaToNameMap.Values.Select(x =>
{
Expand Down Expand Up @@ -90,7 +89,6 @@ static async Task Main(string[] args)
.Union(_classNameToPluralMap)
.ToDictionary(x => x.Key, x => x.Value);


// Register helpers used in the templating.
Helpers.Register(nameof(ToXmlDoc), ToXmlDoc);
Helpers.Register(nameof(GetClassName), GetClassName);
Expand Down Expand Up @@ -166,12 +164,9 @@ static async Task Main(string[] args)

Render.FileToFile("VersionConverter.cs.template", versionConverterPairs, Path.Combine(outputDirectory, "VersionConverter.cs"));
Render.FileToFile("ModelOperators.cs.template", typePairs, Path.Combine(outputDirectory, "ModelOperators.cs"));

}



static void ToXmlDoc(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
private static void ToXmlDoc(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
RenderBlock fn, RenderBlock inverse)
{
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is string)
Expand Down Expand Up @@ -199,7 +194,7 @@ static void ToXmlDoc(RenderContext context, IList<object> arguments, IDictionary
}
}

static void GetTuple(RenderContext context, IList<object> arguments, IDictionary<string, object> options, RenderBlock fn, RenderBlock inverse)
private static void GetTuple(RenderContext context, IList<object> arguments, IDictionary<string, object> options, RenderBlock fn, RenderBlock inverse)
{
if (arguments != null && arguments.Count > 0 && arguments[0] is ITuple && options.TryGetValue("index", out var indexObj) && int.TryParse(indexObj?.ToString(), out var index))
{
Expand All @@ -209,9 +204,7 @@ static void GetTuple(RenderContext context, IList<object> arguments, IDictionary
}
}



static void GetClassName(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
private static void GetClassName(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
RenderBlock fn, RenderBlock inverse)
{
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is SwaggerOperation)
Expand All @@ -224,7 +217,7 @@ static void GetClassName(RenderContext context, IList<object> arguments, IDictio
}
}

static string GetClassName(SwaggerOperation watchOperation)
private static string GetClassName(SwaggerOperation watchOperation)
{
var groupVersionKind =
(Dictionary<string, object>)watchOperation.ExtensionData["x-kubernetes-group-version-kind"];
Expand Down Expand Up @@ -257,7 +250,7 @@ private static void GetInterfaceName(RenderContext context, IList<object> argume
}
}

static string GetClassNameForSchemaDefinition(JsonSchema4 definition)
private static string GetClassNameForSchemaDefinition(JsonSchema4 definition)
{
if (definition.ExtensionData != null &&
definition.ExtensionData.ContainsKey("x-kubernetes-group-version-kind"))
Expand All @@ -280,7 +273,7 @@ static string GetClassNameForSchemaDefinition(JsonSchema4 definition)
return className;
}

static string GetInterfaceName(JsonSchema4 definition)
private static string GetInterfaceName(JsonSchema4 definition)
{
var groupVersionKindElements = (object[])definition.ExtensionData["x-kubernetes-group-version-kind"];
var groupVersionKind = (Dictionary<string, object>)groupVersionKindElements[0];
Expand Down Expand Up @@ -321,8 +314,7 @@ static string GetInterfaceName(JsonSchema4 definition)
return result;
}


static void GetKind(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
private static void GetKind(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
RenderBlock fn, RenderBlock inverse)
{
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema4)
Expand All @@ -339,7 +331,7 @@ private static string GetKind(JsonSchema4 definition)
return groupVersionKind["kind"] as string;
}

static void GetPlural(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
private static void GetPlural(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
RenderBlock fn, RenderBlock inverse)
{
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema4)
Expand All @@ -362,7 +354,7 @@ private static string GetPlural(JsonSchema4 definition)
return _classNameToPluralMap.GetValueOrDefault(className, null);
}

static void GetGroup(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
private static void GetGroup(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
RenderBlock fn, RenderBlock inverse)
{
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema4)
Expand All @@ -379,7 +371,7 @@ private static string GetGroup(JsonSchema4 definition)
return groupVersionKind["group"] as string;
}

static void GetMethodName(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
private static void GetMethodName(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
RenderBlock fn, RenderBlock inverse)
{
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is SwaggerOperation)
Expand All @@ -388,8 +380,7 @@ static void GetMethodName(RenderContext context, IList<object> arguments, IDicti
}
}


static string GetMethodName(SwaggerOperation watchOperation)
private static string GetMethodName(SwaggerOperation watchOperation)
{
var tag = watchOperation.Tags[0];
tag = tag.Replace("_", string.Empty);
Expand All @@ -402,7 +393,7 @@ static string GetMethodName(SwaggerOperation watchOperation)
return methodName;
}

static void GetDotNetType(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
private static void GetDotNetType(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
RenderBlock fn, RenderBlock inverse)
{
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is SwaggerParameter)
Expand Down Expand Up @@ -463,7 +454,7 @@ private static string GetDotNetType(JsonObjectType jsonType, string name, bool r
}
}

static void GetDotNetName(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
private static void GetDotNetName(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
RenderBlock fn, RenderBlock inverse)
{
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is SwaggerParameter)
Expand Down Expand Up @@ -492,7 +483,7 @@ private static string GetDotNetName(string jsonName)
return jsonName;
}

static void GetPathExpression(RenderContext context, IList<object> arguments,
private static void GetPathExpression(RenderContext context, IList<object> arguments,
IDictionary<string, object> options, RenderBlock fn, RenderBlock inverse)
{
if (arguments != null && arguments.Count > 0 && arguments[0] != null &&
Expand All @@ -516,7 +507,7 @@ private static string GetPathExpression(SwaggerOperationDescription operation)
return pathExpression;
}

static void GetApiVersion(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
private static void GetApiVersion(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
RenderBlock fn, RenderBlock inverse)
{
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema4)
Expand Down
Loading