diff --git a/.github/workflows/dotnet.yaml b/.github/workflows/dotnet.yaml index c2b8606..91a1a4d 100644 --- a/.github/workflows/dotnet.yaml +++ b/.github/workflows/dotnet.yaml @@ -34,6 +34,12 @@ jobs: if: matrix.os != 'windows-latest' run: | rsync --archive --ignore-existing ${DOTNET_ROOT/3.1.201/2.1.805}/ ${DOTNET_ROOT/3.1.201/2.1.202}/ $DOTNET_ROOT + - name: Setup Format + run: dotnet tool install -g dotnet-format + - name: Check Format + # don't check formatting on Windows b/c of CRLF issues. + if: matrix.os != 'windows-latest' + run: dotnet format --check --dry-run --exclude ./src/KubernetesClient/generated/ - name: Build run: dotnet build --configuration Release - name: Test diff --git a/examples/attach/Attach.cs b/examples/attach/Attach.cs index b422aa5..e37e211 100755 --- a/examples/attach/Attach.cs +++ b/examples/attach/Attach.cs @@ -21,7 +21,8 @@ namespace attach await AttachToPod(client, pod); } - private async static Task AttachToPod(IKubernetes client, V1Pod pod) { + private async static Task AttachToPod(IKubernetes client, V1Pod pod) + { var webSocket = await client.WebSocketNamespacedPodAttachAsync(pod.Metadata.Name, "default", pod.Spec.Containers[0].Name); var demux = new StreamDemuxer(webSocket); diff --git a/examples/exec/Exec.cs b/examples/exec/Exec.cs index 61394aa..66e4904 100755 --- a/examples/exec/Exec.cs +++ b/examples/exec/Exec.cs @@ -18,7 +18,8 @@ namespace exec await ExecInPod(client, pod); } - private async static Task ExecInPod(IKubernetes client, V1Pod pod) { + private async static Task ExecInPod(IKubernetes client, V1Pod pod) + { var webSocket = await client.WebSocketNamespacedPodExecAsync(pod.Metadata.Name, "default", "ls", pod.Spec.Containers[0].Name); var demux = new StreamDemuxer(webSocket); diff --git a/examples/logs/Logs.cs b/examples/logs/Logs.cs index b6bcb96..c8f5a22 100755 --- a/examples/logs/Logs.cs +++ b/examples/logs/Logs.cs @@ -14,7 +14,8 @@ namespace logs Console.WriteLine("Starting Request!"); var list = client.ListNamespacedPod("default"); - if (list.Items.Count == 0) { + if (list.Items.Count == 0) + { Console.WriteLine("No pods!"); return; } diff --git a/examples/namespace/Namespace.cs b/examples/namespace/Namespace.cs index e68ea3a..c509418 100644 --- a/examples/namespace/Namespace.cs +++ b/examples/namespace/Namespace.cs @@ -8,34 +8,47 @@ namespace @namespace { class NamespaceExample { - static void ListNamespaces(IKubernetes client) { + static void ListNamespaces(IKubernetes client) + { var list = client.ListNamespace(); - foreach (var item in list.Items) { + foreach (var item in list.Items) + { Console.WriteLine(item.Metadata.Name); } - if (list.Items.Count == 0) { + if (list.Items.Count == 0) + { Console.WriteLine("Empty!"); } } - static async Task DeleteAsync(IKubernetes client, string name, int delayMillis) { - while (true) { + static async Task DeleteAsync(IKubernetes client, string name, int delayMillis) + { + while (true) + { await Task.Delay(delayMillis); try { await client.ReadNamespaceAsync(name); - } catch (AggregateException ex) { - foreach (var innerEx in ex.InnerExceptions) { - if (innerEx is Microsoft.Rest.HttpOperationException) { + } + catch (AggregateException ex) + { + foreach (var innerEx in ex.InnerExceptions) + { + if (innerEx is Microsoft.Rest.HttpOperationException) + { var code = ((Microsoft.Rest.HttpOperationException)innerEx).Response.StatusCode; - if (code == HttpStatusCode.NotFound) { + if (code == HttpStatusCode.NotFound) + { return; } throw ex; } } - } catch (Microsoft.Rest.HttpOperationException ex) { - if (ex.Response.StatusCode == HttpStatusCode.NotFound) { + } + catch (Microsoft.Rest.HttpOperationException ex) + { + if (ex.Response.StatusCode == HttpStatusCode.NotFound) + { return; } throw ex; @@ -43,7 +56,8 @@ namespace @namespace } } - static void Delete(IKubernetes client, string name, int delayMillis) { + static void Delete(IKubernetes client, string name, int delayMillis) + { DeleteAsync(client, name, delayMillis).Wait(); } diff --git a/gen/KubernetesWatchGenerator/Program.cs b/gen/KubernetesWatchGenerator/Program.cs index 3fc2f4d..18b8f5a 100644 --- a/gen/KubernetesWatchGenerator/Program.cs +++ b/gen/KubernetesWatchGenerator/Program.cs @@ -51,9 +51,9 @@ namespace KubernetesWatchGenerator _schemaDefinitionsInMultipleGroups = _schemaToNameMap.Values.Select(x => { var parts = x.Split("."); - return new {FullName = x, Name = parts[parts.Length - 1], Version = parts[parts.Length - 2], Group = parts[parts.Length - 3]}; + return new { FullName = x, Name = parts[parts.Length - 1], Version = parts[parts.Length - 2], Group = parts[parts.Length - 3] }; }) - .GroupBy(x => new {x.Name, x.Version}) + .GroupBy(x => new { x.Name, x.Version }) .Where(x => x.Count() > 1) .SelectMany(x => x) .Select(x => x.FullName) @@ -61,7 +61,7 @@ namespace KubernetesWatchGenerator _classNameToPluralMap = swagger.Operations .Where(x => x.Operation.OperationId.StartsWith("list")) - .Select(x => { return new {PluralName = x.Path.Split("/").Last(), ClassName = GetClassNameForSchemaDefinition(x.Operation.Responses["200"].ActualResponseSchema)}; }) + .Select(x => { return new { PluralName = x.Path.Split("/").Last(), ClassName = GetClassNameForSchemaDefinition(x.Operation.Responses["200"].ActualResponseSchema) }; }) .Distinct() .ToDictionary(x => x.ClassName, x => x.PluralName); @@ -69,7 +69,7 @@ namespace KubernetesWatchGenerator _classNameToPluralMap = _classNameToPluralMap .Where(x => x.Key.EndsWith("List")) .Select(x => - new {ClassName = x.Key.Remove(x.Key.Length - 4), PluralName = x.Value}) + new { ClassName = x.Key.Remove(x.Key.Length - 4), PluralName = x.Value }) .ToDictionary(x => x.ClassName, x => x.PluralName) .Union(_classNameToPluralMap) .ToDictionary(x => x.Key, x => x.Value); @@ -119,7 +119,7 @@ namespace KubernetesWatchGenerator var modelsDir = Path.Combine(outputDirectory, "Models"); _classesWithValidation = Directory.EnumerateFiles(modelsDir) - .Select(x => new {Class = Path.GetFileNameWithoutExtension(x), Content = File.ReadAllText(x)}) + .Select(x => new { Class = Path.GetFileNameWithoutExtension(x), Content = File.ReadAllText(x) }) .Where(x => x.Content.Contains("public virtual void Validate()")) .Select(x => x.Class) .ToHashSet(); @@ -244,7 +244,7 @@ namespace KubernetesWatchGenerator interfaces.Add($"ISpec<{GetClassNameForSchemaDefinition(specProperty.Reference)}>"); } - if(_classesWithValidation.Contains(className)) + if (_classesWithValidation.Contains(className)) interfaces.Add("IValidate"); var result = string.Join(", ", interfaces); return result; @@ -272,7 +272,7 @@ namespace KubernetesWatchGenerator if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema4) { var plural = GetPlural(arguments[0] as JsonSchema4); - if(plural != null) + if (plural != null) context.Write($"\"{plural}\""); else context.Write("null"); diff --git a/src/KubernetesClient/CertUtils.cs b/src/KubernetesClient/CertUtils.cs index b4e6a3a..42ff3b6 100644 --- a/src/KubernetesClient/CertUtils.cs +++ b/src/KubernetesClient/CertUtils.cs @@ -21,7 +21,7 @@ namespace k8s /// List of x509 instances. public static X509Certificate2Collection LoadPemFileCert(string file) { - var certs = new X509CertificateParser().ReadCertificates(File.OpenRead(file)); + var certs = new X509CertificateParser().ReadCertificates(File.OpenRead(file)); var certCollection = new X509Certificate2Collection(); // Convert BouncyCastle X509Certificates to the .NET cryptography implementation and add @@ -76,7 +76,8 @@ namespace k8s var cert = new X509CertificateParser().ReadCertificate(new MemoryStream(certData)); // key usage is a bit string, zero-th bit is 'digitalSignature' // See https://www.alvestrand.no/objectid/2.5.29.15.html for more details. - if (cert != null && cert.GetKeyUsage() != null && !cert.GetKeyUsage()[0]) { + if (cert != null && cert.GetKeyUsage() != null && !cert.GetKeyUsage()[0]) + { throw new Exception( "Client certificates must be marked for digital signing. " + "See https://github.com/kubernetes-client/csharp/issues/319"); @@ -93,10 +94,10 @@ namespace k8s } } - var keyParams = (AsymmetricKeyParameter) obj; + var keyParams = (AsymmetricKeyParameter)obj; var store = new Pkcs12StoreBuilder().Build(); - store.SetKeyEntry("K8SKEY", new AsymmetricKeyEntry(keyParams), new[] {new X509CertificateEntry(cert)}); + store.SetKeyEntry("K8SKEY", new AsymmetricKeyEntry(keyParams), new[] { new X509CertificateEntry(cert) }); using (var pkcs = new MemoryStream()) { diff --git a/src/KubernetesClient/IItems.cs b/src/KubernetesClient/IItems.cs index 4c66eba..a588c90 100644 --- a/src/KubernetesClient/IItems.cs +++ b/src/KubernetesClient/IItems.cs @@ -14,4 +14,4 @@ namespace k8s /// IList Items { get; set; } } -} \ No newline at end of file +} diff --git a/src/KubernetesClient/IMetadata.cs b/src/KubernetesClient/IMetadata.cs index 4817fec..e633e9e 100644 --- a/src/KubernetesClient/IMetadata.cs +++ b/src/KubernetesClient/IMetadata.cs @@ -15,4 +15,4 @@ namespace k8s /// T Metadata { get; set; } } -} \ No newline at end of file +} diff --git a/src/KubernetesClient/ISpec.cs b/src/KubernetesClient/ISpec.cs index d3e7010..43376b7 100644 --- a/src/KubernetesClient/ISpec.cs +++ b/src/KubernetesClient/ISpec.cs @@ -14,4 +14,4 @@ namespace k8s /// T Spec { get; set; } } -} \ No newline at end of file +} diff --git a/src/KubernetesClient/IStatus.cs b/src/KubernetesClient/IStatus.cs index c92cbab..e60f59f 100644 --- a/src/KubernetesClient/IStatus.cs +++ b/src/KubernetesClient/IStatus.cs @@ -14,4 +14,4 @@ namespace k8s /// T Status { get; set; } } -} \ No newline at end of file +} diff --git a/src/KubernetesClient/IValidate.cs b/src/KubernetesClient/IValidate.cs index 497f525..85adeab 100644 --- a/src/KubernetesClient/IValidate.cs +++ b/src/KubernetesClient/IValidate.cs @@ -11,4 +11,4 @@ namespace k8s void Validate(); } -} \ No newline at end of file +} diff --git a/src/KubernetesClient/IntstrIntOrString.cs b/src/KubernetesClient/IntstrIntOrString.cs index ec7509d..3c61c81 100644 --- a/src/KubernetesClient/IntstrIntOrString.cs +++ b/src/KubernetesClient/IntstrIntOrString.cs @@ -7,7 +7,7 @@ using YamlDotNet.Serialization; namespace k8s.Models { - public class IntOrStringYamlConverter: IYamlTypeConverter + public class IntOrStringYamlConverter : IYamlTypeConverter { public bool Accepts(Type type) { @@ -18,13 +18,16 @@ namespace k8s.Models { if (parser.Current is YamlDotNet.Core.Events.Scalar scalar) { - try { + try + { if (string.IsNullOrEmpty(scalar.Value)) { return null; } return new IntstrIntOrString(scalar.Value); - } finally { + } + finally + { parser.MoveNext(); } } @@ -33,7 +36,7 @@ namespace k8s.Models public void WriteYaml(IEmitter emitter, object value, Type type) { - var obj = (IntstrIntOrString) value; + var obj = (IntstrIntOrString)value; emitter.Emit(new YamlDotNet.Core.Events.Scalar(obj.Value)); } } @@ -56,7 +59,7 @@ namespace k8s.Models public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - return (IntstrIntOrString) serializer.Deserialize(reader); + return (IntstrIntOrString)serializer.Deserialize(reader); } public override bool CanConvert(Type objectType) @@ -98,7 +101,7 @@ namespace k8s.Models if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; if (obj.GetType() != this.GetType()) return false; - return Equals((IntstrIntOrString) obj); + return Equals((IntstrIntOrString)obj); } public override int GetHashCode() diff --git a/src/KubernetesClient/KubeConfigModels/AuthProvider.cs b/src/KubernetesClient/KubeConfigModels/AuthProvider.cs index a7fcdc6..4194cfc 100644 --- a/src/KubernetesClient/KubeConfigModels/AuthProvider.cs +++ b/src/KubernetesClient/KubeConfigModels/AuthProvider.cs @@ -7,7 +7,8 @@ namespace k8s.KubeConfigModels /// /// Contains information that describes identity information. This is use to tell the kubernetes cluster who you are. /// - public class AuthProvider { + public class AuthProvider + { /// /// Gets or sets the nickname for this auth provider. /// diff --git a/src/KubernetesClient/KubeConfigModels/ClusterEndpoint.cs b/src/KubernetesClient/KubeConfigModels/ClusterEndpoint.cs index a967979..478831e 100644 --- a/src/KubernetesClient/KubeConfigModels/ClusterEndpoint.cs +++ b/src/KubernetesClient/KubeConfigModels/ClusterEndpoint.cs @@ -12,7 +12,7 @@ namespace k8s.KubeConfigModels /// Gets or sets the path to a cert file for the certificate authority. /// [YamlMember(Alias = "certificate-authority", ApplyNamingConventions = false)] - public string CertificateAuthority {get; set; } + public string CertificateAuthority { get; set; } /// /// Gets or sets =PEM-encoded certificate authority certificates. Overrides . diff --git a/src/KubernetesClient/KubeConfigModels/K8SConfiguration.cs b/src/KubernetesClient/KubeConfigModels/K8SConfiguration.cs index 91e6b0e..b74fc54 100644 --- a/src/KubernetesClient/KubeConfigModels/K8SConfiguration.cs +++ b/src/KubernetesClient/KubeConfigModels/K8SConfiguration.cs @@ -16,7 +16,7 @@ namespace k8s.KubeConfigModels /// Gets or sets general information to be use for CLI interactions /// [YamlMember(Alias = "preferences")] - public IDictionary Preferences{ get; set; } + public IDictionary Preferences { get; set; } [YamlMember(Alias = "apiVersion")] public string ApiVersion { get; set; } diff --git a/src/KubernetesClient/Kubernetes.ConfigInit.cs b/src/KubernetesClient/Kubernetes.ConfigInit.cs index 1bee8a5..3a21725 100644 --- a/src/KubernetesClient/Kubernetes.ConfigInit.cs +++ b/src/KubernetesClient/Kubernetes.ConfigInit.cs @@ -43,7 +43,7 @@ namespace k8s ValidateConfig(config); CaCerts = config.SslCaCerts; SkipTlsVerify = config.SkipTlsVerify; - SetCredentials(config); + SetCredentials(config); } /// diff --git a/src/KubernetesClient/Kubernetes.Exec.cs b/src/KubernetesClient/Kubernetes.Exec.cs index 3175249..5868e59 100644 --- a/src/KubernetesClient/Kubernetes.Exec.cs +++ b/src/KubernetesClient/Kubernetes.Exec.cs @@ -24,7 +24,7 @@ namespace k8s { using (var muxedStream = await this.MuxedStreamNamespacedPodExecAsync(name: name, @namespace: @namespace, command: command, container: container, tty: tty, cancellationToken: cancellationToken).ConfigureAwait(false)) using (Stream stdIn = muxedStream.GetStream(null, ChannelIndex.StdIn)) - using (Stream stdOut= muxedStream.GetStream(ChannelIndex.StdOut, null)) + using (Stream stdOut = muxedStream.GetStream(ChannelIndex.StdOut, null)) using (Stream stdErr = muxedStream.GetStream(ChannelIndex.StdErr, null)) using (Stream error = muxedStream.GetStream(ChannelIndex.Error, null)) using (StreamReader errorReader = new StreamReader(error)) diff --git a/src/KubernetesClient/Kubernetes.Watch.cs b/src/KubernetesClient/Kubernetes.Watch.cs index 7cf801a..edd2e99 100644 --- a/src/KubernetesClient/Kubernetes.Watch.cs +++ b/src/KubernetesClient/Kubernetes.Watch.cs @@ -47,7 +47,7 @@ namespace k8s // Don't sent watch, because setting that value will cause the WatcherDelegatingHandler to kick in. That class // "eats" the first line, which is something we don't want. // query = QueryHelpers.AddQueryString(query, "watch", "true"); - if(@continue != null) + if (@continue != null) { Utilities.AddQueryParameter(query, "continue", @continue); } @@ -87,7 +87,7 @@ namespace k8s Utilities.AddQueryParameter(query, "resourceVersion", resourceVersion); } - uriBuilder.Query = query.Length == 0 ? "" : query.ToString(1, query.Length-1); // UriBuilder.Query doesn't like leading '?' chars, so trim it + uriBuilder.Query = query.Length == 0 ? "" : query.ToString(1, query.Length - 1); // UriBuilder.Query doesn't like leading '?' chars, so trim it // Create HTTP transport objects var httpRequest = new HttpRequestMessage(HttpMethod.Get, uriBuilder.ToString()); @@ -147,7 +147,8 @@ namespace k8s throw ex; } - return new Watcher(async () => { + return new Watcher(async () => + { var stream = await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); StreamReader reader = new StreamReader(stream); diff --git a/src/KubernetesClient/Kubernetes.WebSocket.cs b/src/KubernetesClient/Kubernetes.WebSocket.cs index e3adb9d..8b7a97a 100644 --- a/src/KubernetesClient/Kubernetes.WebSocket.cs +++ b/src/KubernetesClient/Kubernetes.WebSocket.cs @@ -119,7 +119,7 @@ namespace k8s query.Append("&stdin=").Append(stdin ? '1' : '0'); query.Append("&stdout=").Append(stdout ? '1' : '0'); query.Append("&tty=").Append(tty ? '1' : '0'); - uriBuilder.Query = query.ToString(1, query.Length-1); // UriBuilder.Query doesn't like leading '?' chars, so trim it + uriBuilder.Query = query.ToString(1, query.Length - 1); // UriBuilder.Query doesn't like leading '?' chars, so trim it return this.StreamConnectAsync(uriBuilder.Uri, _invocationId, webSocketSubProtol, customHeaders, cancellationToken); } @@ -228,7 +228,7 @@ namespace k8s query.Append("&stdout=").Append(stdout ? '1' : '0'); query.Append("&tty=").Append(tty ? '1' : '0'); Utilities.AddQueryParameter(query, "container", container); - uriBuilder.Query = query.ToString(1, query.Length-1); // UriBuilder.Query doesn't like leading '?' chars, so trim it + uriBuilder.Query = query.ToString(1, query.Length - 1); // UriBuilder.Query doesn't like leading '?' chars, so trim it return StreamConnectAsync(uriBuilder.Uri, _invocationId, webSocketSubProtol, customHeaders, cancellationToken); } diff --git a/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs b/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs index 374e837..bf6b7af 100644 --- a/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs +++ b/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs @@ -427,7 +427,7 @@ namespace k8s process.StartInfo.Environment.Add("KUBERNETES_EXEC_INFO", JsonConvert.SerializeObject(execInfo)); - + if (config.EnvironmentVariables != null) foreach (var configEnvironmentVariableKey in config.EnvironmentVariables.Keys) process.StartInfo.Environment.Add(key: configEnvironmentVariableKey, @@ -474,7 +474,7 @@ namespace k8s throw new KubeConfigException($"external exec failed due to uncaught exception: {ex}"); } - + } #endif diff --git a/src/KubernetesClient/KubernetesClientConfiguration.HttpClientHandler.cs b/src/KubernetesClient/KubernetesClientConfiguration.HttpClientHandler.cs index 144e558..6c65607 100644 --- a/src/KubernetesClient/KubernetesClientConfiguration.HttpClientHandler.cs +++ b/src/KubernetesClient/KubernetesClientConfiguration.HttpClientHandler.cs @@ -3,16 +3,18 @@ using System.Net.Http; namespace k8s { - public partial class KubernetesClientConfiguration { - public HttpClientHandler CreateDefaultHttpClientHandler() { + public partial class KubernetesClientConfiguration + { + public HttpClientHandler CreateDefaultHttpClientHandler() + { var httpClientHandler = new HttpClientHandler(); #if !NET452 var uriScheme = new Uri(this.Host).Scheme; - if(uriScheme == "https") + if (uriScheme == "https") { - if(this.SkipTlsVerify) + if (this.SkipTlsVerify) { httpClientHandler.ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; @@ -32,7 +34,8 @@ namespace k8s return httpClientHandler; } - public void AddCertificates(HttpClientHandler handler) { + public void AddCertificates(HttpClientHandler handler) + { if ((!string.IsNullOrWhiteSpace(this.ClientCertificateData) || !string.IsNullOrWhiteSpace(this.ClientCertificateFilePath)) && (!string.IsNullOrWhiteSpace(this.ClientCertificateKeyData) || diff --git a/src/KubernetesClient/KubernetesClientConfiguration.InCluster.cs b/src/KubernetesClient/KubernetesClientConfiguration.InCluster.cs index 7edbfaf..8787ec1 100644 --- a/src/KubernetesClient/KubernetesClientConfiguration.InCluster.cs +++ b/src/KubernetesClient/KubernetesClientConfiguration.InCluster.cs @@ -32,7 +32,8 @@ namespace k8s public static KubernetesClientConfiguration InClusterConfig() { - if (!IsInCluster()) { + if (!IsInCluster()) + { throw new KubeConfigException( "unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined"); } diff --git a/src/KubernetesClient/ResourceQuantity.cs b/src/KubernetesClient/ResourceQuantity.cs index 8e4b690..80214f7 100644 --- a/src/KubernetesClient/ResourceQuantity.cs +++ b/src/KubernetesClient/ResourceQuantity.cs @@ -138,14 +138,14 @@ namespace k8s.Models { return false; } - return Equals((ResourceQuantity) obj); + return Equals((ResourceQuantity)obj); } public override int GetHashCode() { unchecked { - return ((int) Format * 397) ^ _unitlessValue.GetHashCode(); + return ((int)Format * 397) ^ _unitlessValue.GetHashCode(); } } @@ -336,7 +336,7 @@ namespace k8s.Models var minE = -9; var lastv = Roundup(value * Fraction.Pow(10, -minE)); - for (var exp = minE;; exp += 3) + for (var exp = minE; ; exp += 3) { var v = value * Fraction.Pow(10, -exp); if (HasMantissa(v)) @@ -351,10 +351,10 @@ namespace k8s.Models if (minE == 0) { - return $"{(decimal) lastv}"; + return $"{(decimal)lastv}"; } - return $"{(decimal) lastv}e{minE}"; + return $"{(decimal)lastv}e{minE}"; } case SuffixFormat.BinarySI: @@ -384,7 +384,7 @@ namespace k8s.Models lastv = v; } - return $"{(decimal) lastv}{suffix}"; + return $"{(decimal)lastv}{suffix}"; } private static Fraction Roundup(Fraction lastv) diff --git a/src/KubernetesClient/V1Patch.cs b/src/KubernetesClient/V1Patch.cs index d4eb7dc..19ff4a9 100644 --- a/src/KubernetesClient/V1Patch.cs +++ b/src/KubernetesClient/V1Patch.cs @@ -37,7 +37,7 @@ namespace k8s.Models public PathType Type { get; private set; } - public V1Patch(IJsonPatchDocument jsonPatch) : this((object) jsonPatch) + public V1Patch(IJsonPatchDocument jsonPatch) : this((object)jsonPatch) { } diff --git a/src/KubernetesClient/Watcher.cs b/src/KubernetesClient/Watcher.cs index cde5785..d2ce043 100644 --- a/src/KubernetesClient/Watcher.cs +++ b/src/KubernetesClient/Watcher.cs @@ -194,7 +194,8 @@ namespace k8s Action onError = null, Action onClosed = null) { - return new Watcher(async () => { + return new Watcher(async () => + { var response = await responseTask.ConfigureAwait(false); if (!(response.Response.Content is WatcherDelegatingHandler.LineSeparatedHttpContent content)) @@ -203,7 +204,7 @@ namespace k8s } return content.StreamReader; - } , onEvent, onError, onClosed); + }, onEvent, onError, onClosed); } /// diff --git a/src/KubernetesClient/WatcherDelegatingHandler.cs b/src/KubernetesClient/WatcherDelegatingHandler.cs index cd553ac..21fc369 100644 --- a/src/KubernetesClient/WatcherDelegatingHandler.cs +++ b/src/KubernetesClient/WatcherDelegatingHandler.cs @@ -24,7 +24,7 @@ namespace k8s { string query = request.RequestUri.Query; int index = query.IndexOf("watch=true"); - if (index > 0 && (query[index-1] == '&' || query[index-1] == '?')) + if (index > 0 && (query[index - 1] == '&' || query[index - 1] == '?')) { originResponse.Content = new LineSeparatedHttpContent(originResponse.Content, cancellationToken); } diff --git a/src/KubernetesClient/Yaml.cs b/src/KubernetesClient/Yaml.cs index d51cc0d..bc6b75c 100644 --- a/src/KubernetesClient/Yaml.cs +++ b/src/KubernetesClient/Yaml.cs @@ -17,7 +17,8 @@ namespace k8s /// This is a utility class that helps you load objects from YAML files. /// - public class Yaml { + public class Yaml + { /// /// Load a collection of objects from a stream asynchronously /// @@ -27,7 +28,8 @@ namespace k8s /// /// A map from / to Type. For example "v1/Pod" -> typeof(V1Pod) /// - public static async Task> LoadAllFromStreamAsync(Stream stream, Dictionary typeMap) { + public static async Task> LoadAllFromStreamAsync(Stream stream, Dictionary typeMap) + { var reader = new StreamReader(stream); var content = await reader.ReadToEndAsync().ConfigureAwait(false); return LoadAllFromString(content, typeMap); @@ -59,7 +61,8 @@ namespace k8s /// A map from / to Type. For example "v1/Pod" -> typeof(V1Pod) /// - public static List LoadAllFromString(String content, Dictionary typeMap) { + public static List LoadAllFromString(String content, Dictionary typeMap) + { var deserializer = new DeserializerBuilder() .WithNamingConvention(new CamelCaseNamingConvention()) @@ -70,7 +73,8 @@ namespace k8s var types = new List(); var parser = new Parser(new StringReader(content)); parser.Expect(); - while (parser.Accept()) { + while (parser.Accept()) + { var obj = deserializer.Deserialize(parser); types.Add(typeMap[obj.ApiVersion + "/" + obj.Kind]); } @@ -85,7 +89,8 @@ namespace k8s parser.Expect(); var ix = 0; var results = new List(); - while (parser.Accept()) { + while (parser.Accept()) + { var objType = types[ix++]; var obj = deserializer.Deserialize(parser, objType); results.Add(obj); @@ -93,19 +98,23 @@ namespace k8s return results; } - public static async Task LoadFromStreamAsync(Stream stream) { + public static async Task LoadFromStreamAsync(Stream stream) + { var reader = new StreamReader(stream); var content = await reader.ReadToEndAsync().ConfigureAwait(false); return LoadFromString(content); } - public static async Task LoadFromFileAsync (string file) { - using (FileStream fs = File.OpenRead(file)) { + public static async Task LoadFromFileAsync(string file) + { + using (FileStream fs = File.OpenRead(file)) + { return await LoadFromStreamAsync(fs).ConfigureAwait(false); } } - public static T LoadFromString(string content) { + public static T LoadFromString(string content) + { var deserializer = new DeserializerBuilder() .WithNamingConvention(new CamelCaseNamingConvention()) diff --git a/tests/KubernetesClient.Tests/AuthTests.cs b/tests/KubernetesClient.Tests/AuthTests.cs index d71a42a..b6d2f5d 100644 --- a/tests/KubernetesClient.Tests/AuthTests.cs +++ b/tests/KubernetesClient.Tests/AuthTests.cs @@ -173,7 +173,8 @@ namespace k8s.Tests [Fact] public void Cert() { - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { // TODO: This test fails on OS X for some reason. Figure out why... return; } @@ -442,7 +443,7 @@ namespace k8s.Tests if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) arguments = ($"/c echo {responseJson}").Split(" "); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - arguments = new[] {responseJson}; + arguments = new[] { responseJson }; var users = new List @@ -461,7 +462,7 @@ namespace k8s.Tests } } }; - var kubernetesConfig = new K8SConfiguration {Clusters = clusters, Users = users, Contexts = contexts}; + var kubernetesConfig = new K8SConfiguration { Clusters = clusters, Users = users, Contexts = contexts }; return kubernetesConfig; } } diff --git a/tests/KubernetesClient.Tests/TaskAssert.cs b/tests/KubernetesClient.Tests/TaskAssert.cs index 7273f67..142007d 100644 --- a/tests/KubernetesClient.Tests/TaskAssert.cs +++ b/tests/KubernetesClient.Tests/TaskAssert.cs @@ -7,7 +7,7 @@ namespace k8s.Tests { static class TaskAssert { - public static void NotCompleted(Task task,string message = "Task should not be completed") + public static void NotCompleted(Task task, string message = "Task should not be completed") { Assert.False(task.IsCompleted, message); } diff --git a/tests/KubernetesClient.Tests/V1StatusObjectViewTests.cs b/tests/KubernetesClient.Tests/V1StatusObjectViewTests.cs index cb929b7..0e3abf3 100644 --- a/tests/KubernetesClient.Tests/V1StatusObjectViewTests.cs +++ b/tests/KubernetesClient.Tests/V1StatusObjectViewTests.cs @@ -73,4 +73,4 @@ namespace k8s.Tests } } - } +} diff --git a/tests/KubernetesClient.Tests/YamlTests.cs b/tests/KubernetesClient.Tests/YamlTests.cs index 58d8b2a..d0072ef 100644 --- a/tests/KubernetesClient.Tests/YamlTests.cs +++ b/tests/KubernetesClient.Tests/YamlTests.cs @@ -31,8 +31,8 @@ metadata: Assert.Equal(2, objs.Count); Assert.IsType(objs[0]); Assert.IsType(objs[1]); - Assert.Equal("foo", ((V1Pod) objs[0]).Metadata.Name); - Assert.Equal("ns", ((V1Namespace) objs[1]).Metadata.Name); + Assert.Equal("foo", ((V1Pod)objs[0]).Metadata.Name); + Assert.Equal("ns", ((V1Namespace)objs[1]).Metadata.Name); } [Fact]